是否有办法可以在Magento中创建一个订单,其中包含将在订单中定义的“自定义”产品。该订单不需要创建自定义产品。这些自定义产品将具有自定义价格,并在创建订单时确定自定义产品标题。
因此,在创建订单时,我只需指定一些定价产品,然后将其添加到订单中。
同样,产品不会在Magento的任何地方定义,所以我只想说,我想在9.99添加xyz,在1.99添加zxy,也许我想在3.99添加另一个xyz。
订单显示为,
xyz | 9.99
zxy | 1.99
xyz | 3.99
TOTAL | 15.97
谢谢
答案 0 :(得分:3)
以编程方式创建包含自定义产品的订单,这是一个示例代码:
<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('admin');
$order = create();
echo $order;
function create()
{
$storeId = 1;
if (!$storeId) {
$storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
reset($storeIds);
$storeId = current($storeIds);
}
$order = Mage::getModel('sales/order')
->setState('new');
$orderPayment = Mage::getModel('sales/order_payment')
->setStoreId($storeId)
->setCustomerPaymentId(0)
->setMethod('checkmo')
->setPo_number(' - ');
$order->setPayment($orderPayment);
$billingAddress = Mage::getModel('sales/order_address');
$shippingAddress = Mage::getModel('sales/order_address');
$order->setStoreId($storeId)
->setQuoteId(0)
->setGlobal_currency_code('EUR')
->setBase_currency_code('EUR')
->setStore_currency_code('EUR')
->setOrder_currency_code('EUR')
->setStatus($orderData['status']);
// set Customer data
$order->setCustomer_email('a@b.com')
->setCustomerFirstname('firstname')
->setCustomerLastname('lastname')
->setCustomer_is_guest(1);
// set Billing Address
$billingAddress
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
->setPrefix('mr')
->setFirstname('firstname')
->setLastname('lastname')
->setCompany('company')
->setStreet('street')
->setCity('city')
->setCountry_id('US')
->setPostcode('12345');
$order->setBillingAddress($billingAddress);
$shippingAddress
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setPrefix('mr')
->setFirstname('firstname')
->setLastname('lastname')
->setCompany('company')
->setStreet('street')
->setCity('city')
->setCountry_id('US')
->setPostcode('12345');
$order->setShippingAddress($shippingAddress)
->setShipping_method('freeshipping_freeshipping')
->setShippingDescription('Free Shipping - Free');
$orderItem = Mage::getModel('sales/order_item')
->setStoreId(1)
->setQuoteItemId(0)
->setQuoteParentItemId(NULL)
->setQtyBackordered(NULL)
->setTotalQtyOrdered(10)
->setQtyOrdered(10)
->setName('custom product name')
->setPrice(100)
->setBasePrice(10)
->setOriginalPrice(10)
->setRowTotal(1000)
->setBaseRowTotal(1000);
$order->addItem($orderItem);
$order->setSubtotal(2000)
->setSubtotalIncludingTax(2000)
->setBaseSubtotal(2000)
->setGrandTotal(2000)
->setBaseGrandTotal(2000)
->setTaxAmount(0)
->setTotalQtyOrdered(10);
$order->save();
return $order;
}
&GT;