ReadHandler.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\Model\Product;
  7. use Magento\Bundle\Api\ProductOptionRepositoryInterface as OptionRepository;
  8. use Magento\Framework\EntityManager\Operation\ExtensionInterface;
  9. /**
  10. * Class ReadHandler
  11. */
  12. class ReadHandler implements ExtensionInterface
  13. {
  14. /**
  15. * @var OptionRepository
  16. */
  17. private $optionRepository;
  18. /**
  19. * ReadHandler constructor.
  20. *
  21. * @param OptionRepository $optionRepository
  22. */
  23. public function __construct(OptionRepository $optionRepository)
  24. {
  25. $this->optionRepository = $optionRepository;
  26. }
  27. /**
  28. * @param object $entity
  29. * @param array $arguments
  30. * @return \Magento\Catalog\Api\Data\ProductInterface
  31. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  32. */
  33. public function execute($entity, $arguments = [])
  34. {
  35. /** @var $entity \Magento\Catalog\Api\Data\ProductInterface */
  36. if ($entity->getTypeId() != \Magento\Bundle\Model\Product\Type::TYPE_CODE) {
  37. return $entity;
  38. }
  39. $entityExtension = $entity->getExtensionAttributes();
  40. $options = $this->optionRepository->getListByProduct($entity);
  41. if ($options) {
  42. $entityExtension->setBundleProductOptions($options);
  43. }
  44. $entity->setExtensionAttributes($entityExtension);
  45. return $entity;
  46. }
  47. }