2

I'm looking for a way to get magento quote created time, My goal is to get the quote created time & set 10 min timer , if customer checkout while 10min other wise i'll clear the cart items. Timer will refresh back to 10 min upon each new item inserted into cart.

Thanks in advance.

  • I'm not sure how but in sales_flat_quote you have the created at and updated at timestamp and you can get the difference – Nickool Apr 13 '15 at 0:47
  • hi am working on it .can you wait – Sourav Apr 18 '15 at 19:01
2

Hi I have found solution after some hardwork for your requirement.

Steps:1 In custom module's config.xml make two observers.

 <checkout_cart_product_add_after >
                 < observers >
                    <kinex_order >
                        <class> kinex_order/observer </class>
                         <method>catalogProduct </method >
                    </kinex_order >
                </observers >
             </checkout_cart_product_add_after >



<controller_action_predispatch >
                 < observers >
                    <kinex_order >
                        <class> kinex_order/observer </class>
                         <method>getControllerAction </method >
                    </kinex_order >
                </observers >
             </checkout_cart_product_add_after >

Methods:

/* This method set 10 mins after item added to quote object */

   public function catalogProduct(Varien_Event_Observer $observer)
    {

         $quote=Mage::getModel('checkout/cart')->getQuote();

        $removeQuoteTime=Mage::getSingleton('core/session')->getRemoveQuoteTime();   

           $updateAt=date('Y-m-d H:i:s');             
          if($removeQuoteTime){
           $updateAt=$removeQuoteTime;
          }
          else{
           $updateAt=strtotime(date('Y-m-d H:i:s'));
          }
         $currentDate = $updateAt;
         $removeQuoteTime=$currentDate+600;//10 mins add
         Mage::getSingleton('core/session')->setRemoveQuoteTime($removeQuoteTime);



    }


/* below method empty cart if customer does not checkout within 10 min  */

public function  getControllerAction (Varien_Event_Observer $observer){

$currentTime =strtotime(date('Y-m-d H:i:s'));      
    $removeQuoteTime=Mage::getSingleton('core/session')->getRemoveQuoteTime();
    //logic 

    if($currentTime < $removeQuoteTime){

    }else{
    $cartHelper = Mage::helper('checkout/cart');
        $items = $cartHelper->getCart()->getItems();        
        foreach ($items as $item) 
        {
        $itemId = $item->getItemId();
        $cartHelper->getCart()->removeItem($itemId)->save();
        } 
        Mage::getSingleton('core/session')->unsRemoveQuoteTime();    
    }    

}
| improve this answer | |
  • I'll try this & let you know, Thank you for your hard work, If its worked i'll accept it – Adeel Ishfaq Apr 19 '15 at 11:13

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.