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 25, 2009

Sort by price not working in Magento

Filed under: Magento — Tags: , , , , , , — Allan Brown @ 9:12 pm

I recently added a large volume of products to Magento, however when I then began looking through the product listing, it was acting in a really strange way.

All products were displaying correctly however the order was all wrong.  Instead of being ordered or sorted by price by default as they should of been, the order was all over the place.

After a bit of searching I eventually found the problem is in the Magento cache system and specifically in the Layered Navigation indexes.

Logging in as admin and using the “System->Cache Management->Layered Navigation Indices->Refresh now” option resolved the issue.  However this process took a long time to complete on my server, so some patience may be required.

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.

October 15, 2009

include_path setting can cause problems in Magento

Filed under: Magento — Tags: , , , , , — Allan Brown @ 1:24 am

I had a small problem today with the Magento connect application. All other Magento functions were working, but when I tried to access Connect (http://sitedomain.com/index.php/admin/extensions_local/), a load of errors were being displayed saying:

Warning: include_once(Maged/Model.php) [function.include-once]: failed to open stream: No such file or directory in /var/www/web1/html/downloader/Maged/Controller.php on line 21

Warning: include_once() [function.include]: Failed opening ‘Maged/Model.php’ for inclusion (include_path=’/usr/share/pear:/usr/share/php’) in /var/www/web1/html/downloader/Maged/Controller.php on line 21

Warning: include_once(Maged/View.php) [function.include-once]: failed to open stream: No such file or directory in /var/www/web1/html/downloader/Maged/Controller.php on line 22

Warning: include_once() [function.include]: Failed opening ‘Maged/View.php’ for inclusion (include_path=’/usr/share/pear:/usr/share/php’) in /var/www/web1/html/downloader/Maged/Controller.php on line 22

Warning: include_once(Maged/Exception.php) [function.include-once]: failed to open stream: No such file or directory in /var/www/web1/html/downloader/Maged/Controller.php on line 23

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web1/html/downloader/Maged/Controller.php:21) in /var/www/web1/html/downloader/Maged/Controller.php on line 311

After much searching, I discovered that it was due to an incorrectly set ‘include_path’ in the apache php.ini file. We are using some advanced caching on the server to speed things up, and the setting it was changed to was slightly out.

So, we changed it from

/opt/coolstack/php5/lib/php/

to

.:/opt/coolstack/php5/lib/php/

However in most cases, it would be:

on Linux: include_path = “.:/php/includes”
on Windows: include_path = “.;c:\php\includes”

A quick Apache restart and all is well again. Easy fix!

October 13, 2009

Magento and me

Filed under: Magento — Tags: , , — Allan Brown @ 5:55 pm

In Summer 2009 I started on a large project at work which was to be a music download site based on an existing e-commerce system.  After much deliberation it was decided that we would use Magento.

For the past 2 months now I have been trawling through the innerworkings of this e-commerce platform learning it as I go and this blog will cover the experiences I am having.  Topics covered will include development advice, strange bugs and hopefully some invaluble hints for those using Magento as a base for their website.

The project I am undertaking will cover core Magento code changes, custom module development, 3rd party API integration, multiple payment-gateway integration, development of custom themes and templates, integrating to Amazon S3 and EC2 and any other areas as small as adding a youtube video to as large as creating a whole new product type.

If I am able and if there is demand, the work I am doing will be provided as public (or possibly commercial) addons.  If not however, hopefully I will be able to save some of you some time in your own projects.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Powered by WordPress