开发者

Magento: Difference between loading product through collection than product model

So we were trying to load a product through a collection with certain criteria, we didn't have the sku or the id so when we did the following

 $prodModel->getCollection()
        ->addAttributeToFilter('visibility', $visibility)
        ->addAttributeToSelect('*')
        ->addCategoryFilter($cat)
        ->addAttributeToFilter('attribute_1', $sattribute_1)
        ->addAttributeToFilter('attribute_2', $attribute_2)
        ->addAttributeToFilter('type_id', 'configurable')
        ->load()
        ->getFirstItem()

When doing this we got the product we wanted but for some reason it didn't have all of the attributes, even though we specified "*" for all attributes. Specifically the one we were not getting was the media gallery attribute. What we ended up doing is saying g开发者_JAVA技巧etFirstItem()->getId() then loaded the product and it worked find.

I just don't understand whey loading the product with the catalog product model would have more attributes.


I understand you actually asked how to get all of the attributes but I notice you also mention the media gallery attribute specifically. There happens to be a shortcut for getting the product image's final URL.

(string)Mage::helper('catalog/image')->init($product, 'media_gallery');

Casting to a string calls __toString which performs the cleverness. You can also apply resizing, rotation, watermarks, etc. immediately after initialising.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜