Skip to content

Instantly share code, notes, and snippets.

@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 / 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")
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")
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

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.

Easy Content Management for Magento

Wondering whether anything like this already exists out there already. What I want to do is allow content for static blocks and CMS pages to be defined in specific content blocks that have individual fields with the content in them.

So, when editing a CMS Page, you would have a list of N content blocks which each contain their own set of fields based on the schema definition for that particular content block.

For example, imagine a page that has a hero section at the top with a hero image + title + subtitle, then below it a simple set of paragraphs, then below that a feature image set with a grid of feature images that have image + name + description.

That would look like:

class Clean_Api_Model_Sales_Order_Api extends Clean_Api_Model_Sales_Order_Api_Abstract
{
protected function _getAttributes($object, $type, array $attributes = null)
{
$result = parent::_getAttributes($object, $type, $attributes);
// Add properties to $result
return $result;
}
if ((string)Mage::getConfig()->getModuleConfig('Acme_OrderApi')->active == 'true') {
class Clean_Api_Model_Sales_Order_Api_Abstract extends Acme_OrderApi_Model_Order_Api { }
} else {
class Clean_Api_Model_Sales_Order_Api_Abstract extends Mage_Sales_Model_Order_Api { }
}
SELECT count(*), date_format(date_sub(created_at, INTERVAL 7 HOUR), "%h %p PST")
FROM sales_flat_order
# WHERE created_at > date_sub(now(), INTERVAL 1 year)
GROUP BY date_format(date_sub(created_at, INTERVAL 7 HOUR), "%h %p PST")
ORDER BY date_format(date_sub(created_at, INTERVAL 7 HOUR), "%H") ASC