Skip to content

Instantly share code, notes, and snippets.

Inefficient Order Processing over Cron

I was able to run update_availability_status, update_sales_history, and execute_tasks without any issues, and I have them enabled with a cron running every 5 minutes.

I can bump the processing frequency up to 2 minutes as mentioned in the docs, if needed. But that shouldn't be necessary for the module to function, it should just increase the freshness of data.

I ran into a problem with the update_stocks task though. It's hitting a memory limit because of a very inefficient query. I traced it back to MDN_AdvancedStock_Helper_Product_Base on line 130. In my case I have like 14k order IDs that it's attempting to query.

It should be splitting the processing up in to chunks. Perhaps this is related to the problems in the initial order preparation step. Let me know.

Memory usage: real: 23855104, emalloc: 23466888
Code Profiler Time Cnt Emalloc RealMem
mage 56.8197 1 0 0
mage::app::init::system_config 0.0023 1 31,176 0
CORE::create_object_of::Mage_Core_Model_Cache 0.0023 2 138,728 262,144
mage::app::init::config::load_cache 0.0144 1 1,536 0
mage::app::init::stores 0.0203 1 1,458,984 1,572,864
CORE::create_object_of::Mage_Core_Model_Resource_Website 0.0004 1 21,128 0
CORE::create_object_of::Mage_Core_Model_Resource_Website_Collection 0.0068 1 600,488 524,288
SELECT DATE_FORMAT(o.created_at, "%b"), count(*)
FROM sales_flat_order AS o
WHERE created_at BETWEEN
DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 12 MONTH), "%Y-%m-01")
AND
LAST_DAY(DATE_SUB(NOW(), INTERVAL 1 MONTH))
GROUP BY DATE_FORMAT(o.created_at, "%m")
@kalenjordan
kalenjordan / average-sales-excluding-shipping-tax-discounts.sql
Created April 22, 2014 14:55
Average Sales Excluding Shipping, Tax, Discounts
SELECT
date_format(date_sub(created_at, INTERVAL 5 HOUR), "%Y-%m-%d") AS `Day`
, count(*) as `Count`
, AVG(grand_total - tax_amount - shipping_amount) AS `Avg Sales Excluding Tax/Shipping/Discounts`
, AVG(discount_amount) `Avg Discount`
, AVG(tax_amount) `Avg Tax`
, AVG(shipping_amount) `Avg Shipping`
FROM sales_flat_order
WHERE created_at BETWEEN '2014-04-01 05:00:00' AND '2014-04-30 05:00:00'
GROUP BY date_format(date_sub(created_at, INTERVAL 5 HOUR), "%Y-%m-%d")
@kalenjordan
kalenjordan / public-key
Last active August 29, 2015 13:59
Public Key
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2vHCsJ9mmtA2c7gSdmJtpL91tBPhdlKv3liIO/FLKUZugfNNv7p+p/xJ8ZUiEMPMYroaw4vAWu99wsRMiwCkoIExhQj5duNQaE0ZJmM/7fX3uTCICNdEQd7vS8vvoN0XelHRbmZ5Ut7ZXjRnc6v6uYnJEboZhtVLFD/sfbGmZ8Pz8HRi1K4U+YpTDf4CLVyiDd8byL6dJv4KMio/LngSkncaLHZcA959U9baomi/zziYCOFSy8QN9J7APefvodFYIhRD4ynOFeQwr96eJqfJU7a2Rf9kIrdEjbnteY6yE7EdQiifLiidRTdydgB5ZBdxyfmTp0Ay30c8t7zEHkTi7 kalenj@Kalens-Mac-mini.local
@kalenjordan
kalenjordan / tar-magento.sh
Created March 27, 2014 13:03
Tar Magento Files
tar --exclude="media" --exclude="includes" --exclude="var" -cvf var/files.tar .
@kalenjordan
kalenjordan / admin-grid-status.js
Last active August 29, 2015 13:57
Gray out rows in a grid if a status column is inactive
// Drop this javascript in the page where your grid is - maybe using a .phtml
// in before_body_end or whatever.
var statuses = document.querySelectorAll(".admin-autoemail-adminhtml-rule-index td");
[].forEach.call(statuses, function (status) {
if (status.textContent.indexOf("Inactive") > -1) {
status.up('tr').style.color = "#aaa";
status.up('tr').down('a').style.color = "#aaa";
}
});
/* Here are some example custom report queries for use with the custom
* reports module
*
* http://magemail.co/free-custom-reports-module-for-magento/
*/
/*
* Number of items in order
*
* Useful to find out whether customers are buying a given product

Edit Content over the Frontend

Background

Content editing is always a little bit of a hassle. Sometimes your team might not know where a given piece of content exists - whether in CMS Pages, Static Blocks, Product content, or static HTML.

The Idea

Give admins the ability to edit content directly through the frontend via something like a blogger-style interface (you guys remember the blogger days, right?).

The Featuh's

  • Load via AJAX after page load - only shows if the admin is viewing the page.
<div class="block-item cleanse col-md-12 visible-desktop">
<div class="content">
<div class="clearfix">
<div class="program-image visible-phone-tablet">
<h3 class="visible-phone">Start Here</h3>
<img class="img-responsive" src="http://skin.cleanprogram.com/2014-02-24-8-26-UTC/skin/frontend/clean/default/images/clean-cleanse-home.jpg" alt="Clean Cleanse">
</div>
<div class="program-detail col-sm-6 col-md-6 col-lg-12">
<h3 class="hidden-phone">Start Here</h3>
<img class="visible-desktop center-block-element" src="http://skin.cleanprogram.com/2014-02-24-8-26-UTC/skin/frontend/clean/default/images/clean-cleanse-home.jpg" alt="Clean Cleanse">