Magento event before adding product to cart

I want to calculate the price based on your chosen customers. For example, there are two custom attributes length,width

Before adding an item to the cart, I want to change the price based on the selected length and width

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

Is there any event to achieve this?

+4
source share
1 answer

I would look at catalog_product_get_final_price , and a usage example at Mage_CatalogRule_Model_Observer::processFrontFinalPrice() . Please note that after this event prices are processed based on options; see Mage_Catalog_Model_Product_Type_Price::getFinalPrice() and Mage_Catalog_Model_Product_Type_Configurable_Price::getFinalPrice() .

Please keep in mind that setting up this feature requires a lot of testing with different quotation states, customer states, product types, etc. For example, consider a product that was first added to the cart, then updating its quantity from the cart. It is often necessary to implement logic in several methods / observers to handle all permutations.

Full list of events released in CE1.7 when a client is 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()
+9
source

Source: https://habr.com/ru/post/1435491/


All Articles