0

I am using a third party module which is rewriting catalog/image helper function for product images.

<global>
        <models>
            <pio>
                <class>Kadro_PIO_Model</class>
            </pio>
            <catalog>
                <rewrite>
                    <product_image>Kadro_PIO_Model_Product_Image</product_image>
                </rewrite>
            </catalog>
        </models>

Is it possible to disable this Extension/overwrite for catalog/navigation/subcategory_listing.phtml only so that there is used the standard Magento category/image function?

  • 1
    may I ask why do you need the original helper in one place? Maybe the problem you have can be solved differently. – Marius Sep 10 '14 at 7:52
  • This Extension is resizing and compressing images. I use it for the gallery for our product page. This extension creates small, thumb and base images and the dimensions are defined in the backend. But I have the problem that this images are used in the subcategory_listing as well (using catalog/image function) but size is either to big (base and small) or to small (thumbnail image). ->resize(); is not working there. – Simon K. Sep 10 '14 at 8:01
  • And there is no way in the extension to use the original helper? if the extension is properly built it should give you the possibility to set a certain flag that will make it use the original methods. If there isn't then the extension is badly written. – Marius Sep 10 '14 at 8:04
1

The answer is obviously, Yes, You Can. :)

If you disable this third party extension either via editing code or via admin, then magento will start to use its default helper/Model class. Yes Magento is smart enough to to do that.

In order to disable this extension via admin, you need to go

System  >  Configuration  > Advanced

In order to disable via xml file, you need to find activation file of the extension. Most probably it's name would be Kadro_PIO.xml. So go to app\etc\modules\Kadro_PIO.xml and then change

 <active>false</active>

Edit

From your comment, it seems that, the extension do other jobs for you. So my solution will not help you, since it disable that extension fully.

If you just need to avoid the rewrite part, then the fastest and easiest way will be comment out that rewrite part in the extension's config.xml file.

But this is not the proper way to do this. If you need to do this in clear way, then I will suggest you to create a small custom module that will rewrite the extension's rewrite model file.

For this your module config.xml should holds this part

File : app\code\local\Namespace\Modulename\etc\config.xml

<global>
      <models>
           <pio>
                <rewrite>
                    <product_image>Namespace_Modulename_Model_Product_Image</product_image>
                </rewrite>
            </pio>
     </models>
</globlal>

File : app\code\local\Namespace\Modulename\Model\Product\Image.php

<?php
class Namespace_Modulename_Model_Product_Image extends Kadro_PIO_Model_Product_Image
{
    //here you can overwrite any method that extension uses
}
  • Yes of course but this would disable the extension for everything? I need to disable it just for subcategory_listing only ;) – Simon K. Sep 10 '14 at 7:53
  • ok the extension do other jobs too. Then the fastest way would be comment out that rewrite part in the config.xml file. – Rajeev K Tomy Sep 10 '14 at 7:57
  • Yeah sure but this would disable the extension for everything as well? – Simon K. Sep 10 '14 at 8:09
  • see my edit. you need to overwrite the model class an dchange the method that you wish to change – Rajeev K Tomy Sep 10 '14 at 8:10
0

A work around for your problem is that you could register a flag from catalog/navigation/subcategory_listing sections and then based on if this flag is set just call and return the parent functionality from your helper rather than executing your helper funciton..something like

public function image($product)
{

    if(Mage::registry('no_custom_image')){
           return parent::image($product);
    }
    // Your own customization.
}
0

I ended up using Varien_Image methode.

I used this code in my list.phtml:

<?php 

        if (!$_product->getThumbnail())
        {
            $imageUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'placeholder.jpg';
        }
        else
        {
            $imageUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $_product->getThumbnail();
        }

        if(!file_exists("./media/catalog/category/resized"))
            mkdir("./media/catalog/category/resized",0777);

        $imageName = substr(strrchr($imageUrl, "/"),1);
        $imageResized = Mage::getBaseDir('media').DS."catalog".DS."category".DS."resized".DS.$imageName;
        $dirImg = Mage::getBaseDir().str_replace("/",DS,strstr($imageUrl,'/media'));

        if (!file_exists($imageResized)&&file_exists($dirImg)) :
         $imageObj = new Varien_Image($dirImg);
         $imageObj->backgroundColor(array(255,255,255));
         $imageObj->constrainOnly(TRUE);
         $imageObj->keepAspectRatio(TRUE);
         $imageObj->keepFrame(FALSE);
         $imageObj->resize(235, 225);
         $imageObj->save($imageResized);
        endif;

        $newImageUrl = $imageName;

?>

And I get the image with:

 <?php echo Mage::getBaseUrl('media')."catalog/category/resized/".$newImageUrl ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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