Skip to content
This repository was archived by the owner on Jun 11, 2024. It is now read-only.

Commit 96a3673

Browse files
authored
Merge pull request #194 from DivanteLtd/release/v1.9
Release 1.9.0. Update Changelog.md
2 parents c171485 + adb3ca2 commit 96a3673

File tree

24 files changed

+476
-131
lines changed

24 files changed

+476
-131
lines changed

CHANGELOG.MD

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
## Unreleased
44

55

6+
## [1.9.0] (2020.01.28)
7+
8+
### Fixed
9+
- Emulate store when rebuilding cms block and pages. ([#179](https://github.com/DivanteLtd/magento2-vsbridge-indexer/pull/179))
10+
- Fix modules sequence declaration
11+
- Fixes for clean magento install with sample data modules.
12+
- Collecting attributes values when there is no default value ([#160](https://github.com/DivanteLtd/magento2-vsbridge-indexer/pull/160))
13+
14+
### Added
15+
- Product indexer - add dependencies, add dynamic catalogrule_product_price dependencies for Magento <= 2.2.4 ([#176](https://github.com/DivanteLtd/magento2-vsbridge-indexer/pull/176))
16+
- Reindexing products which have beed modified by mass action on product grid when indexers are 'On Save ([#157](https://github.com/DivanteLtd/magento2-vsbridge-indexer/pull/157))
17+
618
## [1.8.3] (2019.12.19)
719

820
### Fixes

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Sign up for a demo at https://vuestorefront.io/ (Vue Storefront integrated with
1616
## Overview
1717

1818
### Version 1.5.0/1.5.1 - support for aliases.
19-
Command ` php bin/magento vsbridge:reindex` will reindex all data to new index.
19+
Command ` php bin/magento vsbridge:reindex --all` will reindex all data to new index.
2020
It will create new index and update aliases at the end.
2121

2222
If you used previous versions, you will have to delete index (created with this extension) from ES manually:

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"name": "Agata",
77
"email": "[email protected]"
88
}],
9-
"version": "1.8.3",
9+
"version": "1.9.0",
1010
"keywords": [
1111
"magento",
1212
"magento2",

src/module-vsbridge-indexer-catalog/Model/Indexer/DataProvider/Product/ConfigurableData.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ private function prepareConfigurableProduct(array $productDTO)
245245
$hasPrice = $this->hasPrice($productDTO);
246246

247247
foreach ($configurableChildren as $child) {
248-
if ($child['stock']['is_in_stock']) {
248+
if (!empty($child['stock']['is_in_stock'])) {
249249
$areChildInStock = 1;
250250
}
251251

@@ -268,9 +268,7 @@ private function prepareConfigurableProduct(array $productDTO)
268268
}
269269
}
270270

271-
$isInStock = $productDTO['stock']['is_in_stock'];
272-
273-
if (!$isInStock || !$areChildInStock) {
271+
if (!empty($productDTO['stock']['is_in_stock']) || !$areChildInStock) {
274272
$productDTO['stock']['is_in_stock'] = false;
275273
$productDTO['stock']['stock_status'] = 0;
276274
}

src/module-vsbridge-indexer-catalog/Model/Indexer/ProductProcessor.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
namespace Divante\VsbridgeIndexerCatalog\Model\Indexer;
1010

11+
use Magento\Framework\Indexer\Config\DependencyInfoProviderInterface;
12+
use Magento\Framework\Indexer\IndexerRegistry;
13+
1114
/**
1215
* Class ProductProcessor
1316
*/
@@ -18,6 +21,25 @@ class ProductProcessor extends \Magento\Framework\Indexer\AbstractProcessor
1821
*/
1922
const INDEXER_ID = 'vsbridge_product_indexer';
2023

24+
/**
25+
* @var DependencyInfoProviderInterface
26+
*/
27+
private $dependencyInfoProvider;
28+
29+
/**
30+
* ProductProcessor constructor.
31+
*
32+
* @param DependencyInfoProviderInterface $dependencyInfoProvider
33+
* @param IndexerRegistry $indexerRegistry
34+
*/
35+
public function __construct(
36+
DependencyInfoProviderInterface $dependencyInfoProvider,
37+
IndexerRegistry $indexerRegistry
38+
) {
39+
parent::__construct($indexerRegistry);
40+
$this->dependencyInfoProvider = $dependencyInfoProvider;
41+
}
42+
2143
/**
2244
* Mark Vsbridge Product indexer as invalid
2345
*
@@ -27,4 +49,50 @@ public function markIndexerAsInvalid()
2749
{
2850
$this->getIndexer()->invalidate();
2951
}
52+
53+
/**
54+
* Run Row reindex
55+
*
56+
* @param int $id
57+
* @param bool $forceReindex
58+
* @return void
59+
*/
60+
public function reindexRow($id, $forceReindex = false)
61+
{
62+
if ($this->hasToReindex()) {
63+
parent::reindexRow($id, $forceReindex);
64+
}
65+
}
66+
67+
/**
68+
* @param int[] $ids
69+
* @param bool $forceReindex
70+
*/
71+
public function reindexList($ids, $forceReindex = false)
72+
{
73+
if ($this->hasToReindex()) {
74+
parent::reindexList($ids, $forceReindex);
75+
}
76+
}
77+
78+
/**
79+
* @return bool
80+
* @throws \Magento\Framework\Exception\NoSuchEntityException
81+
*/
82+
private function hasToReindex(): bool
83+
{
84+
$hasToRun = true;
85+
$dependentIndexerIds = $this->dependencyInfoProvider->getIndexerIdsToRunBefore($this->getIndexerId());
86+
87+
foreach ($dependentIndexerIds as $indexerId) {
88+
$dependentIndexer = $this->indexerRegistry->get($indexerId);
89+
90+
if (!$dependentIndexer->isScheduled()) {
91+
$hasToRun = false;
92+
break;
93+
}
94+
}
95+
96+
return $hasToRun;
97+
}
3098
}

src/module-vsbridge-indexer-catalog/Model/ResourceModel/AbstractEavAttributes.php

Lines changed: 35 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function loadAttributesData($storeId, array $entityIds, array $requiredAt
125125

126126
if (!empty($selects)) {
127127
foreach ($selects as $select) {
128-
$values = $this->getConnection()->fetchAll($select);
128+
$values = $this->getConnection()->fetchAll($select, [], \PDO::FETCH_GROUP);
129129
$this->processValues($values);
130130
}
131131
}
@@ -158,35 +158,39 @@ public function canIndexAttribute(\Magento\Eav\Model\Entity\Attribute $attribute
158158
}
159159

160160
/**
161-
* @param array $values
161+
* @param array $entities
162162
*
163163
* @return array
164164
* @throws \Exception
165165
*/
166-
private function processValues(array $values)
166+
private function processValues(array $entities)
167167
{
168-
foreach ($values as $value) {
169-
$entityIdField = $this->getEntityMetaData()->getIdentifierField();
170-
$entityId = $value[$entityIdField];
171-
$attribute = $this->attributesById[$value['attribute_id']];
172-
$attributeCode = $attribute->getAttributeCode();
168+
foreach ($entities as $entityId => $values) {
169+
foreach ($values as $value) {
170+
$attribute = $this->attributesById[$value['attribute_id']];
171+
$attributeCode = $attribute->getAttributeCode();
173172

174-
if ($attribute->getFrontendInput() === 'multiselect') {
175-
$options = explode(',', $value['value']);
173+
if (isset($this->valuesByEntityId[$entityId][$attributeCode])) {
174+
continue;
175+
}
176+
177+
if ($attribute->getFrontendInput() === 'multiselect') {
178+
$options = explode(',', $value['value']);
179+
180+
if (!empty($options)) {
181+
$options = array_map([$this, 'parseValue',], $options);
182+
}
176183

177-
if (!empty($options)) {
178-
$options = array_map([$this, 'parseValue'], $options);
184+
$value['value'] = $options;
185+
} else {
186+
$value['value'] = $this->prepareValue(
187+
$attributeCode,
188+
$value['value']
189+
);
179190
}
180191

181-
$value['value'] = $options;
182-
} else {
183-
$value['value'] = $this->prepareValue(
184-
$attributeCode,
185-
$value['value']
186-
);
192+
$this->valuesByEntityId[$entityId][$attributeCode] = $value['value'];
187193
}
188-
189-
$this->valuesByEntityId[$entityId][$attributeCode] = $value['value'];
190194
}
191195

192196
return $this->valuesByEntityId;
@@ -235,32 +239,23 @@ private function getLoadAttributesSelect($storeId, $table, array $attributeIds,
235239
$linkField = $this->getEntityMetaData()->getLinkField();
236240
$entityIdField = $this->getEntityMetaData()->getIdentifierField();
237241

238-
$joinStoreCondition = [
239-
"t_default.$linkField=t_store.$linkField",
240-
't_default.attribute_id=t_store.attribute_id',
241-
't_store.store_id=?',
242-
];
243-
244-
$joinCondition = $this->getConnection()->quoteInto(
245-
implode(' AND ', $joinStoreCondition),
246-
$storeId
247-
);
248-
249242
$select = $this->getConnection()->select()
250243
->from(['entity' => $this->getEntityMetaData()->getEntityTable()], [$entityIdField])
251244
->joinInner(
252-
['t_default' => $table],
253-
new \Zend_Db_Expr("entity.{$linkField} = t_default.{$linkField}"),
254-
['attribute_id']
245+
['eav_values' => $table],
246+
new \Zend_Db_Expr("entity.{$linkField} = eav_values.{$linkField}"),
247+
['store_id', 'attribute_id', 'value']
255248
)
256-
->joinLeft(
257-
['t_store' => $table],
258-
$joinCondition,
259-
['value' => new \Zend_Db_Expr('COALESCE(t_store.value, t_default.value)')]
249+
->where(
250+
'eav_values.store_id IN (?)',
251+
[
252+
$storeId,
253+
\Magento\Store\Model\Store::DEFAULT_STORE_ID,
254+
]
260255
)
261-
->where('t_default.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)
262256
->where("entity.$entityIdField IN (?)", $entityIds)
263-
->where('t_default.attribute_id IN (?)', $attributeIds);
257+
->where('eav_values.attribute_id IN (?)', $attributeIds)
258+
->order('eav_values.store_id DESC');
264259

265260
return $select;
266261
}

src/module-vsbridge-indexer-catalog/Model/ResourceModel/Product/AttributeDataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getAttributesById()
6565
*/
6666
public function getAttributeById($attributeId)
6767
{
68-
return $this->loadAttributes->getAttributeById($attributeId);
68+
return $this->loadAttributes->getAttributeById((int) $attributeId);
6969
}
7070

7171
/**

src/module-vsbridge-indexer-catalog/Model/ResourceModel/Product/Configurable.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ private function getConfigurableAttributesForProductsFromResource(array $product
230230
->where('product_id IN (?)', $productIds);
231231
$this->dbHelper->addGroupConcatColumn($select, 'attribute_ids', 'attribute_id');
232232

233-
$attributes = $this->getConnection()->fetchAssoc($select);
234-
235-
return $attributes;
233+
return $this->getConnection()->fetchAssoc($select);
236234
}
237235

238236
/**

src/module-vsbridge-indexer-catalog/Model/ResourceModel/Product/LoadAttributes.php

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ private function initAttributes()
7272
$attributeCollection = $this->getAttributeCollection();
7373

7474
foreach ($attributeCollection as $attribute) {
75-
$this->prepareAttribute($attribute);
76-
77-
$this->attributesById[$attribute->getId()] = $attribute;
78-
$this->attributeCodeToId[$attribute->getAttributeCode()] = $attribute->getId();
75+
$this->addAttribute($attribute);
7976
}
8077
}
8178

@@ -88,7 +85,7 @@ private function initAttributes()
8885
* @return Attribute
8986
* @throws \Magento\Framework\Exception\LocalizedException
9087
*/
91-
public function getAttributeById($attributeId)
88+
public function getAttributeById(int $attributeId)
9289
{
9390
$this->initAttributes();
9491

@@ -105,9 +102,10 @@ public function getAttributeById($attributeId)
105102
* @return Attribute
106103
* @throws \Magento\Framework\Exception\LocalizedException
107104
*/
108-
public function getAttributeByCode($attributeCode)
105+
public function getAttributeByCode(string $attributeCode)
109106
{
110107
$this->initAttributes();
108+
$this->loadAttributeByCode($attributeCode);
111109

112110
if (isset($this->attributeCodeToId[$attributeCode])) {
113111
$attributeId = $this->attributeCodeToId[$attributeCode];
@@ -118,6 +116,34 @@ public function getAttributeByCode($attributeCode)
118116
throw new \Magento\Framework\Exception\LocalizedException(__('Attribute not found.'));
119117
}
120118

119+
/**
120+
* @param string $attributeCode
121+
*/
122+
private function loadAttributeByCode(string $attributeCode)
123+
{
124+
if (!isset($this->attributeCodeToId[$attributeCode])) {
125+
$attributeCollection = $this->getAttributeCollection();
126+
$attributeCollection->addFieldToFilter('attribute_code', $attributeCode);
127+
$attributeCollection->setPageSize(1)->setCurPage(1);
128+
129+
$attribute = $attributeCollection->getFirstItem();
130+
131+
if ($attribute->getId()) {
132+
$this->addAttribute($attribute);
133+
}
134+
}
135+
}
136+
137+
/**
138+
* @param Attribute $attribute
139+
*/
140+
private function addAttribute(Attribute $attribute)
141+
{
142+
$this->prepareAttribute($attribute);
143+
$this->attributesById[$attribute->getId()] = $attribute;
144+
$this->attributeCodeToId[$attribute->getAttributeCode()] = $attribute->getId();
145+
}
146+
121147
/**
122148
* @param Attribute $attribute
123149
*

0 commit comments

Comments
 (0)