且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将产品添加到购物车之前的Magento事件

更新时间:2023-11-29 21:31:58

我将看看 catalog_product_get_final_price ,有关示例使用情况,请参阅 Mage_CatalogRule_Model_Observer :: processFrontFinalPrice() 。请注意,在此事件之后处理基于期权的定价;请参阅 Mage_Catalog_Model_Product_Type_Price :: getFinalPrice() Mage_Catalog_Model_Product_Type_Configurable_Price :: getFinalPrice()



请记住,定制此功能需要大量的测试,包括不同的报价状态,客户状态,产品类型等。例如,考虑添加到购物车中的产品第一次,然后从购物车更新其数量。通常有必要在几个方法/观察者中实现逻辑来处理所有排列。



客户未登录时,CE1.7中触发的事件的完整列表,新增购物车,简单产品:



controller_front_init_routers




  • Mage_Cms_Controller_Router :: initControllerRouters()



controller_action_predispatch




  • Mage_Log_Model_Visitor :: initByRequest()

  • Mage_PageCache_Model_Observer :: processPreDispatch()

  • Mage_Persistent_Model_Observer :: emulateQuote()

  • Mage_Persistent_Model_Observer_Session :: renewCookie()

  • Mage_Persistent_Model_Observer: :checkExpirePersistentQuote()

  • Mage_Persistent_Model_Observer :: emulateCustomer()



catalog_product_load_after




  • Mage_CatalogInventory_Model_Observer :: addInventoryData()



custom_quote_process




  • Mage_Persistent_Model_Observer :: setLoadPersistentQuote()



sales_quote_config_get_product_attributes




  • Mage_SalesRule_Model_Observer :: addProductAttributes()



prepare_catalog_product_collection_prices




  • Mage_CatalogRule_Model_Observer :: prepareCatalogProductCollectionPrices )



sales_quote_item_collection_products_after_load




  • Mage_CatalogInventory_Model_Observer :: addInventoryDataToCollection()



sales_quote_item_qty_set_after




  • Mage_CatalogInventory_Mo del_Observer :: checkQuoteItemQty()



sales_quote_collect_totals_before




  • Mage_Tax_Model_Observer :: quoteCollectTotalsBefore()



sales_quote_address_collect_totals_before




  • Mage_Sales_Model_Observer :: changeQuoteCustomerGroupId



sales_quote_address_collect_totals_after




  • Mage_Sales_Model_Observer :: restoreQuoteCustomerGroupId()



sales_quote_address_collect_totals_before




  • Mage_Sales_Model_Observer :: changeQuoteCustomerGroupId()



catalog_product_get_final_price




  • Mage_CatalogRule_Model_Observer :: processFrontFinalPrice()



sales_ quote_address_collect_totals_after




  • Mage_Sales_Model_Observer :: restoreQuoteCustomerGroupId()



sales_quote_collect_totals_after




  • code> Mage_Sales_Model_Observer :: setQuoteCanApplyMsrp()



sales_quote_save_before / p>


  • Mage_Persistent_Model_Observer :: setQuotePersistentData()



    • sales_quote_save_after




      • Mage_Checkout_Model_Observer :: salesQuoteSaveAfter()

      • Mage_Log_Model_Visitor :: bindQuoteCreate()



      sales_quote_item_save_before




      • Mage_Reports_Model_Event_Observer :: checkoutCartAddProduct()



      checkout_cart_add_product_complete




      • Mage_Wishlist_Model_Observer :: processAddToCart()



      $ _ code code code code code code code code code $ c
      $



    controller_front_send_response_after




    • code> Mage_Persistent_Model_Observer_Session :: synchronizePersistentInfo()


    I want to calculate price based on the customer selected options. For example,there are two configurable attributes length,width

    Before adding product to cart,I want to modify price based on selected length & width

$finalPrice=$rrp+($length*$width)

Is there any event available to achieve this?

I would look at catalog_product_get_final_price, and for an example usage, see Mage_CatalogRule_Model_Observer::processFrontFinalPrice(). Note that options-based pricing is processed after this event; see Mage_Catalog_Model_Product_Type_Price::getFinalPrice() and Mage_Catalog_Model_Product_Type_Configurable_Price::getFinalPrice().

Please keep in mind that customizing this functionality requires lots of testing with different quote states, customer states, product types, etc. For example, consider a product which is added to the cart for the first time, then having its quantity updated from the cart. Often it is necessary to implement logic in a couple of methods/observers to handle all permutations.

Full list for events fired in CE1.7 when customer not logged in, new cart, simple product:

controller_front_init_routers

  • Mage_Cms_Controller_Router::initControllerRouters()

controller_action_predispatch

  • Mage_Log_Model_Visitor::initByRequest()
  • Mage_PageCache_Model_Observer::processPreDispatch()
  • Mage_Persistent_Model_Observer::emulateQuote()
  • Mage_Persistent_Model_Observer_Session::renewCookie()
  • Mage_Persistent_Model_Observer::checkExpirePersistentQuote()
  • Mage_Persistent_Model_Observer::emulateCustomer()

catalog_product_load_after

  • Mage_CatalogInventory_Model_Observer::addInventoryData()

custom_quote_process

  • Mage_Persistent_Model_Observer::setLoadPersistentQuote()

sales_quote_config_get_product_attributes

  • Mage_SalesRule_Model_Observer::addProductAttributes()

prepare_catalog_product_collection_prices

  • Mage_CatalogRule_Model_Observer::prepareCatalogProductCollectionPrices()

sales_quote_item_collection_products_after_load

  • Mage_CatalogInventory_Model_Observer::addInventoryDataToCollection()

sales_quote_item_qty_set_after

  • Mage_CatalogInventory_Model_Observer::checkQuoteItemQty()

sales_quote_collect_totals_before

  • Mage_Tax_Model_Observer::quoteCollectTotalsBefore()

sales_quote_address_collect_totals_before

  • Mage_Sales_Model_Observer::changeQuoteCustomerGroupId()

sales_quote_address_collect_totals_after

  • Mage_Sales_Model_Observer::restoreQuoteCustomerGroupId()

sales_quote_address_collect_totals_before

  • Mage_Sales_Model_Observer::changeQuoteCustomerGroupId()

catalog_product_get_final_price

  • Mage_CatalogRule_Model_Observer::processFrontFinalPrice()

sales_quote_address_collect_totals_after

  • Mage_Sales_Model_Observer::restoreQuoteCustomerGroupId()

sales_quote_collect_totals_after

  • Mage_Sales_Model_Observer::setQuoteCanApplyMsrp()

sales_quote_save_before

  • Mage_Persistent_Model_Observer::setQuotePersistentData()

sales_quote_save_after

  • Mage_Checkout_Model_Observer::salesQuoteSaveAfter()
  • Mage_Log_Model_Visitor::bindQuoteCreate()

sales_quote_item_save_before

  • Mage_Reports_Model_Event_Observer::checkoutCartAddProduct()

checkout_cart_add_product_complete

  • Mage_Wishlist_Model_Observer::processAddToCart()

controller_action_postdispatch

  • Mage_Log_Model_Visitor::saveByRequest()

controller_front_send_response_after

  • Mage_Persistent_Model_Observer_Session::synchronizePersistentInfo()