ReadHandler.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesRule\Model\ResourceModel;
  7. use Magento\Framework\EntityManager\MetadataPool;
  8. use Magento\Framework\EntityManager\Operation\AttributeInterface;
  9. /**
  10. * Class ReadHandler
  11. */
  12. class ReadHandler implements AttributeInterface
  13. {
  14. /**
  15. * @var Rule
  16. */
  17. protected $ruleResource;
  18. /**
  19. * @var MetadataPool
  20. */
  21. protected $metadataPool;
  22. /**
  23. * @param Rule $ruleResource
  24. * @param MetadataPool $metadataPool
  25. */
  26. public function __construct(
  27. Rule $ruleResource,
  28. MetadataPool $metadataPool
  29. ) {
  30. $this->ruleResource = $ruleResource;
  31. $this->metadataPool = $metadataPool;
  32. }
  33. /**
  34. * Read handler
  35. *
  36. * @param string $entityType
  37. * @param array $entityData
  38. * @param array $arguments
  39. * @return array
  40. * @throws \Exception
  41. * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  42. */
  43. public function execute($entityType, $entityData, $arguments = [])
  44. {
  45. $linkField = $this->metadataPool->getMetadata($entityType)->getLinkField();
  46. $entityId = $entityData[$linkField];
  47. $entityData['customer_group_ids'] = $this->ruleResource->getCustomerGroupIds($entityId);
  48. $entityData['website_ids'] = $this->ruleResource->getWebsiteIds($entityId);
  49. return $entityData;
  50. }
  51. }