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

Commit

Permalink
Merge pull request #194 from DivanteLtd/release/v1.9
Browse files Browse the repository at this point in the history
Release 1.9.0. Update Changelog.md
  • Loading branch information
afirlejczyk authored Jan 28, 2020
2 parents c171485 + adb3ca2 commit 96a3673
Show file tree
Hide file tree
Showing 24 changed files with 476 additions and 131 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
## Unreleased


## [1.9.0] (2020.01.28)

### Fixed
- Emulate store when rebuilding cms block and pages. ([#179](https://github.com/DivanteLtd/magento2-vsbridge-indexer/pull/179))
- Fix modules sequence declaration
- Fixes for clean magento install with sample data modules.
- Collecting attributes values when there is no default value ([#160](https://github.com/DivanteLtd/magento2-vsbridge-indexer/pull/160))

### Added
- 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))
- 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))

## [1.8.3] (2019.12.19)

### Fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Sign up for a demo at https://vuestorefront.io/ (Vue Storefront integrated with
## Overview

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

If you used previous versions, you will have to delete index (created with this extension) from ES manually:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"name": "Agata",
"email": "[email protected]"
}],
"version": "1.8.3",
"version": "1.9.0",
"keywords": [
"magento",
"magento2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private function prepareConfigurableProduct(array $productDTO)
$hasPrice = $this->hasPrice($productDTO);

foreach ($configurableChildren as $child) {
if ($child['stock']['is_in_stock']) {
if (!empty($child['stock']['is_in_stock'])) {
$areChildInStock = 1;
}

Expand All @@ -268,9 +268,7 @@ private function prepareConfigurableProduct(array $productDTO)
}
}

$isInStock = $productDTO['stock']['is_in_stock'];

if (!$isInStock || !$areChildInStock) {
if (!empty($productDTO['stock']['is_in_stock']) || !$areChildInStock) {
$productDTO['stock']['is_in_stock'] = false;
$productDTO['stock']['stock_status'] = 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

namespace Divante\VsbridgeIndexerCatalog\Model\Indexer;

use Magento\Framework\Indexer\Config\DependencyInfoProviderInterface;
use Magento\Framework\Indexer\IndexerRegistry;

/**
* Class ProductProcessor
*/
Expand All @@ -18,6 +21,25 @@ class ProductProcessor extends \Magento\Framework\Indexer\AbstractProcessor
*/
const INDEXER_ID = 'vsbridge_product_indexer';

/**
* @var DependencyInfoProviderInterface
*/
private $dependencyInfoProvider;

/**
* ProductProcessor constructor.
*
* @param DependencyInfoProviderInterface $dependencyInfoProvider
* @param IndexerRegistry $indexerRegistry
*/
public function __construct(
DependencyInfoProviderInterface $dependencyInfoProvider,
IndexerRegistry $indexerRegistry
) {
parent::__construct($indexerRegistry);
$this->dependencyInfoProvider = $dependencyInfoProvider;
}

/**
* Mark Vsbridge Product indexer as invalid
*
Expand All @@ -27,4 +49,50 @@ public function markIndexerAsInvalid()
{
$this->getIndexer()->invalidate();
}

/**
* Run Row reindex
*
* @param int $id
* @param bool $forceReindex
* @return void
*/
public function reindexRow($id, $forceReindex = false)
{
if ($this->hasToReindex()) {
parent::reindexRow($id, $forceReindex);
}
}

/**
* @param int[] $ids
* @param bool $forceReindex
*/
public function reindexList($ids, $forceReindex = false)
{
if ($this->hasToReindex()) {
parent::reindexList($ids, $forceReindex);
}
}

/**
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function hasToReindex(): bool
{
$hasToRun = true;
$dependentIndexerIds = $this->dependencyInfoProvider->getIndexerIdsToRunBefore($this->getIndexerId());

foreach ($dependentIndexerIds as $indexerId) {
$dependentIndexer = $this->indexerRegistry->get($indexerId);

if (!$dependentIndexer->isScheduled()) {
$hasToRun = false;
break;
}
}

return $hasToRun;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function loadAttributesData($storeId, array $entityIds, array $requiredAt

if (!empty($selects)) {
foreach ($selects as $select) {
$values = $this->getConnection()->fetchAll($select);
$values = $this->getConnection()->fetchAll($select, [], \PDO::FETCH_GROUP);
$this->processValues($values);
}
}
Expand Down Expand Up @@ -158,35 +158,39 @@ public function canIndexAttribute(\Magento\Eav\Model\Entity\Attribute $attribute
}

/**
* @param array $values
* @param array $entities
*
* @return array
* @throws \Exception
*/
private function processValues(array $values)
private function processValues(array $entities)
{
foreach ($values as $value) {
$entityIdField = $this->getEntityMetaData()->getIdentifierField();
$entityId = $value[$entityIdField];
$attribute = $this->attributesById[$value['attribute_id']];
$attributeCode = $attribute->getAttributeCode();
foreach ($entities as $entityId => $values) {
foreach ($values as $value) {
$attribute = $this->attributesById[$value['attribute_id']];
$attributeCode = $attribute->getAttributeCode();

if ($attribute->getFrontendInput() === 'multiselect') {
$options = explode(',', $value['value']);
if (isset($this->valuesByEntityId[$entityId][$attributeCode])) {
continue;
}

if ($attribute->getFrontendInput() === 'multiselect') {
$options = explode(',', $value['value']);

if (!empty($options)) {
$options = array_map([$this, 'parseValue',], $options);
}

if (!empty($options)) {
$options = array_map([$this, 'parseValue'], $options);
$value['value'] = $options;
} else {
$value['value'] = $this->prepareValue(
$attributeCode,
$value['value']
);
}

$value['value'] = $options;
} else {
$value['value'] = $this->prepareValue(
$attributeCode,
$value['value']
);
$this->valuesByEntityId[$entityId][$attributeCode] = $value['value'];
}

$this->valuesByEntityId[$entityId][$attributeCode] = $value['value'];
}

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

$joinStoreCondition = [
"t_default.$linkField=t_store.$linkField",
't_default.attribute_id=t_store.attribute_id',
't_store.store_id=?',
];

$joinCondition = $this->getConnection()->quoteInto(
implode(' AND ', $joinStoreCondition),
$storeId
);

$select = $this->getConnection()->select()
->from(['entity' => $this->getEntityMetaData()->getEntityTable()], [$entityIdField])
->joinInner(
['t_default' => $table],
new \Zend_Db_Expr("entity.{$linkField} = t_default.{$linkField}"),
['attribute_id']
['eav_values' => $table],
new \Zend_Db_Expr("entity.{$linkField} = eav_values.{$linkField}"),
['store_id', 'attribute_id', 'value']
)
->joinLeft(
['t_store' => $table],
$joinCondition,
['value' => new \Zend_Db_Expr('COALESCE(t_store.value, t_default.value)')]
->where(
'eav_values.store_id IN (?)',
[
$storeId,
\Magento\Store\Model\Store::DEFAULT_STORE_ID,
]
)
->where('t_default.store_id = ?', \Magento\Store\Model\Store::DEFAULT_STORE_ID)
->where("entity.$entityIdField IN (?)", $entityIds)
->where('t_default.attribute_id IN (?)', $attributeIds);
->where('eav_values.attribute_id IN (?)', $attributeIds)
->order('eav_values.store_id DESC');

return $select;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getAttributesById()
*/
public function getAttributeById($attributeId)
{
return $this->loadAttributes->getAttributeById($attributeId);
return $this->loadAttributes->getAttributeById((int) $attributeId);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ private function getConfigurableAttributesForProductsFromResource(array $product
->where('product_id IN (?)', $productIds);
$this->dbHelper->addGroupConcatColumn($select, 'attribute_ids', 'attribute_id');

$attributes = $this->getConnection()->fetchAssoc($select);

return $attributes;
return $this->getConnection()->fetchAssoc($select);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ private function initAttributes()
$attributeCollection = $this->getAttributeCollection();

foreach ($attributeCollection as $attribute) {
$this->prepareAttribute($attribute);

$this->attributesById[$attribute->getId()] = $attribute;
$this->attributeCodeToId[$attribute->getAttributeCode()] = $attribute->getId();
$this->addAttribute($attribute);
}
}

Expand All @@ -88,7 +85,7 @@ private function initAttributes()
* @return Attribute
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getAttributeById($attributeId)
public function getAttributeById(int $attributeId)
{
$this->initAttributes();

Expand All @@ -105,9 +102,10 @@ public function getAttributeById($attributeId)
* @return Attribute
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function getAttributeByCode($attributeCode)
public function getAttributeByCode(string $attributeCode)
{
$this->initAttributes();
$this->loadAttributeByCode($attributeCode);

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

/**
* @param string $attributeCode
*/
private function loadAttributeByCode(string $attributeCode)
{
if (!isset($this->attributeCodeToId[$attributeCode])) {
$attributeCollection = $this->getAttributeCollection();
$attributeCollection->addFieldToFilter('attribute_code', $attributeCode);
$attributeCollection->setPageSize(1)->setCurPage(1);

$attribute = $attributeCollection->getFirstItem();

if ($attribute->getId()) {
$this->addAttribute($attribute);
}
}
}

/**
* @param Attribute $attribute
*/
private function addAttribute(Attribute $attribute)
{
$this->prepareAttribute($attribute);
$this->attributesById[$attribute->getId()] = $attribute;
$this->attributeCodeToId[$attribute->getAttributeCode()] = $attribute->getId();
}

/**
* @param Attribute $attribute
*
Expand Down
Loading

0 comments on commit 96a3673

Please sign in to comment.