Last active
August 29, 2015 14:01
-
-
Save peterjaap/3fe834778bf79e2d3c1b to your computer and use it in GitHub Desktop.
Ebizmarts_AbandonedCart doesn't check whether a product that will be sent in an Abandoned Cart email is still available. This piece of code checks whether the product still exists, is enabled and has stock available (if stock is managed). If any of these 3 do not comply, the product is removed from the quote. Finally, we check whether there are …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Place this on line 117, right after foreach($collection as $quote) in app/code/community/Ebizmarts/AbandonedCart/Model/Cron.php */ | |
foreach($quote->getAllVisibleItems() as $item) { | |
$removeFromQuote = false; | |
$product = Mage::getModel('catalog/product')->load($item->getProductId()); | |
if(!$product || $product->getStatus() == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) | |
{ | |
Mage::log('AbandonedCart; ' . $product->getSku() .' is no longer present or enabled; remove from quote ' . $quote->getId() . ' for email',null,'Ebizmarts_AbandonedCart.log'); | |
$removeFromQuote = true; | |
} | |
$stock = $product->getStockItem(); | |
if( | |
( | |
$stock->getManageStock() || | |
($stock->getUseConfigManageStock() && Mage::getStoreConfig('cataloginventory/item_options/manage_stock', $quote->getStoreId())) | |
) | |
&& $stock->getQty() < $item->getQty()) | |
{ | |
Mage::log('AbandonedCart; ' . $product->getSku() .' is no longer in stock; remove from quote ' . $quote->getId() . ' for email',null,'Ebizmarts_AbandonedCart.log'); | |
$removeFromQuote = true; | |
} | |
if($removeFromQuote) | |
{ | |
$quote->removeItem($item->getId()); | |
} | |
} | |
if(count($quote->getAllVisibleItems()) < 1) | |
{ | |
srand((double)microtime()*1000000); | |
$token = md5(rand(0,9999999)); | |
$quote2 = Mage::getModel('sales/quote')->loadByIdWithoutStore($quote->getId()); | |
$quote2->setEbizmartsAbandonedcartCounter($quote2->getEbizmartsAbandonedcartCounter()+1); | |
$quote2->setEbizmartsAbandonedcartToken($token); | |
$quote2->save(); | |
continue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This pull request was merged in the new MageMonkey version! ebizmarts/magemonkey#8 (comment)