在 magento 中 select 多个数量后,如何从自定义页面订购多个产品?
How can order place for multiple product from custom page after select multiple qty in magento?
我创建了一个自定义页面,显示带有数量按钮的所有产品。这里我们可以选择多个产品。之后我想订购所有选定产品的地方。我如何为多个产品下订单? magento 中有可用的插件吗?
我也需要相同的功能,将通过使用我自己的脚本而不是任何插件来结束这个。以下是以编程方式下订单的完整代码。希望这有帮助。
<?php
$transaction = Mage::getModel('core/resource_transaction');
$increment_ids = array();
if ($orderData) {
try {
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($store_id);
$order = Mage::getModel('sales/order')
->setIncrementId($reservedOrderId)
->setStoreId($store_id)
->setQuoteId(0)
->setGlobal_currency_code('USD')
->setBase_currency_code('USD')
->setStore_currency_code('USD')
->setOrder_currency_code('USD');
//saving customer
$order->setCustomer_email($orderData['email'])
->setCustomerFirstname($orderData['firstname'])
->setCustomerLastname($orderData['lastname'])
->setCustomerGroupId(1)
->setCustomer_is_guest(1);
$regionModel = Mage::getModel('directory/region')->loadByCode("CA", 'US');
$shippingAddress = Mage::getModel('sales/order_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setFirstname($orderData['firstname'])
->setLastname($orderData['lastname'])
->setStreet($orderData['shipping']['line'])
->setCity($orderData['shipping']['city'])
->setRegion($orderData['shipping']['region'])
->setRegionId($regionModel->getId())
->setCountry_id('US')
->setPostcode($orderData['shipping']['postcode'])
->setTelephone($orderData['shipping']['telephone']);
$order->setShippingAddress($shippingAddress)
->setShipping_method($orderData['shipping_method'])
->setShippingDescription($orderData['shipping_description']);
//get region code
$regionModel = Mage::getModel('directory/region')->loadByCode($orderData['billing']['region'], 'US');
// set Billing Address
$billingAddress = Mage::getModel('sales/order_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setFirstname($orderData['firstname'])
->setLastname($orderData['lastname'])
->setStreet($orderData['billing']['line'])
->setCity($orderData['billing']['city'])
->setRegion($regionModel->getName())
->setRegionId($regionModel->getId())
->setCountry_id('US')
->setPostcode($orderData['billing']['postcode'])
->setTelephone($orderData['billing']['telephone']);
$order->setBillingAddress($billingAddress);
//save products
$subTotal = 0;
$productPrice=0;
$qtyTotal=0;
foreach ($orderData['items'] as $key=>$product) {
$_product = Mage::getModel('catalog/product')->load($key);
$rowTotal = $_product->getPrice() * $product;
$orderItem = Mage::getModel('sales/order_item')
->setStoreId($storeId)
->setQuoteItemId(0)
->setQuoteParentItemId(NULL)
->setProductId($key)
->setProductType($_product->getTypeId())
->setQtyBackordered(NULL)
->setTotalQtyOrdered($product)
->setQtyOrdered($product)
->setName($_product->getName())
->setSku($_product->getSku())
->setPrice(($_product->getPrice()))
->setBasePrice($_product->getPrice())
->setOriginalPrice($_product->getPrice())
->setRowTotal($rowTotal)
->setBaseRowTotal($rowTotal);
$qtyTotal += $product;
$subTotal += $rowTotal;
$order->addItem($orderItem);
}
$grandTotal = ($subTotal+$orderData['shipping_charge'])-$orderData['discount'];
$orderPayment = Mage::getModel('sales/order_payment')
->setStoreId($store_id)
->setCustomerPaymentId(0)
->setMethod('purchaseorder')
->setPo_number($reservedOrderId);
$order->setPayment($orderPayment);
//date_default_timezone_set('America/Los_Angeles');
$order->setSubtotal($subTotal)
->setState('processing')
->setStatus('processing')
->setCouponCode($orderData['coupon'])
->setBaseDiscountAmount($orderData['discount'])
->setBaseGrandTotal($grandTotal)
->setBaseSubtotal($subTotal)
->setBaseTotalInvoiced($grandTotal)
->setBaseTotalQtyOrdered($qtyTotal)
->setDiscountAmount($orderData['discount'])
->setGrandTotal($grandTotal)
->setSubtotal($subTotal)
->setTotalQtyOrdered($qtyTotal)
->setBaseTotalDue($grandTotal)
//->setCreatedAt(date('Y-m-d'))
//->setUpdatedAt(date('Y-m-d'))
->setTotalItemCount($order_detail['qty'])
->setShippingAmount($orderData['shipping_charge'])
->setBaseShippingAmount($orderData['shipping_charge']);
$transaction->addObject($order);
$transaction->addCommitCallback(array($order, 'place'));
$transaction->addCommitCallback(array($order, 'save'));
$transaction->save();
$order_data = $order->getData();
$order_id = $order_data['increment_id'];
$order->sendNewOrderEmail();
} catch (Exception $e) {
$finalresult=array('exception',$e->getMessage());
}
}
我创建了一个自定义页面,显示带有数量按钮的所有产品。这里我们可以选择多个产品。之后我想订购所有选定产品的地方。我如何为多个产品下订单? magento 中有可用的插件吗?
我也需要相同的功能,将通过使用我自己的脚本而不是任何插件来结束这个。以下是以编程方式下订单的完整代码。希望这有帮助。
<?php
$transaction = Mage::getModel('core/resource_transaction');
$increment_ids = array();
if ($orderData) {
try {
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($store_id);
$order = Mage::getModel('sales/order')
->setIncrementId($reservedOrderId)
->setStoreId($store_id)
->setQuoteId(0)
->setGlobal_currency_code('USD')
->setBase_currency_code('USD')
->setStore_currency_code('USD')
->setOrder_currency_code('USD');
//saving customer
$order->setCustomer_email($orderData['email'])
->setCustomerFirstname($orderData['firstname'])
->setCustomerLastname($orderData['lastname'])
->setCustomerGroupId(1)
->setCustomer_is_guest(1);
$regionModel = Mage::getModel('directory/region')->loadByCode("CA", 'US');
$shippingAddress = Mage::getModel('sales/order_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setFirstname($orderData['firstname'])
->setLastname($orderData['lastname'])
->setStreet($orderData['shipping']['line'])
->setCity($orderData['shipping']['city'])
->setRegion($orderData['shipping']['region'])
->setRegionId($regionModel->getId())
->setCountry_id('US')
->setPostcode($orderData['shipping']['postcode'])
->setTelephone($orderData['shipping']['telephone']);
$order->setShippingAddress($shippingAddress)
->setShipping_method($orderData['shipping_method'])
->setShippingDescription($orderData['shipping_description']);
//get region code
$regionModel = Mage::getModel('directory/region')->loadByCode($orderData['billing']['region'], 'US');
// set Billing Address
$billingAddress = Mage::getModel('sales/order_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setFirstname($orderData['firstname'])
->setLastname($orderData['lastname'])
->setStreet($orderData['billing']['line'])
->setCity($orderData['billing']['city'])
->setRegion($regionModel->getName())
->setRegionId($regionModel->getId())
->setCountry_id('US')
->setPostcode($orderData['billing']['postcode'])
->setTelephone($orderData['billing']['telephone']);
$order->setBillingAddress($billingAddress);
//save products
$subTotal = 0;
$productPrice=0;
$qtyTotal=0;
foreach ($orderData['items'] as $key=>$product) {
$_product = Mage::getModel('catalog/product')->load($key);
$rowTotal = $_product->getPrice() * $product;
$orderItem = Mage::getModel('sales/order_item')
->setStoreId($storeId)
->setQuoteItemId(0)
->setQuoteParentItemId(NULL)
->setProductId($key)
->setProductType($_product->getTypeId())
->setQtyBackordered(NULL)
->setTotalQtyOrdered($product)
->setQtyOrdered($product)
->setName($_product->getName())
->setSku($_product->getSku())
->setPrice(($_product->getPrice()))
->setBasePrice($_product->getPrice())
->setOriginalPrice($_product->getPrice())
->setRowTotal($rowTotal)
->setBaseRowTotal($rowTotal);
$qtyTotal += $product;
$subTotal += $rowTotal;
$order->addItem($orderItem);
}
$grandTotal = ($subTotal+$orderData['shipping_charge'])-$orderData['discount'];
$orderPayment = Mage::getModel('sales/order_payment')
->setStoreId($store_id)
->setCustomerPaymentId(0)
->setMethod('purchaseorder')
->setPo_number($reservedOrderId);
$order->setPayment($orderPayment);
//date_default_timezone_set('America/Los_Angeles');
$order->setSubtotal($subTotal)
->setState('processing')
->setStatus('processing')
->setCouponCode($orderData['coupon'])
->setBaseDiscountAmount($orderData['discount'])
->setBaseGrandTotal($grandTotal)
->setBaseSubtotal($subTotal)
->setBaseTotalInvoiced($grandTotal)
->setBaseTotalQtyOrdered($qtyTotal)
->setDiscountAmount($orderData['discount'])
->setGrandTotal($grandTotal)
->setSubtotal($subTotal)
->setTotalQtyOrdered($qtyTotal)
->setBaseTotalDue($grandTotal)
//->setCreatedAt(date('Y-m-d'))
//->setUpdatedAt(date('Y-m-d'))
->setTotalItemCount($order_detail['qty'])
->setShippingAmount($orderData['shipping_charge'])
->setBaseShippingAmount($orderData['shipping_charge']);
$transaction->addObject($order);
$transaction->addCommitCallback(array($order, 'place'));
$transaction->addCommitCallback(array($order, 'save'));
$transaction->save();
$order_data = $order->getData();
$order_id = $order_data['increment_id'];
$order->sendNewOrderEmail();
} catch (Exception $e) {
$finalresult=array('exception',$e->getMessage());
}
}