/** * Product list cache, needs to clear on displayed products * * @param Mage_Catalog_Block_Product_List $block */ public function applyProductList(Mage_Catalog_Block_Product_List $block) { // The "messages" block is session-dependent, don't cache if (Mage::helper('cache')->responseHasMessages()) { $block->setData('cache_lifetime', null); return; } // Set cache tags $tags = array(); $tags[] = Mage_Catalog_Model_Category::CACHE_TAG . '_' . $this->_getCategoryIdForProductList($block); // The toolbar needs to apply sort order etc $_toolbar = $block->getToolbarBlock(); $productCollection = $block->getLoadedProductCollection(); /** * @see Mage_Catalog_Block_Product_List_Toolbar::getCurrentOrder */ if ($orders = $block->getAvailableOrders()) { $_toolbar->setAvailableOrders($orders); } if ($sort = $block->getSortBy()) { $_toolbar->setDefaultOrder($sort); } if ($dir = $block->getDefaultDirection()) { $_toolbar->setDefaultDirection($dir); } if ($modes = $block->getModes()) { $_toolbar->setModes($modes); } $_toolbar->setCollection($productCollection); $productIds = array(); foreach ($productCollection as $_product) { $tags[] = Mage_Catalog_Model_Product::CACHE_TAG . "_" . $_product->getId(); $productIds[] = $_product->getId(); } if (!empty($productIds)) { $childIds = Mage::helper('cache')->getChildProductIds($productIds); foreach ($childIds as $childId) { $tags[] = Mage_Catalog_Model_Product::CACHE_TAG . '_' . $childId; } } $block->setData('cache_tags', $tags); // Set cache key $keys = $this->_getBasicKeys($block); $_taxRateRequest = Mage::getModel('tax/calculation')->getRateRequest(); $_customer = Mage::getSingleton('customer/session')->getCustomer(); $_categoryId = $this->_getCategoryIdForProductList($block); foreach (Mage::app()->getRequest()->getParams() as $key => $value) { $value = Mage::helper('cache')->paramValueToCacheKey($value); $keys[] = $key . '_' . $value; } $keys = array_merge($keys, array($_categoryId, $_toolbar->getCurrentOrder(), $_toolbar->getCurrentDirection(), $_toolbar->getCurrentMode(), $_toolbar->getCurrentPage(), $_toolbar->getLimit(), $_customer->getGroupId(), $_taxRateRequest->getCountryId(), $_taxRateRequest->getRegionId(), $_taxRateRequest->getPostcode(), $_taxRateRequest->getCustomerClassId(), Mage::registry('current_tag'))); $block->setData('cache_key', $this->_getCacheKey($keys, $block)); }
public function testGetPriceBlockTemplate() { $this->assertNull($this->_block->getPriceBlockTemplate()); $this->_block->setData('price_block_template', 'test'); $this->assertEquals('test', $this->_block->getPriceBlockTemplate()); }