Product.php 1.1 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\Bundle\Model\Plugin\Frontend;
  8. use Magento\Bundle\Model\Product\Type;
  9. use Magento\Catalog\Model\Product as CatalogProduct;
  10. /**
  11. * Add child identities to product identities on storefront.
  12. */
  13. class Product
  14. {
  15. /**
  16. * @var Type
  17. */
  18. private $type;
  19. /**
  20. * @param Type $type
  21. */
  22. public function __construct(Type $type)
  23. {
  24. $this->type = $type;
  25. }
  26. /**
  27. * Add child identities to product identities
  28. *
  29. * @param CatalogProduct $product
  30. * @param array $identities
  31. * @return array
  32. */
  33. public function afterGetIdentities(CatalogProduct $product, array $identities): array
  34. {
  35. foreach ($this->type->getChildrenIds($product->getEntityId()) as $childIds) {
  36. foreach ($childIds as $childId) {
  37. $identities[] = CatalogProduct::CACHE_TAG . '_' . $childId;
  38. }
  39. }
  40. return array_unique($identities);
  41. }
  42. }