Magento Massaction mit Observer

Wie kann ohne einen Rewrite des Mage_Adminhtml_Block_Sales_Order_Grid eine Massenaktion hinzufügen?

In der config.xml

<events>
	<core_block_abstract_prepare_layout_before>
		<observers>
			<advancedpicklist_prepare_layout_before>
				<type>singleton</type>
				<class>meinmodul/observer</class>
				<method>addPicklistMassaction</method>
			</advancedpicklist_prepare_layout_before>
		</observers>
	</core_block_abstract_prepare_layout_before>
</events>

In im Observer.php

function addPicklistMassaction(Varien_Event_Observer $observer) {
	$block = $observer->getEvent ()->getBlock ();
	$grid = $block->getLayout ()->getBlock ( 'sales_order.grid' );
	
	if ($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction && $grid != null && $grid instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
		$block->addItem ( 'sendPicklist', array (
				'label' => Mage::helper ( 'advancedpicklist' )->__ ( 'Send Picklists' ),
				'url' => Mage::app ()->getStore ()->getUrl ( 'advancedpicklist/index/massSendPicklist' ) 
		) );
	}
	return $this;
}

Leider hat der Mage_Adminhtml_Block_Widget_Grid_Massaction noch keinen Parent, wenn die vorhandenen Events ausgeführt werden. Daher schauen wir mit Hilfe des Layouts nach ob wir das „sales_order.grid“ erstellen.

Warum es dafür keinen einfacheren Weg gibt, zum Beispiel indem direkt ein Event dafür angeboten wird, vermag ich nicht sagen.

Magento Image URLs in Modules

Ever wondered how image urls are build?

http://somehost/media/catalog/product/cache/0/small_image/225x/9df78eab33525d08d6e5fb8d27136e95/c/o/coalesce.jpg

The highlighted parts are:

  • Base media path (media/catalog/product)
  • ‚cache‘
  • Store ID
  • Type of  image (see attribute)
  • Size of image as WIDTHxHEIGHT. In above case WIDTHx uses the aspect ratio to calculate the second (smaller) side
  • MD5 of image parameters (see Mage_Catalog_Model_Product_Image::setBaseFile for details).
  • First char of filename
  • Second char of filename
  • Filename

The last three parts are the filename of the original image relative to media/catalog/product.

Things to remember:

  • The hash code is generated using image parameters => The same parameters will generate the same hash code.
  • The hash code does not contain any random data
  • The hash code does not contain the filename