I am working on the process of integrating third party tracking code into Magento 1.9.3.3 and managed to add tracking for customer registration, Add to cart, Successful checkout.
But Remove an item from cart is not been able to trigger the tracking code. Please have a look on my code and let me know valuable suggestions.
My config.xml code:
<events>
<sales_quote_remove_item>
<observers>
<sales_quote_remove_item_smartech>
<class>smartech/observer</class>
<method>removeFromCartScript</method>
</sales_quote_remove_item_smartech>
</observers>
</sales_quote_remove_item>
</events>
My observer code:
public function removeFromCartScript ($observer) {
$item = $observer->getEvent()->getQuoteItem();
$p_url = $item->getUrl();
$p_id = $item->getId();
$p_name = $item->getName();
$p_qty = $item->getQty();
$p_price = $item->getFinalPrice();
Mage::getSingleton('core/session')->setProductFromShoppingCart('remove_from_cart');
$removeProductVariable = Mage::getSingleton('core/session')->getProductFromShoppingCart();
Mage::log("Session Variable: ".$removeProductVariable, null, "smartech.log");
}
and my PHTML code:
<?php
$removeProductVariable = Mage::getModel('core/session')->getProductFromCart();
if($removeProductVariable === 'remove_from_cart') {
echo "Remove from cart called";
?>
<script>
//Following script need to be triggered with deleted product details respectively
smartech('dispatch', 5, {
"s^prurl": "<?php echo $p_url ?>",
"i^prid": "<?php echo $p_id ?>",
"s^prname": "<?php echo $p_name ?>",
"i^prqt": "<?php echo $p_qty ?>",
"f^prprice": "<?php echo number_format((float)$p_price, 2, '.', '')?>"
});
</script>
<?php
// Clear add_to_cart session variable:
Mage::getModel('core/session')->unsProductFromCart();
}
?>