Vinai / nicer-image-names

Magento extension to build catalog image file names from product attributes so they have neat descriptive names.
77 stars 31 forks source link

Cached image is not updated if the base file is replaced directly (without product save) #23

Open alexkuk opened 9 years ago

alexkuk commented 9 years ago

I faced with this problem and I have a solution for it. Could you please review it and consider including it into the module?

The solution is to add an to override Mage_Catalog_Model_Product_Image::isCached() method in Netzarbeiter_NicerImageNames_Model_Image:

    public function isCached()
    {
        if (Mage::getStoreConfig("catalog/nicerimagenames/disable_ext")) {
            return parent::isCached();
        }

        if (!$this->_fileExists($this->_newFile)) {
            return false;
        }

        if (!file_exists($this->_baseFile)) {
            return true;
        }

        if (filemtime($this->_newFile) < filemtime($this->_baseFile)) {
            Mage::dispatchEvent('nicerimagenames_regenerate_image', array(
                'url' => $this->getUrl()
            ));
            return false;
        }

        return true;
    }

It checks the base file change time, and if cached file is older - we regenerate a cached file

Vinai commented 9 years ago

Hey, thanks for the idea. I'm very open to include the code in the extension. Can you please open a pull request? Would you be willing to includ the event observer, too? One note: what do you think, maybe it would be better to name the event in a way that states the condition which just occured - maybe nicerimagenames_new_file_available or the like - since event names generally should not be in "command" form, but rather state things that happened.

Vinai commented 8 years ago

Should be fixed by https://github.com/Vinai/nicer-image-names/pull/34 Please validate