Skip to content

Commit

Permalink
rebased on main
Browse files Browse the repository at this point in the history
  • Loading branch information
fballiano committed May 12, 2023
1 parent 4da40b1 commit 5a4fc0c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/code/core/Mage/Checkout/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<fields>
<delete_quote_after translate="label">
<label>Quote Lifetime (days)</label>
<validate>validate-not-negative-number</validate>
<sort_order>1</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
Expand Down
17 changes: 10 additions & 7 deletions app/code/core/Mage/Sales/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,27 @@ class Mage_Sales_Model_Observer
public function cleanExpiredQuotes($schedule)
{
Mage::dispatchEvent('clear_expired_quotes_before', ['sales_observer' => $this]);

$lifetimes = Mage::getConfig()->getStoresConfigByPath('checkout/cart/delete_quote_after');
foreach ($lifetimes as $storeId => $lifetime) {
$lifetime = (int)$lifetime * 86400;

/** @var Mage_Sales_Model_Resource_Quote_Collection $quotes */
$quotes = Mage::getModel('sales/quote')->getCollection();
foreach ($lifetimes as $storeId => $day) {
$day = (int) $day;
$lifetime = 86400 * $day;

/** @var Mage_Sales_Model_Resource_Quote_Collection $quotes */
$quotes = Mage::getResourceModel('sales/quote_collection');
$quotes->addFieldToFilter('store_id', $storeId);
$quotes->addFieldToFilter('updated_at', ['to' => date("Y-m-d", time() - $lifetime)]);
$quotes->addFieldToFilter('is_active', 0);
$quotes->addFieldToFilter('updated_at', ['to' => date('Y-m-d', time() - $lifetime)]);
if ($day == 0) {
$quotes->addFieldToFilter('is_active', 0);
}

foreach ($this->getExpireQuotesAdditionalFilterFields() as $field => $condition) {
$quotes->addFieldToFilter($field, $condition);
}

$quotes->walk('delete');
}

return $this;
}

Expand Down

0 comments on commit 5a4fc0c

Please sign in to comment.