ProductIdentitiesExtender.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\ConfigurableProduct\Model\Plugin\Frontend;
  8. use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
  9. use Magento\Catalog\Model\Product;
  10. /**
  11. * Extender of product identities for child of configurable products
  12. */
  13. class ProductIdentitiesExtender
  14. {
  15. /**
  16. * @var Configurable
  17. */
  18. private $configurableType;
  19. /**
  20. * @param Configurable $configurableType
  21. */
  22. public function __construct(Configurable $configurableType)
  23. {
  24. $this->configurableType = $configurableType;
  25. }
  26. /**
  27. * Add child identities to product identities
  28. *
  29. * @param Product $subject
  30. * @param array $identities
  31. * @return array
  32. */
  33. public function afterGetIdentities(Product $subject, array $identities): array
  34. {
  35. foreach ($this->configurableType->getChildrenIds($subject->getId()) as $childIds) {
  36. foreach ($childIds as $childId) {
  37. $identities[] = Product::CACHE_TAG . '_' . $childId;
  38. }
  39. }
  40. return array_unique($identities);
  41. }
  42. }