20

tl;dr: 注文に変換されなかった見積もりレコードを削除するための、すぐに使用できるメカニズムは他にないようです。

Mage_Salesモジュールには期限切れの見積もりを消去するスケジュールされたジョブがありますが、これは非アクティブとしてマークされたレコード (つまり ) のみを削除しsales_flat_quoteますis_active = 0。私の知る限り、見積もりが注文に変換されたときにのみ、見積もりは無効としてマークされます。この場合、quote テーブルはますます大きくなるだけです。

参照Mage_Sales_Model_Observer::cleanExpiredQuotes()

class 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');
        }
        return $this;
    }

    //...
}
4

1 に答える 1

9

独自のクリーンアップ ルーチンでオブザーバーを上書きします。特定の期間、特定の見積もりを保持するため、4 段階の削除があります。ゲスト カートはリメールを受信し、回復可能です。空の登録済みの顧客の見積もりは、完了した見積もりの​​ほかに期限切れになり、コンテンツを含む登録済みのカートは、観察された顧客の行動ごとに長期間保存されます。

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category    Mage
 * @package     Mage_Sales
 * @copyright   Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * Sales observer
 *
 * @category   Chief
 * @package    Chief_Sales
 * @author     Magento Core Team <core@magentocommerce.com>
 */

/* Valid for 1.4.2.0, 1.5.1.0 */

class Chief_Sales_Model_Observer extends Mage_Sales_Model_Observer
{
    /**
     * Clean expired quotes (cron process)
     *
     * @param Mage_Cron_Model_Schedule $schedule
     * @return Mage_Sales_Model_Observer
     */
    public function cleanExpiredQuotes($schedule)
    {
        $lifetimes = Mage::getConfig()->getStoresConfigByPath('checkout/cart/delete_quote_after');

        /* Quotes converted to orders */
        foreach ($lifetimes as $storeId=>$lifetime) {
            $lifetime *= 86400;

            $quotes = Mage::getModel('sales/quote')->getCollection();
            /* @var $quotes Mage_Sales_Model_Mysql4_Quote_Collection */

            $quotes->addFieldToFilter('store_id', $storeId);
            $quotes->addFieldToFilter('updated_at', array('to'=>date("Y-m-d", time()-$lifetime)));
            $quotes->addFieldToFilter('is_active', 0);            // Filled Quotes
            $quotes->walk('delete');
        }


        /* Quotes abandoned by Guest Carts */
        foreach ($lifetimes as $storeId=>$lifetime) {
            $lifetime *= 86400;

            // triple lifetime for abandoned cart remail
            $lifetime *= 3;

            $quotes = Mage::getModel('sales/quote')->getCollection();
            /* @var $quotes Mage_Sales_Model_Mysql4_Quote_Collection */

            $quotes->addFieldToFilter('store_id', $storeId);
            $quotes->addFieldToFilter('updated_at', array('to'=>date("Y-m-d", time()-$lifetime)));
            $quotes->addFieldToFilter('is_active', 1);            // Active Quotes
            $quotes->addFieldToFilter('customer_group_id', 0);    // Which are Group NLI (Guest)
            $quotes->walk('delete');
        }


        /* Quotes abandoned by Registered carts no contents */
        foreach ($lifetimes as $storeId=>$lifetime) {
            $lifetime *= 86400;

            $quotes = Mage::getModel('sales/quote')->getCollection();
            /* @var $quotes Mage_Sales_Model_Mysql4_Quote_Collection */

            $quotes->addFieldToFilter('store_id', $storeId);
            $quotes->addFieldToFilter('updated_at', array('to'=>date("Y-m-d", time()-$lifetime)));
            $quotes->addFieldToFilter('is_active', 1);                      // Active Quotes
            $quotes->addFieldToFilter('customer_group_id', array('gt'=>0)); // For all other groups
            $quotes->addFieldToFilter('items_qty', 0);                      // For empty carts
            $quotes->walk('delete');
        }


        /* Quotes abandoned by Registered carts */
        foreach ($lifetimes as $storeId=>$lifetime) {
            $lifetime *= 86400;

            // Registered cart lifetime for abandoned cart remail 7*25 = 175 days
            $lifetime *= 25;

            $quotes = Mage::getModel('sales/quote')->getCollection();
            /* @var $quotes Mage_Sales_Model_Mysql4_Quote_Collection */

            $quotes->addFieldToFilter('store_id', $storeId);
            $quotes->addFieldToFilter('updated_at', array('to'=>date("Y-m-d", time()-$lifetime)));
            $quotes->addFieldToFilter('is_active', 1);                      // Active Quotes
            $quotes->addFieldToFilter('customer_group_id', array('gt'=>0)); // For all other groups
            $quotes->addFieldToFilter('items_qty', array('gt'=>0));         // For expired carts
            $quotes->walk('delete');
        }
        return $this;
    }
}
于 2014-07-22T22:08:32.933 に答える