0

Magento version 1.9.3.8.

PHP 7.1.22

I'm trying to create Reorder programmatically. But for some orders I've got exceptions:

2019-11-05T09:16:33+00:00 ERR (3): 
Exception: Rate was empty inside quote validate method, trying to forcefully recalculate in F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Sales\Model\Service\Quote.php:305
Stack trace:
0 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Sales\Model\Service\Quote.php(137): Mage_Sales_Model_Service_Quote->_validate()
1 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Sales\Model\Service\Quote.php(126): Mage_Sales_Model_Service_Quote->submitOrder()
2 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Adminhtml\Model\Sales\Order\Create.php(1555): Mage_Sales_Model_Service_Quote->submit()
3 F:\OSPanel\domains\mymagento.local\app\code\local\MageB2B\CreateOrder\controllers\IndexController.php(47): Mage_Adminhtml_Model_Sales_Order_Create->createOrder()
4 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Core\Controller\Varien\Action.php(418): MageB2B_CreateOrder_IndexController->SaveAction()
5 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('save')
6 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Core\Controller\Varien\Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
7 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Core\Model\App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
8 F:\OSPanel\domains\mymagento.local\app\Mage.php(683): Mage_Core_Model_App->run(Array)
9 F:\OSPanel\domains\mymagento.local\index.php(83): Mage::run('', 'store')
10 {main}
2019-11-05T09:16:33+00:00 ERR (3): 
Mage_Core_Exception: Please specify a shipping method. in F:\OSPanel\domains\mymagento.local\app\Mage.php:595
Stack trace:
0 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Sales\Model\Service\Quote.php(313): Mage::throwException('Please specify ...')
1 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Sales\Model\Service\Quote.php(137): Mage_Sales_Model_Service_Quote->_validate()
2 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Sales\Model\Service\Quote.php(126): Mage_Sales_Model_Service_Quote->submitOrder()
3 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Adminhtml\Model\Sales\Order\Create.php(1555): Mage_Sales_Model_Service_Quote->submit()
4 F:\OSPanel\domains\mymagento.local\app\code\local\MageB2B\CreateOrder\controllers\IndexController.php(47): Mage_Adminhtml_Model_Sales_Order_Create->createOrder()
5 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Core\Controller\Varien\Action.php(418): MageB2B_CreateOrder_IndexController->SaveAction()
6 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('save')
7 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Core\Controller\Varien\Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
8 F:\OSPanel\domains\mymagento.local\app\code\core\Mage\Core\Model\App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
9 F:\OSPanel\domains\mymagento.local\app\Mage.php(683): Mage_Core_Model_App->run(Array)
10 F:\OSPanel\domains\mymagento.local\index.php(83): Mage::run('', 'store')
11 {main}

Here is my controller action:

public function SaveAction()
    {
        Mage::getSingleton('adminhtml/session_quote')->clear();

        $params = $this->getRequest()->getParams();
        $orderId = $params['order_id'];

        $order = Mage::getModel('sales/order')->load($orderId);

        try {
            $order->setReordered(true);

            Mage::getSingleton('adminhtml/session_quote')->setUseOldShippingMethod(true);
            $reorder = Mage::getSingleton('adminhtml/sales_order_create');

            $reorder->getQuote()->setShippingMethod($order->getShippingMethod());
            $reorder->getQuote()->getShippingAddress()->setCollectShippingRates(true);
            $reorder->getQuote()->setTotalsCollectedFlag(false)->collectTotals();

            // create new order
            $reorder->initFromOrder($order)
                    ->setRecollect(true)
                    ->createOrder();

            Mage::getSingleton('adminhtml/session_quote')->clear();

            Mage::getSingleton('core/session')->addSuccess(Mage::helper('mageb2b_createorder')->__('Order created successfully.'));
            $this->_redirect('sales/order/history');
        } catch (Exception $e) {
            Mage::logException($e);
            Mage::getSingleton('core/session')->addError(Mage::helper('mageb2b_createorder')->__('Can not reorder error. Check log for more information.'));
            $this->_redirect('sales/order/view', array('order_id' => $order->getId()));
        }
    }

But, this code works correct for another orders.

Exception appears here: app/code/core/Mage/Sales/Model/Service/Quote.php

if (!$this->getQuote()->isVirtual() && (!$method || !$rate)) {
                Mage::throwException(Mage::helper('sales')->__('Please specify a shipping method.'));
            }

If I commented out "Mage::throwException" (or delete "|| !$rate") new order will created succeffully, but with all prices $0.00.

What is the reason? And how can I fix it?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.