Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TableResolver.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
17 use Magento\Customer\Model\Context as CustomerContext;
20 
26 {
30  private $priceTableResolver;
31 
35  private $storeManager;
36 
40  private $httpContext;
41 
45  private $dimensionFactory;
46 
50  private $dimensionModeConfiguration;
51 
59  public function __construct(
60  IndexScopeResolverInterface $priceTableResolver,
61  StoreManagerInterface $storeManager,
62  Context $context,
63  DimensionFactory $dimensionFactory,
64  DimensionModeConfiguration $dimensionModeConfiguration
65  ) {
66  $this->priceTableResolver = $priceTableResolver;
67  $this->storeManager = $storeManager;
68  $this->httpContext = $context;
69  $this->dimensionFactory = $dimensionFactory;
70  $this->dimensionModeConfiguration = $dimensionModeConfiguration;
71  }
72 
83  public function afterGetTableName(
84  ResourceConnection $subject,
85  string $result,
87  ) {
88  if (!is_array($tableName)
89  && $tableName === 'catalog_product_index_price'
90  && $this->dimensionModeConfiguration->getDimensionConfiguration()
91  ) {
92  return $this->priceTableResolver->resolve('catalog_product_index_price', $this->getDimensions());
93  }
94 
95  return $result;
96  }
97 
102  private function getDimensions(): array
103  {
104  $dimensions = [];
105  foreach ($this->dimensionModeConfiguration->getDimensionConfiguration() as $dimensionName) {
106  if ($dimensionName === WebsiteDimensionProvider::DIMENSION_NAME) {
107  $dimensions[] = $this->createDimensionFromWebsite();
108  }
109  if ($dimensionName === CustomerGroupDimensionProvider::DIMENSION_NAME) {
110  $dimensions[] = $this->createDimensionFromCustomerGroup();
111  }
112  }
113 
114  return $dimensions;
115  }
116 
121  private function createDimensionFromWebsite(): Dimension
122  {
123  $storeKey = $this->httpContext->getValue(StoreManagerInterface::CONTEXT_STORE);
124  return $this->dimensionFactory->create(
125  WebsiteDimensionProvider::DIMENSION_NAME,
126  (string)$this->storeManager->getStore($storeKey)->getWebsiteId()
127  );
128  }
129 
133  private function createDimensionFromCustomerGroup(): Dimension
134  {
135  return $this->dimensionFactory->create(
136  CustomerGroupDimensionProvider::DIMENSION_NAME,
137  (string)$this->httpContext->getValue(CustomerContext::CONTEXT_GROUP)
138  );
139  }
140 }
$tableName
Definition: trigger.php:13
__construct(IndexScopeResolverInterface $priceTableResolver, StoreManagerInterface $storeManager, Context $context, DimensionFactory $dimensionFactory, DimensionModeConfiguration $dimensionModeConfiguration)
$storeManager
afterGetTableName(ResourceConnection $subject, string $result, $tableName)