1

I have been trying figure out past 3 days but in vain, iam looking to send a reminder email to customers to reorder their previous purchase. Magento reorder function works with logged in customers with www.yourdomain.com/sales/order/reorder/{order_id} which adds the items from their previous orders to their shopping cart. But if the customer is not signed in it redirects to a guest form. i want to load items from a previous order to their shopping cart even if they are not logged in. so when customer clicks a link, he is then redirected to the checkout/cart page with all items from their previous order. i tried using the following code

<?php
include_once 'app/Mage.php';
Mage::app();
$orderId= '2986';
$quote = Mage::getModel('sales/order')->load($orderId);
$cart->init();
$cart = Mage::getModel('sales/quote')->load($quote);
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
$this->_redirect('checkout/cart');
?>
0

Please use below code for create order based on order id, You can make a link with this order id,

For this you can make an observere before load cart page.

$order=Mage::getModel('sales/order')->load(2); // 2 is order entity_id
 $cart = Mage::getSingleton('checkout/cart');

 $items = $order->getItemsCollection();

 foreach ($items as $item) {
            try {
                $cart->addOrderItem($item);
            } catch (Mage_Core_Exception $e){
                if (Mage::getSingleton('checkout/session')->getUseNotice(true)) {
                    Mage::getSingleton('checkout/session')->addNotice($e->getMessage());
                }
                else {
                    Mage::getSingleton('checkout/session')->addError($e->getMessage());
                }

            } catch (Exception $e) {
                Mage::getSingleton('checkout/session')->addException($e,
                    Mage::helper('checkout')->__('Cannot add the item to shopping cart.')
                );

            }
        }

$cart->save();
  • it throws an error stating customer session already exist. i then added $cart->init(); above $items = $order->getItemsCollection(); and it worked. Thank you very much for help.you saved my day @InfoBeans – Venu Prasath Oct 5 '16 at 11:52
  • Its my pleasure. – InfoBeans Oct 6 '16 at 4:59

Your Answer

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

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