Skip to content

Commit

Permalink
Merge pull request #5 from atishgoswami/cache-xtags-name-bugfix
Browse files Browse the repository at this point in the history
Uses CACHE_TAG constants instead of hardcoded cache tag values
  • Loading branch information
phoenix128 authored Sep 26, 2018
2 parents 58d225d + a77c562 commit c4e115b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
7 changes: 4 additions & 3 deletions Observer/CatalogCategoryCollectionLoadAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use MSP\APIEnhancer\Api\TagInterface;
use Magento\Catalog\Model\Category;

class CatalogCategoryCollectionLoadAfter implements ObserverInterface
{
Expand All @@ -44,11 +45,11 @@ public function __construct(
public function execute(\Magento\Framework\Event\Observer $observer)
{
$collection = $observer->getCategoryCollection();
$tags = ['catalog_category'];
$ids = array_keys($collection->getItems());
$tags = [Category::CACHE_TAG];
$ids = array_keys($collection->getItems());

foreach ($ids as $id) {
$tags[] = 'catalog_category_' . $id;
$tags[] = Category::CACHE_TAG . '_' . $id;
}

$this->tag->addTags($tags);
Expand Down
5 changes: 3 additions & 2 deletions Observer/CatalogCategoryLoadAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
use MSP\APIEnhancer\Api\TagInterface;
use Magento\Catalog\Model\Category;

class CatalogCategoryLoadAfter implements ObserverInterface
{
Expand All @@ -43,7 +44,7 @@ public function __construct(
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
$productId = $observer->getCategory()->getId();
$this->tag->addTags(['catalog_category', 'catalog_category_' . $productId]);
$categoryId = $observer->getCategory()->getId();
$this->tag->addTags([Category::CACHE_TAG, Category::CACHE_TAG . '_' . $categoryId]);
}
}
5 changes: 3 additions & 2 deletions Observer/CatalogProductCollectionLoadAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Magento\Store\Model\StoreManagerInterface;
use MSP\APIEnhancer\Api\CustomerAuthInterface;
use MSP\APIEnhancer\Api\TagInterface;
use Magento\Catalog\Model\Product;

class CatalogProductCollectionLoadAfter implements ObserverInterface
{
Expand Down Expand Up @@ -90,7 +91,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)

$fixCatalogRules = !!$this->scopeConfig->getValue(static::XML_PATH_FIX_CATALOG_RULES);

$tags = ['catalog_product'];
$tags = [Product::CACHE_TAG];
$productIds = array_keys($collection->getItems());

if ($fixCatalogRules) {
Expand All @@ -115,7 +116,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
if ($fixCatalogRules && isset($rulePrices[$product->getId()])) {
$product->setCustomAttribute('special_price', $rulePrices[$product->getId()]);
}
$tags[] = 'catalog_product_' . $product->getId();
$tags[] = Product::CACHE_TAG . '_' . $product->getId();
}

$this->tag->addTags($tags);
Expand Down
3 changes: 2 additions & 1 deletion Observer/CatalogProductLoadAfter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Magento\Store\Model\StoreManagerInterface;
use MSP\APIEnhancer\Api\CustomerAuthInterface;
use MSP\APIEnhancer\Api\TagInterface;
use Magento\Catalog\Model\Product;

class CatalogProductLoadAfter implements ObserverInterface
{
Expand Down Expand Up @@ -112,6 +113,6 @@ public function execute(\Magento\Framework\Event\Observer $observer)
}
}

$this->tag->addTags(['catalog_product', 'catalog_product_' . $productId]);
$this->tag->addTags([Product::CACHE_TAG, Product::CACHE_TAG .'_' . $productId]);
}
}

0 comments on commit c4e115b

Please sign in to comment.