Magento IMP 4

Add comment to form input in admin

$afterElementHtml = '<p class="nm"><small>' . ' this is the hint! ' . '</small></p>'; $linkFieldset->addField('field_name', 'text', array( 'after_element_html' => $afterElementHtml, ));

Pretty Backtrace

Inapp/code/core/Mage/Core/functions.phpMagento offers a function namedmageDebugBacktrace()which is nice, but I thought could be made nicer. This backtrace shows frame numbers, file names and line numbers, classes, methods and arguments where possible. It can be placed anywhere you fancy, as long as it is included by Magento - I normally add it to functions.php when needed, and remove when I’m done.
Example output:
[ 0] app/code/core/Enterprise/Search/Model/Adapter/Abstract.php:414 Enterprise_Search_Model_Adapter_HttpStream->_search('art', Array) [ 1] app/code/core/Enterprise/Search/Model/Resource/Engine.php:113 Enterprise_Search_Model_Adapter_Abstract->getIdsByQuery('art', Array) [ 2] app/code/core/Enterprise/Search/Model/Resource/Collection.php:352 Enterprise_Search_Model_Resource_Engine->getIdsByQuery('art', Array) [ 3] app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php:825 Enterprise_Search_Model_Resource_Collection->_beforeLoad() [ 4] app/code/core/Mage/Review/Model/Observer.php:78 Mage_Eav_Model_Entity_Collection_Abstract->load() [ 5] app/code/core/Mage/Core/Model/App.php:1299 Mage_Review_Model_Observer->catalogBlockProductCollectionBeforeToHtml(Varien_Event_Observer) [ 6] app/code/core/Mage/Core/Model/App.php:1274 Mage_Core_Model_App->_callObserverMethod(Mage_Review_Model_Observer, 'catalogBlockProductCollectionBeforeToHtml', Varien_Event_Observer) [ 7] app/Mage.php:416 Mage_Core_Model_App->dispatchEvent('catalog_block_product_list_collection', Array) [ 8] app/code/core/Mage/Catalog/Block/Product/List.php:163 Mage::dispatchEvent('catalog_block_product_list_collection', Array) [ 9] app/code/core/Mage/Core/Block/Abstract.php:802 Mage_Catalog_Block_Product_List->_beforeToHtml() [10] app/code/core/Mage/Core/Block/Abstract.php:570 Mage_Core_Block_Abstract->toHtml() [11] app/code/core/Mage/Core/Block/Abstract.php:514 Mage_Core_Block_Abstract->_getChildHtml('search_result_list', '1') (and so on...)
Code:
function niceDebugBacktrace() { $d = debug_backtrace(); array_shift($d); $out = ''; $c1width = strlen(count($d) + 1); $c2width = 0; foreach ($d as &$f) { if (!isset($f['file'])) $f['file'] = ''; if (!isset($f['line'])) $f['line'] = ''; if (!isset($f['class'])) $f['class'] = ''; if (!isset($f['type'])) $f['type'] = ''; $f['file_rel'] = str_replace(BP . DS, '', $f['file']); $thisLen = strlen($f['file_rel'] . ':' . $f['line']); if ($c2width < $thisLen) $c2width = $thisLen; } foreach ($d as $i => $f) { $args = ''; if (isset($f['args'])) { $args = array(); foreach ($f['args'] as $arg) { if (is_object($arg)) { $str = get_class($arg); } elseif (is_array($arg)) { $str = 'Array'; } elseif (is_numeric($arg)) { $str = $arg; } else { $str = "'$arg'"; } $args[] = $str; } $args = implode(', ', $args); } $out .= sprintf( "[%{$c1width}s] %-{$c2width}s %s%s%s(%s)\n", $i, $f['file_rel'] . ':' . $f['line'], $f['class'], $f['type'], $f['function'], $args ); } return $out; }
Usage:
echo niceDebugBacktrace();

Config Model Rewrite Definition

<config> <global> <models> <catalog> <rewrite> <product>Namespace_Module_Catalog_Product</product> </rewrite> </catalog> </models> </global> </config>

Config URL Rewrite Definition

<config> <global> <rewrite> <namespace_module> <from><![CDATA[#^/some/regex/([a-z]*/?$#]]></from> <to><![CDATA[/frontname/whatever/whatever/blah/$1]]></to> </namespace_module> </rewrite> </global> </config>

Adding A Layout Handle From A Controller

Doing this is a slight pain, to quote what Alan Storm said on StackOverflow:
  1. If you add your handle before you call $this->loadLayout() from a controller it’s too soon
  2. If you add your handle after you call $this->loadLayout() it’s too late
So, if you really need to add a handle to a controller, you need to replace the call to$this->loadLayout() with:
$update = $this->getLayout()->getUpdate(); $update->addHandle('default'); $this->addActionLayoutHandles(); $update->addHandle('your_handle'); $this->loadLayoutUpdates(); $this->generateLayoutXml(); $this->generateLayoutBlocks(); $this->_isLayoutLoaded = true;

Config Menu Definition

This should go in adminhtml.xml. Also seeConfig ACL Definition (note that the XML path of the ACL entry needs to match up with the XML path of the menu entry).
To place an entry under the sales node (alter the name for other nodes):
<adminhtml> <menu> <sales> <children> <namespace_module translate="title" module="namespace_module"> <title>Your Module</title> <sort_order>100</sort_order> <action>adminhtml/namespace_module</action> <!-- Children are optional, you should remove the above <action> if you have them --> <children> <this translate="title" module="namespace_module"> <title>This</title> <sort_order>10</sort_order> <action>adminhtml/namespace_module_this</action> </this> <that translate="title" module="namespace_module"> <title>That</title> <sort_order>20</sort_order> <action>adminhtml/namespace_module_that</action> </that> </children> </namespace_module> </children> </sales> </menu> </adminhtml>
To place an entry on the top bar itself:
<adminhtml> <menu> <namespace_module translate="title" module="namespace_module"> <title>Your Module</title> <sort_order>100</sort_order> <action>adminhtml/namespace_module</action> <!-- Children are optional, you should remove the above <action> if you have them --> <children> <this translate="title" module="namespace_module"> <title>This</title> <sort_order>10</sort_order> <action>adminhtml/namespace_module_this</action> </this> <that translate="title" module="namespace_module"> <title>That</title> <sort_order>20</sort_order> <action>adminhtml/namespace_module_that</action> </that> </children> </namespace_module> </menu> </adminhtml>

Config ACL Definition

This should go inadminhtml.xml. Also seeConfig Menu Definition (note that the XML path of the menu entry needs to match up with the XML path of the ACL entry). To see how to implement the checking of an ACL within an admin controller see the_isAllowed() method inBoilerplate Admin Controller.
To place an entry under the sales node (alter the name for other nodes):
<adminhtml> <acl> <resources> <admin> <children> <sales> <children> <namespace_module translate="title" module="namespace_module"> <title>Your Module</title> <sort_order>100</sort_order> <!-- Children are optional --> <children> <this translate="title" module="namespace_module"> <title>This</title> <sort_order>10</sort_order> </this> <that translate="title" module="namespace_module"> <title>That</title> <sort_order>20</sort_order> </that> </children> </namespace_module> </children> </sales> </children> </admin> </resources> </acl> </adminhtml>
To place an entry on the top bar itself:
<adminhtml> <acl> <resources> <admin> <children> <namespace_module translate="title" module="namespace_module"> <title>Your Module</title> <sort_order>100</sort_order> <!-- Children are optional --> <children> <this translate="title" module="namespace_module"> <title>This</title> <sort_order>10</sort_order> </this> <that translate="title" module="namespace_module"> <title>That</title> <sort_order>20</sort_order> </that> </children> </namespace_module> </children> </admin> </resources> </acl> </adminhtml>

Remove Customers From MySQL

Is this ok?
TRUNCATE TABLE `customer_address_entity`; TRUNCATE TABLE `customer_address_entity_datetime`; TRUNCATE TABLE `customer_address_entity_decimal`; TRUNCATE TABLE `customer_address_entity_int`; TRUNCATE TABLE `customer_address_entity_text`; TRUNCATE TABLE `customer_address_entity_varchar`; TRUNCATE TABLE `customer_entity`; TRUNCATE TABLE `customer_entity_datetime`; TRUNCATE TABLE `customer_entity_decimal`; TRUNCATE TABLE `customer_entity_int`; TRUNCATE TABLE `customer_entity_text`; TRUNCATE TABLE `customer_entity_varchar`;

Remove Orders From MySQL

What version did flat come in? Are all these tables safe to truncate? Make different scripts for different versions.
TRUNCATE `sales_flat_creditmemo`; TRUNCATE `sales_flat_creditmemo_comment`; TRUNCATE `sales_flat_creditmemo_grid`; TRUNCATE `sales_flat_creditmemo_item`; TRUNCATE `sales_flat_invoice`; TRUNCATE `sales_flat_invoice_comment`; TRUNCATE `sales_flat_invoice_grid`; TRUNCATE `sales_flat_invoice_item`; TRUNCATE `sales_flat_order`; TRUNCATE `sales_flat_order_address`; TRUNCATE `sales_flat_order_grid`; TRUNCATE `sales_flat_order_item`; TRUNCATE `sales_flat_order_payment`; TRUNCATE `sales_flat_order_status_history`; TRUNCATE `sales_flat_quote`; TRUNCATE `sales_flat_quote_address`; TRUNCATE `sales_flat_quote_address_item`; TRUNCATE `sales_flat_quote_item`; TRUNCATE `sales_flat_quote_item_option`; TRUNCATE `sales_flat_quote_payment`; TRUNCATE `sales_flat_quote_shipping_rate`; TRUNCATE `sales_flat_shipment`; TRUNCATE `sales_flat_shipment_comment`; TRUNCATE `sales_flat_shipment_grid`; TRUNCATE `sales_flat_shipment_item`; TRUNCATE `sales_flat_shipment_track`;

No comments:

Post a Comment