From time to time it is necessary to clear users’ unused shopping carts, especially for guest users. This feature has already been added with the last versions of Mаgentо. But for old versions, you can use a cron which would clear users’ shopping carts at the specified time. To do this, you should create a model and set up time to call methods for cleaning shopping carts.
So, let’s create a module with “clearing” methods:
Partner With Us
Let's discuss how to grow your business. Get a Free Quote.
Talk to Vlad
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
… /** * Clear the users. */ public function clearCustomer() { $sql = sprintf('DELETE FROM %s WHERE NOT ISNULL(customer_id) AND updated_at < DATE_SUB(Now(), INTERVAL %s DAY) LIMIT %s', $this->getQuoteTableName(), $this->getSqlСondition('customer'), $this->getLimit() ); $this->getConnection()->query($sql); } /** * Clear the guests. */ public function clearGuest() { $sql = sprintf('DELETE FROM %s WHERE ISNULL(customer_id) AND updated_at < DATE_SUB(Now(), INTERVAL %s DAY) LIMIT %s', $this->getQuoteTableName(), $this->getSqlСondition('anonymous'), $this->getLimit() ); $this->getConnection()->query($sql); } … |
And register a cron job.
1 2 3 4 5 6 7 8 9 10 11 12 |
<crontab> <jobs> <belvg_cartclear> <schedule> <config_path>belvg_cartclear/settings/scheduler</config_path> </schedule> <run> <model>belvg_cartclear/sales_quote::run</model> </run> </belvg_cartclear> </jobs> </crontab> |
To refine module methods you should set up cron for website.
Partner With Us
Looking for a partner that will help you to grow your business? We are the right company to develop your webstore. Feel free to get in touch with us. We will be happy to discuss your business opportunities and provide you with a Free Quote.
Talk to Vlad
I have read your code for shopping cart which is really nice but I am confused from Clear the Guest function which you have written last in the program. Could you please clear my doubts about ClearGuest() ? Thanks in advance.