CacheInvalidate.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Swatches\Plugin\Catalog;
  7. use \Magento\Framework\App\Cache\Type\Block;
  8. use \Magento\Framework\App\Cache\Type\Collection;
  9. class CacheInvalidate
  10. {
  11. /**
  12. * @var \Magento\Framework\App\Cache\TypeListInterface
  13. */
  14. private $typeList;
  15. /**
  16. * @var \Magento\Swatches\Helper\Data
  17. */
  18. private $swatchHelper;
  19. /**
  20. * @param \Magento\Framework\App\Cache\TypeListInterface $typeList
  21. * @param \Magento\Swatches\Helper\Data $swatchHelper
  22. */
  23. public function __construct(
  24. \Magento\Framework\App\Cache\TypeListInterface $typeList,
  25. \Magento\Swatches\Helper\Data $swatchHelper
  26. ) {
  27. $this->typeList = $typeList;
  28. $this->swatchHelper = $swatchHelper;
  29. }
  30. /**
  31. * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject
  32. * @param \Magento\Catalog\Model\ResourceModel\Eav\Attribute $result
  33. * @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
  34. */
  35. public function afterSave(
  36. \Magento\Catalog\Model\ResourceModel\Eav\Attribute $subject,
  37. \Magento\Catalog\Model\ResourceModel\Eav\Attribute $result
  38. ) {
  39. if ($this->swatchHelper->isSwatchAttribute($subject)) {
  40. $this->typeList->invalidate(Block::TYPE_IDENTIFIER);
  41. $this->typeList->invalidate(Collection::TYPE_IDENTIFIER);
  42. }
  43. return $result;
  44. }
  45. }