1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\SalesRule\Model\ResourceModel;
- use Magento\Framework\EntityManager\MetadataPool;
- use Magento\Framework\EntityManager\Operation\AttributeInterface;
- /**
- * Class SaveHandler
- */
- class SaveHandler implements AttributeInterface
- {
- /**
- * @var Rule
- */
- protected $ruleResource;
- /**
- * @var MetadataPool
- */
- protected $metadataPool;
- /**
- * @param Rule $ruleResource
- * @param MetadataPool $metadataPool
- */
- public function __construct(
- Rule $ruleResource,
- MetadataPool $metadataPool
- ) {
- $this->ruleResource = $ruleResource;
- $this->metadataPool = $metadataPool;
- }
- /**
- * Save handler
- *
- * @param string $entityType
- * @param array $entityData
- * @param array $arguments
- * @return array
- * @throws \Exception
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function execute($entityType, $entityData, $arguments = [])
- {
- $linkField = $this->metadataPool->getMetadata($entityType)->getLinkField();
- if (isset($entityData['website_ids'])) {
- $websiteIds = $entityData['website_ids'];
- if (!is_array($websiteIds)) {
- $websiteIds = explode(',', (string)$websiteIds);
- }
- $this->ruleResource->bindRuleToEntity($entityData[$linkField], $websiteIds, 'website');
- }
- if (isset($entityData['customer_group_ids'])) {
- $customerGroupIds = $entityData['customer_group_ids'];
- if (!is_array($customerGroupIds)) {
- $customerGroupIds = explode(',', (string)$customerGroupIds);
- }
- $this->ruleResource->bindRuleToEntity($entityData[$linkField], $customerGroupIds, 'customer_group');
- }
- return $entityData;
- }
- }
|