1

I'm working with the AW Mobile2 extension which works fine more or less. I notice the product image doesn't show up on the product view page. Unfortunately I do not see any related issue in the log files like "exception 'Mage_Core_Exception' with message 'Invalid block type'".

Debugging turned out out that Magento doesn't show the image because of the block type:

app/design/frontend/aw_mobile2/iphone/layout/catalog.xml

[Does not work]
<block type="aw_mobile2/catalog_product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>

[Works]
<block type="catalog/product_view_media" name="product.info.media" as="media" template="catalog/product/view/media.phtml"/>

app/code/local/AW/Mobile2/etc/config.xml

    <global>
        <blocks>
            <aw_mobile2>
                <class>AW_Mobile2_Block</class>
            </aw_mobile2>
        </blocks>
        ...

app/code/local/AW/Mobile2/Block/Catalog/Product/View/Media.php

class AW_Mobile2_Block_Catalog_Product_View_Media extends Mage_Catalog_Block_Product_View_Media
{
    /**
     * @return array|Varien_Data_Collection
     */
    public function getGalleryImages()
    {
        if ($this->_isGalleryDisabled) {
            return array();
        }
        return $this->_getMediaGalleryImages($this->getProduct());
    }

    /**
     * @param Mage_Catalog_Model_Product $product
     * @return Varien_Data_Collection
     */
    protected function _getMediaGalleryImages($product)
    {
        if (!$product->hasData('media_gallery_images') && is_array($product->getMediaGallery('images'))) {
            $images = new Varien_Data_Collection();
            foreach ($product->getMediaGallery('images') as $image) {
                if ($image['disabled'] && !$this->_isBaseImage($image, $product)) {
                    continue;
                }
                $image['url'] = $product->getMediaConfig()->getMediaUrl($image['file']);
                $image['id'] = isset($image['value_id']) ? $image['value_id'] : null;
                $image['path'] = $product->getMediaConfig()->getMediaPath($image['file']);
                $images->addItem(new Varien_Object($image));
            }
            $product->setData('media_gallery_images', $images);
        }

        return $product->getData('media_gallery_images');
    }

    /**
     * @param array $image
     * @param Mage_Catalog_Model_Product $product
     * @return bool
     */
    protected function _isBaseImage($image, $product)
    {
        return (strcasecmp($product->getImage(), $image['file']) == 0);
    }
}

The file permissions are also correct. Sure I could go with the working solution but I'm really wondering why the aw_mobile2 block type doesn't work. This part wasn't modified and should work though.

I stuck and appreciate any hint. Thanks!

4
  • 1
    Just to make sure, did you clear the cache?
    – Marius
    Commented Mar 10, 2016 at 14:41
  • Thanks for your comment. Yes, caches are all disabled in backend and I deleted var/cache a couple times. No luck.
    – Stefan
    Commented Mar 10, 2016 at 14:46
  • Compilation is disabled? Commented Mar 10, 2016 at 17:47
  • Compilation is disabled.
    – Stefan
    Commented Mar 11, 2016 at 8:50

2 Answers 2

1

The only difference between this block and the original block is that it excludes all but the base image:

if ($image['disabled'] && !$this->_isBaseImage($image, $product)) {
    continue;
}

So it looks like either you don't have a base image set for your products, or it does not recognize them. To debug further, you can add some logging to the _isBaseImage() method, like this:

protected function _isBaseImage($image, $product)
{
    Mage::log(__METHOD__ . ': ' . $product->getImage() . ' - ' . $image['file']);
    return (strcasecmp($product->getImage(), $image['file']) == 0);
}

and then see in var/system.log what it actually compares. I guess, the comparision used there is not reliable.

2
  • Thanks for looking into this. I added Mage::log to each function in Media.php right after {. But nothing gets logged. So it looks like it does not get used at all.
    – Stefan
    Commented Mar 11, 2016 at 8:51
  • Then either the class file cannot be read or the module is not active or you have a typo somewhere in the XML files. Commented Mar 11, 2016 at 8:56
0

In my case "someone" disabled the Module's Output in System > Config > Advanced. Set it to "Enable" fixed the issue. Thanks everyone.

Your Answer

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

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