/** * @param \Magento\Catalog\Model\ResourceModel\Config $config * @param callable $proceed * @return array */ public function aroundGetAttributesUsedForSortBy(\Magento\Catalog\Model\ResourceModel\Config $config, \Closure $proceed) { $cacheId = self::PRODUCT_LISTING_SORT_BY_ATTRIBUTES_CACHE_ID . $config->getEntityTypeId() . '_' . $config->getStoreId(); if ($this->isCacheEnabled && ($attributes = $this->cache->load($cacheId))) { return unserialize($attributes); } $attributes = $proceed(); if ($this->isCacheEnabled) { $this->cache->save(serialize($attributes), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]); } return $attributes; }
public function testGetAttributesUsedForSortByWithCacheSave() { $entityTypeId = 'type'; $storeId = 'store'; $attributes = ['attributes']; $this->subject->expects($this->any())->method('getEntityTypeId')->willReturn($entityTypeId); $this->subject->expects($this->any())->method('getStoreId')->willReturn($storeId); $cacheId = \Magento\Catalog\Plugin\Model\ResourceModel\Config::PRODUCT_LISTING_SORT_BY_ATTRIBUTES_CACHE_ID . $entityTypeId . '_' . $storeId; $this->cache->expects($this->any())->method('load')->with($cacheId)->willReturn(false); $this->cache->expects($this->any())->method('save')->with(serialize($attributes), $cacheId, [\Magento\Eav\Model\Cache\Type::CACHE_TAG, \Magento\Eav\Model\Entity\Attribute::CACHE_TAG]); $this->assertEquals($attributes, $this->getConfig(true)->aroundGetAttributesUsedForSortBy($this->subject, $this->mockPluginProceed($attributes))); }
/** * {@inheritdoc} */ public function getAttributesUsedForSortBy() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getAttributesUsedForSortBy'); if (!$pluginInfo) { return parent::getAttributesUsedForSortBy(); } else { return $this->___callPlugins('getAttributesUsedForSortBy', func_get_args(), $pluginInfo); } }
/** * {@inheritdoc} */ public function getValidationRulesBeforeSave() { $pluginInfo = $this->pluginList->getNext($this->subjectType, 'getValidationRulesBeforeSave'); if (!$pluginInfo) { return parent::getValidationRulesBeforeSave(); } else { return $this->___callPlugins('getValidationRulesBeforeSave', func_get_args(), $pluginInfo); } }