예제 #1
0
 /**
  * Update cart on update-items action
  *
  * @param $observer
  * @return $this
  */
 public function updateGiftCart($observer)
 {
     if ($this->_helper->productGiftEnabled() && $this->_helper->productGiftStrategy()) {
         $cart = $observer->getEvent()->getCart();
         $cart_info = $observer->getEvent()->getInfo();
         $prev_item = null;
         foreach ($cart_info as $itemId => $itemInfo) {
             $item = $cart->getQuote()->getItemById($itemId);
             $qty = isset($itemInfo['qty']) ? (double) $itemInfo['qty'] : false;
             $gift_attr = $item->getOptionByCode('gift_for_product_id');
             if ($gift_attr && $gift_attr->getValue() && $prev_item->getOrigData('qty') != $prev_item->getQty()) {
                 try {
                     $item->setQty($prev_item->getQty());
                 } catch (Exception $e) {
                     Mage::getSingleton('core/session')->addError('You can\'t change gift quantity: ' . $e->getMessage());
                 }
             }
             $prev_item = $item;
         }
     }
     return $this;
 }