/** * Calculate discounts by sales rules * @param Varien_Event_Observer $observer */ public function salesruleProcess($observer) { $quote = $observer->getQuote(); $address = $observer->getAddress(); $rule = $observer->getRule(); $discounts = @unserialize($quote->getAuctaneapiDiscounts()); if (!self::$_counter) { $discounts = array(); $address->setBaseShippingDiscountAmount(0); self::$_counter++; } if (!isset(self::$_shippingAmountProcessed[$rule->getId()]) && $address->getShippingAmount()) { $shippingAmount = $address->getShippingAmountForDiscount(); if ($shippingAmount !== null) { $baseShippingAmount = $address->getBaseShippingAmountForDiscount(); } else { $baseShippingAmount = $address->getBaseShippingAmount(); } //check for discount applied on shipping amount or not if (!$rule['apply_to_shipping']) { $baseShippingAmount = 0; } $baseDiscountAmount = 0; $rulePercent = min(100, $rule->getDiscountAmount()); switch ($rule->getSimpleAction()) { case Mage_SalesRule_Model_Rule::TO_PERCENT_ACTION: $rulePercent = max(0, 100 - $rule->getDiscountAmount()); case Mage_SalesRule_Model_Rule::BY_PERCENT_ACTION: $baseDiscountAmount = ($baseShippingAmount - $address->getBaseShippingDiscountAmount()) * $rulePercent / 100; break; case Mage_SalesRule_Model_Rule::TO_FIXED_ACTION: $baseDiscountAmount = $baseShippingAmount - $rule->getDiscountAmount(); break; case Mage_SalesRule_Model_Rule::BY_FIXED_ACTION: $baseDiscountAmount = $rule->getDiscountAmount(); break; case Mage_SalesRule_Model_Rule::CART_FIXED_ACTION: self::$_cartRules = $address->getCartFixedRules(); if (!isset(self::$_cartRules[$rule->getId()])) { self::$_cartRules[$rule->getId()] = $rule->getDiscountAmount(); } if (self::$_cartRules[$rule->getId()] > 0) { $baseDiscountAmount = min($baseShippingAmount - $address->getBaseShippingDiscountAmount(), self::$_cartRules[$rule->getId()]); self::$_cartRules[$rule->getId()] -= $baseDiscountAmount; } break; } $ruleDiscount = 0; $left = $baseShippingAmount - ($address->getBaseShippingDiscountAmount() + $baseDiscountAmount); if ($left >= 0) { $ruleDiscount = $baseDiscountAmount; } $discounts[$rule->getId() . '-' . $observer->getItem()->getId() . '-' . uniqid()] = $observer->getResult()->getBaseDiscountAmount() + $ruleDiscount; $address->setBaseShippingDiscountAmount(min($address->getBaseShippingDiscountAmount() + $baseDiscountAmount, $baseShippingAmount)); self::$_shippingAmountProcessed[$rule->getId()] = true; } else { $discounts[$rule->getId() . '-' . $observer->getItem()->getId() . '-' . uniqid()] = $observer->getResult()->getBaseDiscountAmount(); } $quote->setAuctaneapiDiscounts(@serialize($discounts)); }
public function salesConvertQuoteItemToOrderItem(Varien_Event_Observer $observer) { $quoteItem = $observer->getItem(); if ($additionalOptions = $quoteItem->getOptionByCode('additional_options')) { $orderItem = $observer->getOrderItem(); $options = $orderItem->getProductOptions(); $options['additional_options'] = unserialize($additionalOptions->getValue()); $orderItem->setProductOptions($options); } }
/** * Save additional (subscription) product options (added in addSubscriptionProductSubscriptionToQuote) * from quote items to order items * * @event sales_convert_quote_item_to_order_item * @param Varien_Event_Observer $observer */ public function addSubscriptionProductSubscriptionToOrder(Varien_Event_Observer $observer) { /** @var Mage_Sales_Model_Quote_Item $quoteItem */ /** @noinspection PhpUndefinedMethodInspection */ $quoteItem = $observer->getItem(); /** @var Mage_Sales_Model_Order_Item $orderItem */ /** @noinspection PhpUndefinedMethodInspection */ $orderItem = $observer->getOrderItem(); if ($additionalOptions = $quoteItem->getOptionByCode('additional_options')) { $options = $orderItem->getProductOptions(); $options['additional_options'] = unserialize($additionalOptions->getValue()); $orderItem->setProductOptions($options); } }
/** * Change deal_qty and deal_bought when item cancel * * @param Varien_Event_Observer $observer observed object */ public function salesOrderItemCancel(Varien_Event_Observer $observer) { $item = $observer->getItem(); if ($item->getDealStat()) { $product = Mage::getModel('catalog/product')->load($item->getProductId()); $product->setDealQty($product->getDealQty() + $item->getQtyOrdered())->setDealBought($product->getDealBought() - $item->getQtyOrdered())->save(); } }
public function catalogInventorySave(Varien_Event_Observer $observer) { $product = $observer->getItem(); $this->updateStock($product->getProductId()); }
/** * Listener to update $this->_lastUpdatedItem. * @param Varien_Event_Observer $observer * @return void */ public function checkoutCartUpdateItemComplete(Varien_Event_Observer $observer) { $this->_lastUpdatedItem = $observer->getItem(); }
/** * Refresh stock related ddq cache when saving a stock item. * * @param Varien_Event_Observer $observer */ public function refreshDdqCache(Varien_Event_Observer $observer) { if ($observer && $observer->getItem() && $observer->getItem()->getProduct()) { Mage::helper('ddq/cache')->clean(array('tag' => Mage_Catalog_Model_Product::CACHE_TAG . '_' . $observer->getItem()->getProduct()->getId())); } }
/** * When product is added to shopping cart add an entry to reservationquotes with reservation data * @param Varien_Event_Observer $event * * @return $this */ public function updateCartReservation(Varien_Event_Observer $event) { /** @var $quoteItem Mage_Sales_Model_Quote_Item */ $quoteItem = $event->getItem(); /** @var $product Mage_Catalog_Model_Product */ $product = $quoteItem->getProduct(); $source = unserialize($product->getCustomOption('info_buyRequest')->getValue()); if ($this->excludedFromUpdate($quoteItem, $source)) { return $this; } list($startDateArr, $endDateArr) = ITwebexperts_Payperrentals_Helper_Data::getStartEndDates($source); foreach ($startDateArr as $count => $startDate) { $endDate = $endDateArr[$count]; if ($quoteItem->getProductType() != ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE_BUNDLE) { $qty = $this->getSelectedQtyByTheCustomerForTheProduct($product, $quoteItem); $product = $this->getProduct($product, $source); if ($quoteItem->getProductType() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) { Mage::getResourceModel('payperrentals/reservationquotes')->deleteByQuoteItemAndDates($quoteItem, $startDate, $endDate); $this->saveSimpleReservationProduct($quoteItem, $product, $source, $qty, $startDate, $endDate); } $this->saveConfigurableReservationProduct($quoteItem, $product, $source, $qty, $startDate, $endDate); } else { $qty = $this->getSelectedQtyByTheCustomerForTheProduct($product, $quoteItem); ITwebexperts_Payperrentals_Helper_Data::createQuantities($source, $qty, true); $selectionIds = $source['bundle_option']; $selections = $product->getTypeInstance(true)->getSelectionsByIds($selectionIds, $product); Mage::getResourceModel('payperrentals/reservationquotes')->deleteByQuoteItemAndDates($quoteItem, $startDate, $endDate); foreach ($selections->getItems() as $selection) { if ($selection->getTypeId() == ITwebexperts_Payperrentals_Helper_Data::PRODUCT_TYPE) { $qty = ITwebexperts_Payperrentals_Helper_Data::getQuantityForSelectionProduct($selection, $qty); $this->saveSimpleReservationProduct($quoteItem, $selection, $source, $qty, $startDate, $endDate); } } } } return $this; }
/** * Add item option hash to checkout session. This is for comparison * checks when adding new items to the cart in order to determine * which item the requested one should be merged with, if any. * * @param Varien_Event_Observer $observer */ public function addOptionHashToSession(Varien_Event_Observer $observer) { if (Mage::helper('ddq')->isEnabled()) { try { if ($observer->getItem() && $observer->getItem()->getId()) { // retrieve cart item option hash as separation identification $optionHash = Mage::helper('ddq')->getCartItemOptionHash($observer->getItem(), array('info_buyRequest', 'ddq_identifier')); if (!is_null($optionHash)) { // retrieve stored option hash / item id pairings for comparison check $optionHashTable = Mage::getSingleton('checkout/session')->getData(self::OPTION_HASH_TABLE_KEY); if (!is_array($optionHashTable)) { $optionHashTable = array(); } if (!isset($optionHashTable[$optionHash])) { $optionHashTable[$optionHash] = array(); } foreach ($optionHashTable as &$ids) { if (($key = array_search($observer->getItem()->getId(), $ids)) !== false) { unset($ids[$key]); } } // add the option hash to the table $optionHashTable[$optionHash][] = $observer->getItem()->getId(); // re-save the table in the session Mage::getSingleton('checkout/session')->setData(self::OPTION_HASH_TABLE_KEY, $optionHashTable); } } } catch (Exception $e) { Mage::helper('ddq')->log($e); } } }
/** * change product price for mtm products (made to measure) * * @param Varien_Event_Observer $observer */ public function mtmProductModifyUpdateItem(Varien_Event_Observer $observer) { $item = $observer->getItem(); $this->_mtmProductModifyPrice($item); }