cancel
Showing results for 
Search instead for 
Did you mean: 

Call cart subtotal and items for a cart abandonment tracking service

Call cart subtotal and items for a cart abandonment tracking service

I have been asked to add a small script tag to our site to allow a third party service to track our abandoned carts so they can do marketing and retargeting. I wasn't given much information on how or where to implement this code, and I'm not very good with php (normally I stick to design and basic maintenance of the site). For now I'm planning on putting it in the footer.phtml of my theme so it doesn't hinder load times, although I may need to add it to the add to cart button itself. I am unsure which would be better.

 

The script tags normally reads 

<script type="text/javascript" src="{path to offsite JSfile}/?cart={ subtotal price in 00.00 format}&prodID={list of product skus separatd by commas}"></script>

with real values in the curly brackets. The values for the subtotal and items skus need to be dynamic obviously, and I'm having trouble getting the values. (Again, I'm terrible with php.)

 

so far i'm trying this for the code (which I am sure is way off but hey, you gotta start somewhere):

<?php
$checkoutSession = Mage::getSingleton('checkout/session');
$currentQuote = $checkoutSession->getQuote(); 
$items = $currentQuote->getAllItems();
foreach ($items as $item)
{
    $itemsingle = $item->getSku();
    $itemList.= $prefix.$itemsingle;
    $prefix = ', ';
};
$subTotal = $currentQuote->getSubtotal();
$finalcartabandoned='<script type="text/javascript" src="{file path to off site JS file}cart='.$subTotal."&prodID=";
$finalcartabandoned.=$items;
$finalcartabandoned.='"></script>';
echo $finalcartabandoned;
?>

It's not returning any values for either the subtotal or the items. I know for the items, that my code is probably terrible, but I was expecting the subtotals to return correctly. What am I doing wrong that the subtotals are not returning?

 

So far everything i've been seeing says that to call for the subtotal in the cart you use one of these:

Mage::helper('checkout/cart')->getQuote()->getSubtotal()
Mage::helper('checkout/session')->getQuote()->getSubtotal()
Mage::getSingleton('checkout/cart')->getQuote()->getSubtotal()
Mage::getSingleton('checkout/session')->getQuote()->getSubtotal()

but using those seem to create fatal errors. Splitting the code into chunks like in my current code method seems to mitigate that, but obviously something is wrong. 

 

What do I need to do?

2 REPLIES

Re: Call cart subtotal and items for a cart abandonment tracking service

If I understood it the right, by modifying your code in footer.phtml the following way:
https://www.gyazo.com/f087e15c06470dfc7d53adc025651194
You should get the desired result:
https://www.gyazo.com/3961e8d8f506c27db20ee22607fbbced

P.S. If that is not what you are looking for, please describe in more detail which parameters you would like to get?

P.S.S. just as a side note: you can get the subtotal this way, however, it's impossible to get product id using this scheme

 

 

______________________________________________________________
Innovative, top-performing Magento Extensions (with an array of FREE tools).

Re: Call cart subtotal and items for a cart abandonment tracking service

Thank you for the help! It seems to work as I need it to so far.