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

1 Answer 1

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();
2
  • 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 Commented Oct 5, 2016 at 11:52
  • Its my pleasure.
    – InfoBeans
    Commented Oct 6, 2016 at 4:59

Your Answer

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

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