Magento - не кэшируйте валюту - PullRequest
2 голосов
/ 01 ноября 2011

Я установил это расширение в моем магазине Magento: http://www.magentocommerce.com/magento-connect/catalogcache.html

Это действительно улучшило время загрузки страницы для каталогов. Проблема в том, что если я изменил валюту магазина, она не будет обновляться на странице, и кэшированная валюта продолжит отображаться. Любые идеи, как я могу сделать так, чтобы изменения валюты вступили в силу?

Вот код из расширения:

class Netresearch_CatalogCache_Block_Product_List extends Mage_Catalog_Block_Product_List
{
    protected function _isCacheActive()
    {
        if(!Mage::getStoreConfig('catalog/frontend/cache_list')) {
            return false;
        }

        /* if there are any messages dont read from cache to show them */
        if(Mage::getSingleton('core/session')->getMessages(true)->count() > 0) {
            return false;
        }
        return true;

    }

    public function getCacheLifetime()
    {
        if($this->_isCacheActive())
        {
            return 2419200;;
        }
    }
/*
    protected function _loadCache()
    {

        $cache = parent::_loadCache();
        Mage::debug($cache === false ? "computed" : "from cache");
        return $cache;
    }
*/
    public function getCacheKey()
    {
        if(!$this->_isCacheActive()) {
            parent::getCacheKey();
        }
        $_taxRateRequest = Mage::getModel('tax/calculation')->getRateRequest();
        $_customer = Mage::getSingleton('customer/session')->getCustomer();
        $this->_category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
        $_page = $this->getPage();

        $toolbar = new Mage_Catalog_Block_Product_List_Toolbar();
        $return = 'ProductView_'.
            /* Create differnet caches for differnt...
             * ... categories */
            $this->_category->getId().'_'.
            /* ... orders */
            $toolbar->getCurrentOrder().'_'.
            /* ... direction */
            $toolbar->getCurrentDirection().'_'.
            /* ... mode */
            $toolbar->getCurrentMode().'_'.
            /* ... page */
            $toolbar->getCurrentPage().'_'.
            /* ... items per page */
            $toolbar->getLimit().'_'.
            /* ... stores */
            Mage::App()->getStore()->getCode().'_'.
            /* ... customer groups */
            $_customer->getGroupId().'_'.
            $_taxRateRequest->getCountryId()."_".$_taxRateRequest->getRegionId()."_".$_taxRateRequest->getPostcode()."_".$_taxRateRequest->getCustomerClassId()."_".
            /* ... tags */
            Mage::registry('current_tag').'_'.
            '';
            /* ... layern navigation + search */
            foreach(Mage::app()->getRequest()->getParams() as $key=>$value) {
                $return .= $key.'-'.$value.'_';
            }
        return $return;
    }


    public function getCacheTags()
    {
        if(!$this->_isCacheActive()) {
            return parent::getCacheTags();
        }
        $cacheTags = array(
            Mage_Catalog_Model_Category::CACHE_TAG,
            Mage_Catalog_Model_Category::CACHE_TAG.'_'.$this->_category->getId()
        );
        foreach($this->_getProductCollection() as $_product) {
            $cacheTags[] = Mage_Catalog_Model_Product::CACHE_TAG."_".$_product->getId();
        }
        return $cacheTags;

    }
}

Кэширование валюты также обсуждается здесь, но я все еще не уверен, что делать: http://www.magentocommerce.com/boards/viewthread/41112/

1 Ответ

2 голосов
/ 01 ноября 2011

Вы можете попробовать добавить уникальный идентификатор для ваших кодов валют:

        /* ... items per page */
        $toolbar->getLimit().'_'.
        /* ... stores */
        Mage::App()->getStore()->getCode().'_'.
        /*** ADD CURRENCY CODE TO ID ***/
        Mage::app()->getStore()->getCurrentCurrencyCode().'_'.
        /* ... customer groups */
        $_customer->getGroupId().'_'.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...