Search code examples
magento

Change the path of product images path in magento site


In product view page page, images are serving from this path : link1

media/catalog/product/cache/1/image/350x350/9df78eab33525d08d6e5fb8d27136e95/c/h/image-name.jpg :

but I want to serve from this path : link2

`media/cache/images/1/thumbnail/602f0fa2c1f0d1ba5e241f914e856ff9/catalog/product/c/image-name.jpg` : 

media.phtml

<?php
    $_product = $this->getProduct();
    $_helper = $this->helper('catalog/output');
    $dexxtz = Mage::helper('productzoom');

    $dexxtz->getCss();
    $dexxtz->getJs();
?>

<ul id="etalage">
    <li>                
        <img class="etalage_thumb_image" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'image')); ?>" />
        <img class="etalage_source_image" title="<?php echo $_product->getImageLabel(); ?>" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'image'), true); ?>" />
    </li>
    <?php 
        foreach ($this->getGalleryImages() as $_image) {
            if(Mage::registry('current_product')->getImage() != $_image->getFile()) { ?>                
            <li>
                <img class="etalage_thumb_image" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())); ?>" />
                <img class="etalage_source_image" title="<?php echo $_image->getLabel(); ?>" src="<?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()), true); ?>" />
            </li> 
        <?php 
            }    
        }
    ?>   
</ul>

Solution

  • You need first to copy app/code/core/Mage/Catalog/Model/Product/Image.php to app/code/local/Mage/Catalog/Model/Product/Image.php.

    Then take a look to the file you just copied, l.313-319 :

        // build new filename (most important params)
        $path = array(
            Mage::getSingleton('catalog/product_media_config')->getBaseMediaPath(),
            'cache',
            Mage::app()->getStore()->getId(),
            $path[] = $this->getDestinationSubdir()
        );
    

    This "$path" array will build your catalog image path. Change it to whatever you like. In your case :

        // build new filename (most important params)
        $path = array(
            Mage::getBaseDir('media'),
            'cache/images',
            Mage::app()->getStore()->getId(),
            $path[] = $this->getDestinationSubdir()
        );
    

    Dont forget to modify clear cache path too, l.686 :

    public function clearCache()
    {
        $directory = Mage::getBaseDir('media') . DS.'catalog'.DS.'product'.DS.'cache'.DS;
    

    ... to ...

    public function clearCache()
    {
        $directory = Mage::getBaseDir('media') . DS.'cache'.DS.'images'.DS;
    

    Next, go to your media.phtml file. Change :

    <?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'image')); ?>
    ...
    <?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile())); ?>
    

    ... to ...

    <?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($_product, 'thumbnail')); ?>
    ...
    <?php echo $dexxtz->getImageFeatured($this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile())); ?>