Magento update item qty use observer events <checkoutITeye - AG环亚娱乐集团

Magento update item qty use observer events <checkoutITeye

2019-01-13 15:40:46 | 作者: 海昌 | 标签: 效劳,检测,存在 | 浏览: 2270

 there is a visual service item in cart, 

 every time change relation product ,  the service item will be change qty

 so add a Magento Observer model to approach it.

 

here is some content in the config.xml :

 global 
 helpers 
 mycheckout 
 class Bysoft_Mycheckout_Helper /class 
 /mycheckout 
 /helpers 
 models 
 mycheckout 
 class Bysoft_Mycheckout_Model /class 
 /mycheckout 
 /models 
 resources 
 bysoft_mycheckout_setup 
 setup 
 module Bysoft_Mycheckout /module 
 class Mage_Sales_Model_Mysql4_Setup /class 
 /setup 
 /bysoft_mycheckout_setup 
 /resources 
 events 
 checkout_cart_save_before !-- identifier of the event we want to catch -- 
 observers 
 checkout_cart_save_before_handler !-- identifier of the event handler -- 
 type model /type !-- class method call type; valid are model, object and singleton -- 
 class mycheckout/observer /class !-- observers class alias -- 
 method changeServiceItemQty /method !-- observers method to be called -- 
 args /args !-- additional arguments passed to observer -- 
 /checkout_cart_save_before_handler 
 /observers 
 /checkout_cart_save_before 
 /events 
 /global 

  PHP Model Class:

 ?php
class Bysoft_Mycheckout_Model_Observer
 public function changeServiceItemQty(Varien_Event_Observer $observer)
 $event = $observer- getEvent();
 $cart = $event- getCart(); 
 //检测安心厨房产品总价
 $semi_total = 0;
 $items= $cart- getQuote()- getAllItems();
 foreach ($items as $item) {
 $productId = $item- getProduct()- getId();
 $item_product = Mage::getModel(catalog/product)- load($productId);
 $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
 $attributeSetModel- load($item_product- getAttributeSetId());
 $attributeSetName = $attributeSetModel- getAttributeSetName();
 if ($attributeSetName == Semi Cooked $item- getData(product_type) == bundle) {
 $semi_total += $item- getRowTotalInclTax();
 //检测效劳item是否存在
 $item_exists = false;
 $item_exists_id = false;
 $item_exists_sku = false;
 $cartHelper = Mage::helper(checkout/cart);
 foreach ($items as $item) {
 $productId = $item- getProduct()- getId();
 $item_product = Mage::getModel(catalog/product)- load($productId);
 $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
 $attributeSetModel- load($item_product- getAttributeSetId());
 $attributeSetName = $attributeSetModel- getAttributeSetName();
 if ($attributeSetName == Chef Catering Services) {
 $item_exists = true;
 $item_exists_id = $item- getId();
 $item_exists_sku = $item_product- getSku();
 //更新已存在效劳数量
 $item- setQty(ceil(0.3*$semi_total));
 break;
 //假如semi cooked总金额小于1000. 将效劳item 删去
 if ($semi_total 1000 $item_exists) {
 foreach ($items as $item) {
 $productId = $item- getProduct()- getId();
 $item_product = Mage::getModel(catalog/product)- load($productId);
 $attributeSetModel = Mage::getModel("eav/entity_attribute_set");
 $attributeSetModel- load($item_product- getAttributeSetId());
 $attributeSetName = $attributeSetModel- getAttributeSetName();
 if ($attributeSetName == Chef Catering Services) { 
 $itemId = $item- getItemId();
 $cartHelper- getCart()- removeItem($itemId);
}

 

版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表AG环亚娱乐集团立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章