Невозможно установить способ доставки в Magento order create script

У меня возникли проблемы с получением моего сценария для создания заказа на моем сайте, который использует Magento 1.7. Ошибка, которую я получаю, – «укажите способ доставки», подробнее

blockquote Fatal error: Не удалось исключить «Mage_Core_Exception» с сообщением «Пожалуйста, укажите способ доставки». в /home/mysite/public_html/app/Mage.php:594 Трассировка стека: # 0 /home/mysite/public_html/app/code/core/Mage/Sales/Model/Service/Quote.php(303): Маг: : throwException ('Пожалуйста, укажите …') # 1 /home/mysite/public_html/app/code/core/Mage/Sales/Model/Service/Quote.php(222): Mage_Sales_Model_Service_Quote -> _ validate () # 2 / home / mysite / public_html / app / code / core / Mage / Sales / Model / Service / Quote.php (238): Mage_Sales_Model_Service_Quote-> submitNominalItems () # 3 /home/mysite/public_html/apitest/magento_order_create.php(82) : Mage_Sales_Model_Service_Quote-> submitAll () # 4 {main} брошен в /home/mysite/public_html/app/Mage.php в строке 594

Я пытаюсь использовать сценарий ниже, чтобы создать заказ, и я передаю skus и количества в сообщении с другой страницы. `

<?php // Link Mage Class require ('../app/Mage.php'); // Initialize Magento framework Mage::app('mysite'); //create a cart $quote = Mage::getModel('sales/quote') ->setStoreId(Mage::app()->getStore('mysite')->getId()); //Get Customer by Id $customer = Mage::getModel('customer/customer')->load('1'); //attach customer to cart $quote->assignCustomer($customer); //attach products foreach ($_POST as $sku=>$qty) { $product = Mage::helper('catalog/product')->getProduct($sku,Mage::app()->getStore()->getId(), 'sku'); $buyInfo = array( 'qty' => $qty, // custom option id => value id // or // configurable attribute id => value id ); $quote->addProduct($product, new Varien_Object($buyInfo)); } //get and set customer billing address //need to work on this encase we use diffrent billing and shipping addresses $addressData = Mage::getModel('customer/address')->load('1'); $billingAddress = $quote->getBillingAddress()->addData($addressData); $shippingAddress = $quote->getShippingAddress()->addData($addressData); // set shipping and payment methods. assumes freeshipping and check payment // have been enabled. /* $shippingAddress->setCollectShippingRates(true)->collectShippingRates() ->setShippingMethod('freeshipping_freeshipping') ->setPaymentMethod('checkmo'); */ // THIS IS WHERE THE ERROR SEEMS TO BE $quote->getShippingAddress()->setShippingMethod('freeshipping_freeshipping'); $quote->getShippingAddress()->setCollectShippingRates(true); $quote->getShippingAddress()->collectShippingRates(); //set payment method $quote->getPayment()->importData(array('method' => 'checkmo')); //save cart and check out $quote->collectTotals()->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); printf("Created order %s\n", $order->getIncrementId()); ` 

Вышеупомянутый скрипт изначально появился из http://pastebin.com/8cft4d8v, и он работает как очарование моей тестовой среды (также 1.7). Я прокомментировал оригинальный код метода доставки и сломался в отдельные строки. На живом сайте есть два сайта и два магазина, я убедился, что бесплатная доставка включена на бэкэнд и проверена, что она появляется при запуске этого скрипта.

 <?php // Link Mage Class require ('../app/Mage.php'); // Initialize Magento framework Mage::app('mysite'); $methods = Mage::getSingleton('shipping/config')->getActiveCarriers(); var_dump($methods); 

Я достаточно уверен, что адрес установлен правильно, если я эхо выхожу на экран, на котором находится адрес.

Я пробовал прочитать документацию, посмотреть на другой пример кода и изменить его части, чтобы узнать, могу ли я установить способ доставки, но не повезло.

Ну, главное решение похоже на то, что было решено во время перезагрузки сервера. Но я также опубликую окончательный сценарий, который мы будем использовать. По какой-то причине установка способа доставки на объект цитаты не работает, поэтому я также вернулся к «оригинальному» сценарию, который я нашел на http://pastebin.com/8cft4d8v . Я также избавился от некоторых строк, которые, похоже, не имели никакого значения, если они существуют или нет. Надеюсь, это может помочь кому-то по очереди

 <?php // Link Mage Class require ('..\app\Mage.php'); // Initialize Magento framework Mage::app('my'); //create a cart $quote = Mage::getModel('sales/quote') ->setStoreId(Mage::app()->getStore('default')->getId()); //Get Customer by Id $customer = Mage::getModel('customer/customer')->load('1'); //attach customer to cart $quote->assignCustomer($customer); //attach products foreach ($_POST as $sku=>$qty) { $product = Mage::helper('catalog/product')->getProduct($sku, Mage::app()->getStore()->getId(), 'sku'); $buyInfo = array( 'qty' => $qty, // custom option id => value id // or // configurable attribute id => value id ); $quote->addProduct($product, new Varien_Object($buyInfo)); } $billingAddress = $quote->getBillingAddress()->addData(); $shippingAddress = $quote->getShippingAddress()->addData(); // set shipping and payment methods. assumes freeshipping and check payment // have been enabled. $shippingAddress->setCollectShippingRates(true)->collectShippingRates() ->setShippingMethod('flatrate_flatrate'); $quote->getPayment()->importData(array('method' => 'checkmo')); //save cart and check out $quote->collectTotals()->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); printf("Created order %s\n", $order->getIncrementId()); по <?php // Link Mage Class require ('..\app\Mage.php'); // Initialize Magento framework Mage::app('my'); //create a cart $quote = Mage::getModel('sales/quote') ->setStoreId(Mage::app()->getStore('default')->getId()); //Get Customer by Id $customer = Mage::getModel('customer/customer')->load('1'); //attach customer to cart $quote->assignCustomer($customer); //attach products foreach ($_POST as $sku=>$qty) { $product = Mage::helper('catalog/product')->getProduct($sku, Mage::app()->getStore()->getId(), 'sku'); $buyInfo = array( 'qty' => $qty, // custom option id => value id // or // configurable attribute id => value id ); $quote->addProduct($product, new Varien_Object($buyInfo)); } $billingAddress = $quote->getBillingAddress()->addData(); $shippingAddress = $quote->getShippingAddress()->addData(); // set shipping and payment methods. assumes freeshipping and check payment // have been enabled. $shippingAddress->setCollectShippingRates(true)->collectShippingRates() ->setShippingMethod('flatrate_flatrate'); $quote->getPayment()->importData(array('method' => 'checkmo')); //save cart and check out $quote->collectTotals()->save(); $service = Mage::getModel('sales/service_quote', $quote); $service->submitAll(); $order = $service->getOrder(); printf("Created order %s\n", $order->getIncrementId());