-
-
Save arush/1940064 to your computer and use it in GitHub Desktop.
Remove quotes that belong to anonymous users with expired cookies (because they'll never be able to retrieve them)
This file contains hidden or 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
/** | |
* Clean expired quotes (cron process) | |
* | |
* @param Mage_Cron_Model_Schedule $schedule | |
* @return Mage_Sales_Model_Observer | |
*/ | |
public function cleanExpiredQuotes($schedule) | |
{ | |
Mage::dispatchEvent('clear_expired_quotes_before', array('sales_observer' => $this)); | |
$lifetimes = Mage::getConfig()->getStoresConfigByPath('checkout/cart/delete_quote_after'); | |
foreach ($lifetimes as $storeId=>$lifetime) { | |
$lifetime *= 86400; | |
/** @var $quotes Mage_Sales_Model_Mysql4_Quote_Collection */ | |
$quotes = Mage::getModel('sales/quote')->getCollection(); | |
$quotes->addFieldToFilter('store_id', $storeId); | |
$quotes->addFieldToFilter('updated_at', array('to'=>date("Y-m-d", time() - $lifetime))); | |
$quotes->addFieldToFilter('is_active', 0); | |
foreach ($this->getExpireQuotesAdditionalFilterFields() as $field => $condition) { | |
$quotes->addFieldToFilter($field, $condition); | |
} | |
$quotes->walk('delete'); | |
} | |
$lifetimes = Mage::getConfig()->getStoresConfigByPath('web/cookie/cookie_lifetime'); | |
foreach ($lifetimes as $storeId=>$lifetime) { | |
/** @var $quotes Mage_Sales_Model_Mysql4_Quote_Collection */ | |
$quotes = Mage::getModel('sales/quote')->getCollection(); | |
$quotes->addFieldToFilter('store_id', $storeId); | |
$quotes->addFieldToFilter('updated_at', array('to'=>date("Y-m-d", time() - $lifetime))); | |
$quotes->addFieldToFilter('customer_id', array("null" => 'dummy')); | |
foreach ($this->getExpireQuotesAdditionalFilterFields() as $field => $condition) { | |
$quotes->addFieldToFilter($field, $condition); | |
} | |
$quotes->walk('delete'); | |
} | |
return $this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment