ReadHandler.php 1.4 KB

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