3

I have been searching for an answer on the web, but have tried all the solutions I have found and nothing seems to work.

The order adds fine, but in the admin panel is shows "No shipping information available".

When I go through the cart, then it shows "Free Shipping".

Any ideas on how to set the shipping method on the order?

           //Product to add to the order
           $product = Mage::getSingleton('catalog/product')->load($productId);

            //Previous order to copy from 
            $order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
            $converter = Mage::getModel('sales/convert_order');
            $quote = $converter->toQuote($order);

            $quote->setBillingAddress($converter->addressToQuoteAddress($order->getBillingAddress())); 
            $quote->setShippingAddress($converter->addressToQuoteAddress($order->getShippingAddress()));
            $quote->getShippingAddress()->setShippingMethod("tablerate_bestway"); 
            $shippingAddress = $quote->getShippingAddress();
            $shippingAddress->setFreeShipping( true )
            ->setCollectShippingRates(true)->collectShippingRates()
            ->setShippingMethod(‘tablerate_bestway’)
            ->setPaymentMethod(‘checkmo’);

            $quote->setStore($order->getStore()); 
            $quote->setCustomer($customer);
            $converter->paymentToQuotePayment($order->getPayment(), $quote->getPayment()); 




            $convert = Mage::getModel('sales/convert_quote');


            $newOrder = Mage::getModel('sales/order');

            $payment = $convert->paymentToOrderPayment($quote->getPayment());

            $newOrder->setPayment($payment);
            $newOrder->setBillingAddress($convert->addressToOrderAddress($quote->getBillingAddress())); 
            $newOrder->setShippingAddress($convert->addressToOrderAddress($quote->getShippingAddress()))->setShipping_Method('tablerate_bestway'); 
            $newOrder->getShippingAddress()->setFreeShipping(true);
            $newOrder->setShippingMethod('tablerate_bestway');
            $newOrder->setCustomerId($customer->getId()); 
            $newOrder->setCustomerFirstname($customer->getFirstname());
            $newOrder->setCustomerLastname($customer->getLastname()); 
            $newOrder->setCustomerEmail($customer->getEmail()); 

            $newOrder->setState(Mage_Sales_Model_Order::STATE_PROCESSING,true);
            $order->setWeight($product->getWeight());

            $newOrder->setSubtotal($product->getPrice())
            ->setBaseSubtotal($product->getPrice())
            ->setGrandTotal($product->getPrice())
            ->setBaseGrandTotal($product->getPrice());


            $message = 'Generated Order';
            $newOrder->addStatusToHistory($newOrder->getStatus(), $message);

             $orderItem = Mage::getModel('sales/order_item')
            ->setStoreId($newOrder->getStore()->getStoreId())
            ->setQuoteItemId(NULL)
            ->setQuoteParentItemId(NULL)
            ->setProductId($product->getId())
            ->setProductType($product->getTypeId())
            ->setQtyBackordered(NULL)
            ->setTotalQtyOrdered(1)
            ->setQtyOrdered(1)
            ->setWeight($product->getWeight())
            ->setIsVirtual(0)
            ->setIsQtyDecimal(0)
            ->setQtyInvoiced(1) 
            ->setName($product->getName()." Generated")
            ->setSku($product->getSku())
            ->setPrice($product->getPrice())
            ->setBasePrice($product->getPrice())
            ->setBaseOriginalPrice($product->getPrice())                
            ->setOriginalPrice($product->getPrice())
            ->setRowTotal($product->getPrice())
            ->setBaseRowTotal($product->getPrice())
            ->setOrder($newOrder)
            ->setProductOptions($savedOptions);

            $newOrder->addItem($orderItem);

            $newOrder->save();

            $invoice = Mage::getModel('sales/service_order', $newOrder)->prepareInvoice();
            $invoice->setRequestedCaptureCase(Mage_Sales_Model_Order_Invoice::STATE_PAID);
            $invoice->register();
            $invoice->setAmount($grandtotal);
            $invoice->pay()->save();
            $transactionSave = Mage::getModel('core/resource_transaction')
            ->addObject($invoice)
            ->addObject($newOrder);

            $newOrder->save(); 
            $transactionSave->save();

            $payment->pay($invoice);
1
  • did you find any solution for this issue?
    – Aboodred1
    Nov 17, 2019 at 15:52

2 Answers 2

0

Please use this

$order->setShippingAddress($shippingAddress)
      ->setShipping_method(<Code>)
      ->setShippingDescription(<Title>);

For Ex. UPS we set as

$order->setShippingAddress($shippingAddress)
      ->setShipping_method('ups')
      ->setShippingDescription('UPS');
0

Admin panel shows information that are in shipping_amount and shipping_description columns of the orders table. To add those information to order you need to use:

$quote->getShippingAddress()
            ->setShippingMethod('flatrate4_flatrate4')
            ->setShippingDescription('Description')
            ->setShippingAmount($amount)
            ->save();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.