简体   繁体   English

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

[英]Magento 1.9 create order using programmation from backend

I tried to test a script to create magento order. 我试图测试一个脚本来创建magento订单。 code seems to fails on the last line "$service->getOrder();" 代码似乎在最后一行“ $ service-> getOrder();”失败 Currency used is EUR and Customer ID is 2(already exist) I think the problem is with shipping method.but not sure Any help is appreciated. 我使用的货币是EUR,客户ID为2(已经存在)我认为问题在于运输方式。但是不确定是否能提供任何帮助。

<?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());

?>

Most likely your problem is connected with the unavailability of shipping method for the current address validation: https://gyazo.com/13c1e692b92a8413594a75ababeba16d 您的问题很可能与当前地址验证的送货方式不可用有关: https : //gyazo.com/13c1e692b92a8413594a75ababeba16d

Such result, I see for free shipping at my store settings (it is not available for the address) If I replace the address for my usual, for which free shiping is available, the validation is successful, and your code works completely, without any change in it: https://gyazo.com/2496d809d2e16bcab6a0fb3f63270ed2 这样的结果,我在商店设置中看到免费送货(该地址不可用)如果我按惯常的方式替换了地址(可以免费送货),则验证成功,并且您的代码可以完全正常工作,而无需进行任何操作更改它: https : //gyazo.com/2496d809d2e16bcab6a0fb3f63270ed2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM