Magento has a cron job for the deletion of expired quotes which hasn't changed since the first version I got in touch with, i.e. 1.6.

The cron job is located in Mage_Sales_Model_Observer::cleanExpiredQuotes() in Magento 1 and Magento\Sales\Cron\CleanExpiredQuotes in Magento 2.

The intention is clear: We have to do some housekeeping in the system and delete quotes we don't need anymore. In the understanding of Magento that are quotes which haven't been updated for more than X days (with X is configured value of quote lifetime for the store) and which are incative.

In what situation do we have incative quotes? A quote is inactivated after it has been converted to an order. The quote_id of the incative quote is stored in the order table.

And here is the first ilogic aspect of Magento's approach to delete inactive quotes:

When a quote older than X days will be deleted, the corresponding order has a "dead" link to non-existant quote. Most of the quote data is copied to corresponding sales_* tables and is not needed later. But at least at one point the order needs the quote: If you have an order item with a custom option of the type file. In this case the data of the uploaded file (i.e. the filename) comes from quote_item_option table and the download controller accesses directly \Magento\Quote\Model\Quote\Item\Option objects - this will obviously not work after the deletion of the quote although the file is still in the filesystem.

Another strange thing in the logic of quote housekeeping is the fact that quotes for guest users who don't by within the creation session will be kept forever in the database since they are active but with no customer_id.

My questions:

  • Did some of you already face the a problem with missing quotes for a placed order (for example not working download of custom option file) and how did you handle it?
  • Shouldn't the logic be rather: "delete active quotes with no customer_id and older than X days"?

For two earlier Magento 1 implementation I have overwritten Magento's cron but I'm not sure if I missing something in Magento's rationale to do things as they do.

Update: Some details about the custom options and the download controller, because it was asked in a comment:

The controller file is (Magento 2): vendor/magento/module-sales/Controller/Download/DownloadCustomOption.php

The uploaded files are stored in a subdirectory of pub/media/custom_options/quote, the filename and a secret_key are stored in a serialized json object in the value field in quote_item_option.

The download URL is like this: http://yourmagentosite/sales/download/downloadCustomOption/id/[quote_item_option.option_id]/key/[secret_key]/

When the quote of an order is deleted, the above link returns a 404 error because there is no corresponding entry in quote_item_option.

  • Can you give us the path of the download controller that accesses directly \Magento\Quote\Model\Quote\Item\Option objects ? It will help me to understand. Thanks. Feb 27 '19 at 17:17
  • @Julien Loizelet I have updated the question with some details
    – HelgeB
    Feb 28 '19 at 9:48
  • @Amit Bera The cron logic is unchanged in Magento since version 1.6, therefore the question is also relevant for Magento 1.9 ;-)
    – HelgeB
    Feb 28 '19 at 12:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.