Bit of Background
A client is using Bronto to send emails to site visitors that have abandoned their shopping cart in Magento. Bronto grabs the Abandoned Carts from Magento's reports. The issue that the client ran into is that he noticed that shopping carts that have been placed as orders in Magento are not being removed from the abandoned shopping cart report causing him to accidentally send emails about an abandoned cart to customers that have already placed the order.
What I did
I took a look and tried to find one main reason why this occurred, but I couldn't find any. I tried doing a test order myself and noticed that as soon as I add an item to the shopping cart my cart is considered an abandoned cart. I think to myself "weird, this should consider it abandoned if my session expires and I haven't checked-out." I did a bit of research to see if anyone had this same exact issue, but no luck, close though. The next step that I took was turn on Persistent Shopping Cart. I turned on persistence, but that didn't help because my cart was still being sent to the Abandoned Carts report. Even after I checked-out the cart remained in the report. I then created a Module that observed the sales_order_place_after event. This module checks the order after being placed and inactivates the quote("the abandoned cart" when a user is logged-in) that the order was created from. Inactivating the quote removes the cart from the abandoned carts report. This works fine but some quotes seem to slip through the cracks and don't get set to inactive, not sure why.
My Questions
1. Why does Magento automatically consider a cart abandoned as soon as you add an item to it?
2. Where and how can I change this?
3. Why doesn't the persistent shopping cart do what it's said to do? (not send cart to abandoned cart unless the persistent session expires or am I just not understanding the persistent shopping cart functionality, please explain)
4. What causes some of the quotes not to be set to inactive by my module?(I've shown the code below. config.xml and Observer.php)
5. Am I using the correct event?
config.xml
<config>
<modules>
<RIS_AbandonedCartCleanUp>
<version>0.0.1</version>
</RIS_AbandonedCartCleanUp>
</modules>
<global>
<!-- Define the Model -->
<models>
<abandonedcartcleanup>
<class>RIS_AbandonedCartCleanUp_Model</class>
</abandonedcartcleanup>
</models>
<events>
<sales_order_place_after>
<observers>
<abandonedcartcleanup>
<type>singleton</type>
<class>RIS_AbandonedCartCleanUp_Model_Observer</class>
<method>remove_order_quote</method>
</abandonedcartcleanup>
</observers>
</sales_order_place_after>
</events>
</global>
</config>
Observer.php
<?php
class RIS_AbandonedCartCleanUp_Model_Observer{
public function __construct(){
}
//Keep an eye out for when all the sales order saves have been committed
public function remove_order_quote($observer){
// Gets the order which is being saved.
$order = $observer->getOrder();
$quoteId = $order->getQuoteId();
//Get the quote for this specific order
$quote = Mage::getModel('sales/quote')->load($quoteId);
//Check if the quote is active
if($quote->getIsActive() == 1){
//set the quote to inactive and save
$quote->setIsActive('0')
->save();
}
}
}
?>