6 declare(strict_types=1);
26 private $tableMaintainer;
33 private $dimensionCollectionFactory;
38 private $dimensionsArray;
43 private $dimensionModeConfiguration;
48 private $modeSwitcherConfiguration;
62 $this->tableMaintainer = $tableMaintainer;
63 $this->dimensionCollectionFactory = $dimensionCollectionFactory;
64 $this->dimensionModeConfiguration = $dimensionModeConfiguration;
65 $this->modeSwitcherConfiguration = $modeSwitcherConfiguration;
74 foreach ($this->dimensionModeConfiguration->getDimensionModes() as $dimension => $modes) {
84 public function switchMode(
string $currentMode,
string $previousMode)
88 $this->
moveData($currentMode, $previousMode);
91 $this->modeSwitcherConfiguration->saveMode($currentMode);
107 foreach ($this->getDimensionsArray($currentMode) as $dimensions) {
108 if (!empty($dimensions)) {
109 $this->tableMaintainer->createTablesForDimensions($dimensions);
122 public function moveData(
string $currentMode,
string $previousMode)
124 $dimensionsArrayForCurrentMode = $this->getDimensionsArray($currentMode);
125 $dimensionsArrayForPreviousMode = $this->getDimensionsArray($previousMode);
127 foreach ($dimensionsArrayForCurrentMode as $dimensionsForCurrentMode) {
128 $newTable = $this->tableMaintainer->getMainTable($dimensionsForCurrentMode);
129 if (empty($dimensionsForCurrentMode)) {
131 foreach ($dimensionsArrayForPreviousMode as $dimensionsForPreviousMode) {
132 $oldTable = $this->tableMaintainer->getMainTable($dimensionsForPreviousMode);
133 $this->insertFromOldTablesToNew($newTable, $oldTable);
137 foreach ($dimensionsArrayForPreviousMode as $dimensionsForPreviousMode) {
138 $oldTable = $this->tableMaintainer->getMainTable($dimensionsForPreviousMode);
139 $this->insertFromOldTablesToNew($newTable, $oldTable, $dimensionsForCurrentMode);
154 foreach ($this->getDimensionsArray($previousMode) as $dimensions) {
155 if (empty($dimensions)) {
156 $this->tableMaintainer->truncateTablesForDimensions($dimensions);
158 $this->tableMaintainer->dropTablesForDimensions($dimensions);
172 if (isset($this->dimensionsArray[
$mode])) {
173 return $this->dimensionsArray[
$mode];
176 $this->dimensionsArray[
$mode] = $this->dimensionCollectionFactory->create(
$mode);
178 return $this->dimensionsArray[
$mode];
190 private function insertFromOldTablesToNew(
string $newTable,
string $oldTable, array $dimensions = [])
192 $select = $this->tableMaintainer->getConnection()->select()->from($oldTable);
194 foreach ($dimensions as $dimension) {
195 if ($dimension->getName() === WebsiteDimensionProvider::DIMENSION_NAME) {
196 $select->where(
'website_id = ?', $dimension->getValue());
198 if ($dimension->getName() === CustomerGroupDimensionProvider::DIMENSION_NAME) {
199 $select->where(
'customer_group_id = ?', $dimension->getValue());
202 $this->tableMaintainer->getConnection()->query(
203 $this->tableMaintainer->getConnection()->insertFromSelect(
207 \
Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
createTables(string $currentMode)
dropTables(string $previousMode)
__construct(TableMaintainer $tableMaintainer, DimensionCollectionFactory $dimensionCollectionFactory, DimensionModeConfiguration $dimensionModeConfiguration, ModeSwitcherConfiguration $modeSwitcherConfiguration)
moveData(string $currentMode, string $previousMode)
switchMode(string $currentMode, string $previousMode)
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode