0

In, what feels like a never ending quest to teach myself Magento and use it at a practical level I have finally decided that I should dive into the code and learn how individual components are rendered/found (and in doing so cause myself a real headache!).

I have decided to review how a product image is rendered on the catalog list page, or more specifically, how the link is generated to display the required image.

Ive started at template/catalog/products/list.phtml and on line 35 I see a product collection is returned and then on line 52 the required url is echo(ed) using $_product->getProductUrl().

I have gone into a number of the functions to try and understand what is happening in each, some I understand and others I don't. Using var_dump($_productCollection) I tried to find the link in there. Unsurprisingly there was a lot of information (i'm sure it's all very useful, but was lost on me) but no links! Is the array in '_selectAttributes' the answer to finding how the link is generated?

I also noticed '_entityTable' which has the value 'catalog_product_entity' looking in that table has not helped find a connection to catalog_product_entity_media_gallery, which is where I stumbled upon the paths being stored.

My question:

  • From the information that is provided in the collection how would I track down how the link is being generated?

  • media/catalog/product/ holds my catalog images, but the folder names are 1-3 and a-z, hence no help in finding required images, is this a database optimisation thing?

1 Answer 1

0

var_dumping a collection will result in a lot messy code since it's a class so you're better of looking at each individual item when doing for example an foreach.

foreach ($_productCollection as $item)
{
   var_dump($item->getData());exit;
}

A collection always returns a model for each item. When calling Mage::getModel('catalog/product')->getCollection() each item in that collection will be of an instance op Mage_Catalog_Model_Product. These models extend the Mage_Core_Model_Abstract class which provides you with the getData() method to see all the data as a manageable array.

No to the images. To come up with a nice, resized etc image Magento uses, for product images at least, the Mage_Catalog_Helper_Image class that asks for the product and the name of the attribute that holds the image. For example thumbnail, small_image or image.

The class will perform the requested modifications to the image (like resize), cache it and then output a string that is the image path and name. The path/name is based on the original name and the modifications done to the image so that the class can check if a cached version already exists of that image.

The directory structure of the uncached images is, correct me if I'm wrong, to prevent having one big directory with all images and actually logically splitting them up making it more manageable.

A direct reference between the cache link and the data in the collection is hard to find and in most cases not of any value since caches can be truncated creating new links. But it's basically the original file name and then the resize parameters as the parent directory for example.

I hope my explanation wasn't too long and actually makes some sence

1
  • Thanks for a good explanation. I thought digging through the code would be a bit easier than this
    – tony09uk
    Dec 12, 2013 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.