Allan Brown

January 19, 2010

Define or pre-select products or items in a massaction Magento grid

Recently while building an administration interface for Magento (in adminhtml) I was needing to select products which should be added to a newsletter template (custom module).  The problem is that there is no obvious way to pre-select items or products when using a massaction grid in Magento.  The logic im trying to manipulate is contained in Mage_Adminhtml_Block_Widget_Grid.

The solution is to change (or pre-populate) the getRequest parameters (_POST values) so that the grid thinks that products have been selected on a previous page.  This can be done using the example code below, which should work for Magento massaction grids for products.

$this->getRequest()->setParam('internal_products',implode(',',$productIdArray));

$productIdArray contains a simple array of ids matching products.  Such as array(12,13,14,15)

November 1, 2009

Adding images to magento using code (Programmaticaly)

Filed under: Magento — Tags: , , , — Allan Brown @ 3:00 pm

Ive been working on automatically adding products to Magento from a 3rd party XML feed.  Its fairly easy to do, however I couldint find much information on how to attach images to a product, and then how to set a product image as thumbnail, small image and base image.

The code to add an image to a product in Magento is:

$product->addImageToMediaGallery($imagePath, array('image','small_image','thumbnail'), false, true, $productData['data_display_name'] . " " . $productData['data_artist_display_name'] . " " . $productData['data_catalog_number']);

It is the array(‘image’,’small_image’,'thumbnail’) which tells Magento that you are wanting to use this image as the small image, thumbnail and base image.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Powered by WordPress