Product.php 894 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Swatches\Model\Plugin;
  7. /**
  8. * Class Product for changing image roles list
  9. */
  10. class Product
  11. {
  12. /**
  13. * Unset swatch image role if product is not simple
  14. *
  15. * @param \Magento\Catalog\Model\Product $product
  16. * @param array|string $imageRoles
  17. * @return array
  18. */
  19. public function afterGetMediaAttributes(\Magento\Catalog\Model\Product $product, $imageRoles)
  20. {
  21. if ($product->getTypeId() !== \Magento\Catalog\Model\Product\Type::TYPE_SIMPLE
  22. && $product->getTypeId() !== \Magento\Catalog\Model\Product\Type::TYPE_VIRTUAL
  23. ) {
  24. if (is_array($imageRoles)) {
  25. unset($imageRoles[\Magento\Swatches\Model\Swatch::SWATCH_IMAGE_NAME]);
  26. }
  27. }
  28. return $imageRoles;
  29. }
  30. }