This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Magento 2.2.5 - backward compatibility for versions < 2.2.6
Fix issue with PriceTableResolver #53.
- Loading branch information
Agata Firlejczyk
committed
Aug 30, 2019
1 parent
ee4d8b7
commit 25a7aa3
Showing
2 changed files
with
134 additions
and
41 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
src/module-vsbridge-indexer-catalog/Model/Product/PriceTableResolverProxy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<?php | ||
/** | ||
* @package Divante\VsbridgeIndexerCatalog | ||
* @author Agata Firlejczyk <afirlejczyk@divante.pl> | ||
* @copyright 2019 Divante Sp. z o.o. | ||
* @license See LICENSE_DIVANTE.txt for license details. | ||
*/ | ||
|
||
namespace Divante\VsbridgeIndexerCatalog\Model\Product; | ||
|
||
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider; | ||
use Magento\Framework\Indexer\DimensionFactory; | ||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Store\Model\Indexer\WebsiteDimensionProvider; | ||
|
||
/** | ||
* Class PriceTableResolverProxy | ||
*/ | ||
class PriceTableResolverProxy | ||
{ | ||
const DEFAULT_PRICE_INDEXER_TABLE = 'catalog_product_index_price'; | ||
|
||
/** | ||
* Object Manager instance | ||
* | ||
* @var \Magento\Framework\ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* available from Magento 2.6 | ||
* @var \Magento\Framework\Indexer\DimensionFactory | ||
*/ | ||
private $dimensionFactory; | ||
|
||
/** | ||
* available from Magento 2.6 | ||
* @var \Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver | ||
*/ | ||
private $priceTableResolver; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $priceIndexTableName = []; | ||
|
||
/** | ||
* PriceTableResolver constructor. | ||
* | ||
* @param ObjectManagerInterface $objectManager | ||
*/ | ||
public function __construct(ObjectManagerInterface $objectManager) | ||
{ | ||
$this->objectManager = $objectManager; | ||
} | ||
|
||
/** | ||
* @param int $websiteId | ||
* @param int $customerGroupId | ||
* | ||
* @return mixed|string | ||
*/ | ||
public function resolve(int $websiteId, int $customerGroupId) | ||
{ | ||
if (class_exists('\Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver')) { | ||
$this->createDimensionFactory(); | ||
$this->createPriceTableResolver(); | ||
$key = $websiteId . '_' . $customerGroupId; | ||
|
||
if (!isset($this->priceIndexTableName[$key])) { | ||
$priceIndexTableName = $this->priceTableResolver->resolve( | ||
self::DEFAULT_PRICE_INDEXER_TABLE, | ||
[ | ||
$this->dimensionFactory->create( | ||
WebsiteDimensionProvider::DIMENSION_NAME, | ||
(string)$websiteId | ||
), | ||
$this->dimensionFactory->create( | ||
CustomerGroupDimensionProvider::DIMENSION_NAME, | ||
(string)$customerGroupId | ||
), | ||
] | ||
); | ||
|
||
$this->priceIndexTableName[$key] = (string)$priceIndexTableName; | ||
} | ||
|
||
return $this->priceIndexTableName[$key]; | ||
} | ||
|
||
return self::DEFAULT_PRICE_INDEXER_TABLE; | ||
} | ||
|
||
/** | ||
* @return DimensionFactory | ||
*/ | ||
private function createDimensionFactory() | ||
{ | ||
if (null === $this->dimensionFactory) { | ||
$this->dimensionFactory = $this->create(\Magento\Framework\Indexer\DimensionFactory::class); | ||
} | ||
|
||
return $this->dimensionFactory; | ||
} | ||
|
||
/** | ||
* @return \Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver | ||
*/ | ||
private function createPriceTableResolver() | ||
{ | ||
if (null === $this->priceTableResolver) { | ||
$this->priceTableResolver = $this->create( | ||
\Magento\Catalog\Model\Indexer\Product\Price\PriceTableResolver::class | ||
); | ||
} | ||
|
||
return $this->priceTableResolver; | ||
} | ||
|
||
/** | ||
* @param string $class | ||
* | ||
* @return mixed | ||
*/ | ||
private function create($class) | ||
{ | ||
return $this->objectManager->create($class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters