Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SaveHandler.php
Go to the documentation of this file.
1 <?php
7 
11 
16 {
20  protected $ruleResource;
21 
25  protected $metadataPool;
26 
31  public function __construct(
34  ) {
35  $this->ruleResource = $ruleResource;
36  $this->metadataPool = $metadataPool;
37  }
38 
46  public function execute($entityType, $entityData, $arguments = [])
47  {
48  $linkField = $this->metadataPool->getMetadata($entityType)->getLinkField();
49  if (isset($entityData['website_ids'])) {
50  $websiteIds = $entityData['website_ids'];
51  if (!is_array($websiteIds)) {
52  $websiteIds = explode(',', (string)$websiteIds);
53  }
54  $this->ruleResource->bindRuleToEntity($entityData[$linkField], $websiteIds, 'website');
55  }
56 
57  if (isset($entityData['customer_group_ids'])) {
58  $customerGroupIds = $entityData['customer_group_ids'];
59  if (!is_array($customerGroupIds)) {
60  $customerGroupIds = explode(',', (string)$customerGroupIds);
61  }
62  $this->ruleResource->bindRuleToEntity($entityData[$linkField], $customerGroupIds, 'customer_group');
63  }
64  return $entityData;
65  }
66 }
execute($entityType, $entityData, $arguments=[])
Definition: SaveHandler.php:46
__construct(Rule $ruleResource, MetadataPool $metadataPool)
Definition: SaveHandler.php:31
$arguments