I'm trying to execute the following Method with the Observer in my Magento module. But it isn't working and I don't know why.
This is my config.xml
<?xml version="1.0"?>
<config>
<modules>
<TimgMage_CustomAddToCart>
<version>0.0.1</version>
</TimgMage_CustomAddToCart>
</modules>
<global>
<models>
<TimgMage_CustomAddToCart>
<class>TimgMage_CustomAddToCart_Model</class>
</TimgMage_CustomAddToCart>
</models>
<events>
<!-- START: Add to cart actions -->
<checkout_cart_product_add_after>
<observers>
<timgmage_customaddtocart_model_observer>
<class>TimgMage_CustomAddToCart_Model_Observer</class>
<method>checkoutCartProductAddAfter</method>
<type>singleton</type>
</timgmage_customaddtocart_model_observer>
</observers>
</checkout_cart_product_add_after>
</events>
</global>
</config>
And the observer
<?php
class TimgMage_CustomAddToCart_Model_Observer
{
public function checkoutCartProductAddAfter(Varien_Event_Observer $observer) {
Mage::log('Entered to checkoutCartProductAddAfter.', null, 'timgmage.log');
/* @var $item Mage_Sales_Model_Quote_Item */
$item = $observer->getQuoteItem();
if ($item->getParentItem()) {
$item = $item->getParentItem();
}
// Discounted 25% off
$percentDiscount = 0.25;
// This makes sure the discount isn't applied over and over when refreshing
$specialPrice = $item->getOriginalPrice() - ($item->getOriginalPrice() * $percentDiscount);
// Make sure we don't have a negative
if ($specialPrice > 0) {
$item->setCustomPrice($specialPrice);
$item->setOriginalCustomPrice($specialPrice);
$item->getProduct()->setIsSuperMode(true);
}
}
}
Please anybody can help me.
controller_action_predispatch_checkout_cart_add
instead.