【发布时间】:2015-02-27 23:01:40
【问题描述】:
我正在以编程方式创建新订单。我想添加新的自定义选项 创建新订单时,但我不知道。如何创建自定义 选项以及如何在下面的代码中添加自定义选项,请帮助我。
<?php
require_once ‘app/Mage.php’;Mage::app();
$quote = Mage::getModel(‘sales/quote’)
->setStoreId(Mage::app()->getStore(‘default’)->getId());
if ('existing') {
// for customer orders:
$customer = Mage::getModel(‘customer/customer’)
->setWebsiteId(1)
->loadByEmail(‘customer@email.com’);
$quote->assignCustomer($customer);
} else {
// for guest orders only:
$quote->setCustomerEmail(‘customer@email.com’);
}
// add product(s)
$product = Mage::getModel(‘catalog/product’)->load(4);
$buyInfo = array(
‘qty’ => 1,
// custom option id => value id
// or
// configurable attribute id => value id
);
$quote->addProduct($product, new Varien_Object($buyInfo));
$addressData = array(
‘firstname’ => ‘Test’,
‘lastname’ => ‘Test’,
‘street’ => ‘Sample Street 10′,
‘city’ => ‘Somewhere’,
‘postcode’ => ’123456′,
‘telephone’ => ’123456′,
‘country_id’ => ‘US’,
‘region_id’ => 12, // id from directory_country_region table
);
$billingAddress = $quote->getBillingAddress()->addData($addressData);
$shippingAddress = $quote->getShippingAddress()->addData($addressData);
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
->setShippingMethod(‘flatrate_flatrate’)
->setPaymentMethod(‘checkmo’);
$quote->getPayment()->importData(array(‘method’ => ‘checkmo’));
$quote->collectTotals()->save();
$service = Mage::getModel(‘sales/service_quote’, $quote);
$service->submitAll();
$order = $service->getOrder();
printf(“Created order %s\n”, $order->getIncrementId());
?>
【问题讨论】:
-
自定义订单是什么意思?
-
我想在以编程方式创建新订单时保存自定义选项。
-
inchoo 网站上比较复杂。我不明白。请在我上面的代码中解决或自定义。