首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento 1.9使用后端编程创建订单

Magento 1.9使用后端编程创建订单
EN

Stack Overflow用户
提问于 2016-03-10 16:21:07
回答 1查看 817关注 0票数 1

我试着测试一个脚本来创建magento order。在最后一行“$service->getOrder()”上,代码似乎失败了;使用的货币是EUR,而客户ID是2(已经存在),我认为问题在于发送method.but不确定是否感谢任何帮助。

代码语言:javascript
复制
<?php
require_once 'app/Mage.php';
umask(0);
$websiteId = Mage::app() -> getWebsite() -> getId();
$store = Mage::app() -> getStore();
// Start New Sales Order Quote
$quote = Mage::getModel('sales/quote') -> setStoreId($store -> getId());
// Set Sales Order Quote Currency
//$quote -> setCurrency($order -> AdjustmentAmount -> currencyID);
$customer = Mage::getModel('customer/customer');

$customer -> load(2);
//customer already exist
// Assign Customer To Sales Order Quote
$quote -> assignCustomer($customer);

// Configure Notification
$quote -> setSendCconfirmation(1);
$product = Mage::getModel('catalog/product') -> load(92);
//product already exist
$quote -> addProduct($product, new Varien_Object( array('qty' => 1)));

$addressData = array('firstname' => 'Test', 'lastname' => 'Test', 'street' => 'Sample Street 10', 'city' => 'Somewhere', 'postcode' => '123456', 'telephone' => '123456', 'country_id' => 'FR', 'region_id' => 182, // id from directory_country_region table
);

$billingAddress = $quote -> getBillingAddress() -> addData($addressData);
$shippingAddress = $quote -> getShippingAddress() -> addData($addressData);

$shippingAddress -> setCollectShippingRates(true) -> collectShippingRates() -> setShippingMethod('freeshipping_freeshipping') -> setPaymentMethod('checkmo');

$quote -> getPayment() -> importData(array('method' => 'checkmo'));

$quote -> collectTotals();

$quote -> reserveOrderId();
$quote -> save();
$service = Mage::getModel('sales/service_quote', $quote);
$service -> submitAll();
$order = $service -> getOrder();

printf("Created order %s\n", $orderObj -> getIncrementId());

?>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-03-11 10:06:55

您的问题很可能与当前地址验证的传送方法不可用:https://gyazo.com/13c1e692b92a8413594a75ababeba16d有关。

这样的结果,我可以在我的商店设置中看到免费送货(该地址不可用),如果我替换了我通常的地址,这是免费的,验证是成功的,并且您的代码完全工作,没有任何改变:https://gyazo.com/2496d809d2e16bcab6a0fb3f63270ed2

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35921867

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档