Skip to content

Instantly share code, notes, and snippets.

View astorm's full-sized avatar

Alana Storm astorm

View GitHub Profile
@astorm
astorm / commerce_bug_error
Created April 21, 2011 15:43 — forked from anonymous/commerce_bug_error
Commerce Bug error
Magento 1.4.1.1
URL: .../catalogsearch/result/?q=test
Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Flat::getEntityType() in /var/www/html/products/app/code/local/[redacted]/Commercebug/Model/Collectorcollections.php on line 36
@astorm
astorm / gist:992233
Created May 25, 2011 23:29
Fix console.log in Chrome and Magento
<!-- Add to the package layout (via local.xml or however you prefer) -->
<!-- Also, best to remove before deployment, as some users report -->
<!-- it makes IE 7 crash -->
<default>
<reference name="content">
<block type="core/text" name="fix.console" as="fix.console">
<action method="setText">
<text><![CDATA[<script type="text/javascript">
iframe = document.createElement('iframe');
iframe.style.display = 'none';
@astorm
astorm / gist:1003007
Created June 1, 2011 18:53
Queries Run during the Loading and Saving of a Magento Product Model
--------------------------------------------------
SELECT `eav_entity_type`.* FROM `eav_entity_type` WHERE (eav_entity_type.entity_type_code='catalog_product')
--------------------------------------------------
--------------------------------------------------
SELECT `catalog_product_entity`.* FROM `catalog_product_entity` WHERE (entity_id=167)
--------------------------------------------------
--------------------------------------------------
SELECT `main_table`.*, `additional_table`.*, `entity_attribute`.*, IFNULL(al.value, main_table.frontend_label) AS `store_label` FROM `eav_attribute` AS `main_table`
<?php
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
/**
* Generating and validating class file name,
* class and if evrything ok do include if needed and return of class name
*
* @return mixed
*/
protected function _validateControllerClassName($realModule, $controller)
@astorm
astorm / gist:1188644
Created September 2, 2011 13:54
Moving a Magento Block Object
<layout>
<catalog_category_default>
<!-- block gets added -->
<reference name="content">
<block type="core/text" name="are_you_sure"></block>
</reference>
</catalog_category_default>
<catalog_category_default>
<!-- later, a different handle gets a reference and sets block state -->
@astorm
astorm / Loader.php
Created December 14, 2011 17:42
Old Magento Loader from an Earlier Alpha
<?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
@astorm
astorm / gist:2492919
Created April 25, 2012 20:02
Generate XML Tree of Magento DB Stored Configuration
<?php
// Why does this work? Start reading
// http://alanstorm.com/category/magento#magento_config
//START: bootstrap magento CLI environment ...
//your bootstrap may be more or less complicated depending on your version/needs
//and it not needed if you're doing this from a controller action or otherwise
//already bootstrapped environment
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
@astorm
astorm / gist:2572772
Created May 2, 2012 01:03
Magento's Tax Calculation Based On setting

Info here is based on a Magento CE 1.6.1 install. Your version may vary. Also, there's lots of conjecture on my part near the end, so DANGER WILL ROBINSON.

Configuration setting is located at

System -> Configuration -> Tax -> Calculation Settings

Label is "Tax Calculation Method Based On"

Possible Settings are

@astorm
astorm / gist:2974947
Created June 22, 2012 20:17
Magento's Performance Profile
There's multiple reasons Magento's performance profile is different
than most "mid-2000s" LAMP stack frameworks and CMS systems.
1. SQL Bottleneck: Magento's functionality is implemented in such a
way that there's a large number of SQL queries on each page request.
Between the special EAV structure of product/category models, and a
general "model first" approach to development, you end up seeing a lot
of SQL queries.
2. "Classical" (Java/C#) style OOP. Magento uses a class heavy
#File: app/code/core/Mage/Core/Model/Resource/Db/Abstract.php
public function forsedSave(Mage_Core_Model_Abstract $object)
{
$this->_beforeSave($object);
$bind = $this->_prepareDataForSave($object);
$adapter = $this->_getWriteAdapter();
// update
if (!is_null($object->getId()) && $this->_isPkAutoIncrement) {
unset($bind[$this->getIdFieldName()]);