Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConditionBuilder.php
Go to the documentation of this file.
1 <?php
8 
14 use Magento\Catalog\Model\ResourceModel\Eav\Attribute as CatalogEavAttribute;
17 
25 {
29  private $storeManager;
30 
35  public function __construct(StoreManagerInterface $storeManager)
36  {
37  $this->storeManager = $storeManager;
38  }
39 
51  EntityMetadataInterface $metadata,
52  array $scopes,
53  $linkFieldValue
54  ) {
55  $website = $this->getWebsiteForWebsiteScope($scopes);
56  if (!$website) {
57  return [];
58  }
59  $storeIds = $website->getStoreIds();
60 
61  $condition = [
62  $metadata->getLinkField() . ' = ?' => $linkFieldValue,
63  'attribute_id = ?' => $attribute->getAttributeId(),
64  ];
65 
66  $conditions = [];
67  foreach ($storeIds as $storeId) {
68  $identifier = $metadata->getEntityConnection()->quoteIdentifier(Store::STORE_ID);
69  $condition[$identifier . ' = ?'] = $storeId;
70  $conditions[] = $condition;
71  }
72 
73  return $conditions;
74  }
75 
87  EntityMetadataInterface $metadata,
88  array $scopes,
89  $linkFieldValue
90  ) {
91  $website = $this->getWebsiteForWebsiteScope($scopes);
92  if (!$website) {
93  return [];
94  }
95  $storeIds = $website->getStoreIds();
96 
97  $condition = [
98  $metadata->getLinkField() => $linkFieldValue,
99  'attribute_id' => $attribute->getAttributeId(),
100  ];
101 
102  $conditions = [];
103  foreach ($storeIds as $storeId) {
104  $condition[Store::STORE_ID] = $storeId;
105  $conditions[] = $condition;
106  }
107 
108  return $conditions;
109  }
110 
115  private function getWebsiteForWebsiteScope(array $scopes)
116  {
117  $store = $this->getStoreFromScopes($scopes);
118  return $store ? $store->getWebsite() : null;
119  }
120 
125  private function getStoreFromScopes(array $scopes)
126  {
127  foreach ($scopes as $scope) {
128  if (Store::STORE_ID === $scope->getIdentifier()) {
129  return $this->storeManager->getStore($scope->getValue());
130  }
131  }
132 
133  return null;
134  }
135 }
$storeManager
buildNewAttributesWebsiteScope(AbstractAttribute $attribute, EntityMetadataInterface $metadata, array $scopes, $linkFieldValue)
buildExistingAttributeWebsiteScope(AbstractAttribute $attribute, EntityMetadataInterface $metadata, array $scopes, $linkFieldValue)