Example #1
0
 /**
  * Event fired before updating items in cart so it add damage waiver flag to the buyRequest
  * @param Varien_Event_Observer $observer
  *
  * @throws Exception
  */
 public function checkDamageWaiver(Varien_Event_Observer $observer)
 {
     $data = $observer->getInfo();
     /** @var $quote Mage_Sales_Model_Quote */
     $quote = Mage::getSingleton('checkout/cart')->getQuote();
     foreach ($data as $itemId => $itemInfo) {
         $item = $quote->getItemById($itemId);
         if (!$item) {
             continue;
         }
         if (isset($itemInfo['damage_waiver'])) {
             $option = $item->getOptionByCode('info_buyRequest');
             $buyRequest = new Varien_Object($option ? unserialize($option->getValue()) : null);
             if ($itemInfo['damage_waiver']) {
                 $buyRequest->setDamageWaiver(1);
             } else {
                 $buyRequest->setDamageWaiver(0);
             }
             if ($option) {
                 $option->setValue(serialize($buyRequest->getData()));
             }
             $option->save();
         }
     }
 }