Observador no disparar
-
16-10-2019 - |
Pregunta
Se puede ver por qué mi observador no está disparando?
config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Caitlinhavener_Dynamicprice>
<version>0.1.0</version>
</Caitlinhavener_Dynamicprice>
</modules>
<global>
<models>
<chdispatcher>
<class>Caitlinhavener_Dynamicprice_Model</class>
</chdispatcher>
</models>
<frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<modify_to_custom_price>
<class>Caitlinhavener_Dynamicprice_Model_Observer</class>
<method>modifyPrice</method>
</modify_to_custom_price>
</observers>
</checkout_cart_product_add_after>
</events>
</frontend>
</global>
</config>
Observer.php:
<?php
Mage::log('Im here')
or exit("unable to log");
class Caitlinhavener_Dynamicprice_Model_Observer
{
public function modifyPrice(Varien_Event_Observer $obs)
{
// Get the quote item
$item = $obs->getQuoteItem();
Mage::log('Get Quote Item '. var_dump($_item->debug());
// Ensure we have the parent item, if it has one
$item = ( $item->getParentItem() ? $item->getParentItem() : $item );
Mage::log('Get parent item ' . var_dump($_item->debug());
// Load the custom price
//$price = "your custom price logic";
$price = Mage::registry('dynamic_tier_price');
Mage::log('Price is ' . $price);
// Set the custom price
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
// Enable super mode on the product.
$item->getProduct()->setIsSuperMode(true);
Mage::log('Item after super mode ' . var_dump($_item->debug());
}
}
?>
Tanto @airhorse y @philwinkle tenían las respuestas correctas. Que tenía que hacer todas estas cosas para que funcione.
Solución
Un par de cosas:
El modelo se define como:
<class>Caitlinhavener_Dynamicprice_Model_Observer</class>
¿Qué está buscando el archivo de clase en el Caitlinhavener/Dynamicprice/Model/Observer/Observer.php
estructura de carpetas.
Cambiar esta línea:
<class>Caitlinhavener_Dynamicprice_Model</class>
Del mismo modo, usted tiene un problema en el modelo / método en su detector de eventos - el cambio a:
<class>chdispatcher/observer</class>
Editar
Frontend no debe estar dentro de anidado de <global>
:
<global>
<models>
<chdispatcher>
<class>Caitlinhavener_Dynamicprice_Model</class>
</chdispatcher>
</models>
</global>
<frontend>
<events>
<checkout_cart_product_add_after>
<observers>
<modify_to_custom_price>
<class>chdispatcher/observer</class>
<method>modifyPrice</method>
</modify_to_custom_price>
</observers>
</checkout_cart_product_add_after>
</events>
</frontend>
Otros consejos
You need to redeclare your models and take your events tag out of the frontend tag. See below.
<config>
<modules>
<Caitlinhavener_Dynamicprice>
<version>0.1.0</version>
</Caitlinhavener_Dynamicprice>
</modules>
<global>
<models>
<dispatcher>
<class>Caitlinhavener_Dynamicprice_Model</class>
</dispatcher>
</models>
<events>
<checkout_cart_product_add_after>
<observers>
<modify_to_custom_price>
<class>caitlinhavener_dynamicprice/observer</class>
<method>modifyPrice</method>
</modify_to_custom_price>
</observers>
</checkout_cart_product_add_after>
</events>
</global>
</config>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange