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

Commit

Permalink
Merge branch develop.
Browse files Browse the repository at this point in the history
  • Loading branch information
Agata Firlejczyk committed Nov 15, 2019
2 parents 2d08499 + 2cc62d3 commit 67b0977
Show file tree
Hide file tree
Showing 25 changed files with 513 additions and 330 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased

## [1.7.0] (2019.11.14)

### Changed/Improved
- Speed up exporting for product/category data. Class `ConvertDataTypes` was removed, converting value to int/float is executed when loading product/category attributes.

## [1.6.0] (2019.11.07)

### Added
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.6.0",
"version": "1.7.0",
"keywords": [
"magento",
"magento2",
Expand Down
10 changes: 5 additions & 5 deletions src/module-vsbridge-indexer-catalog/Index/Mapping/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace Divante\VsbridgeIndexerCatalog\Index\Mapping;

use Divante\VsbridgeIndexerCatalog\Model\Attributes\CategoryChildAttributes;
use Divante\VsbridgeIndexerCatalog\Model\ResourceModel\Category\AttributeDataProvider;
use Divante\VsbridgeIndexerCatalog\Model\ResourceModel\Category\LoadAttributes;
use Divante\VsbridgeIndexerCore\Api\MappingInterface;
use Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface;
use Divante\VsbridgeIndexerCore\Index\Mapping\GeneralMapping;
Expand Down Expand Up @@ -39,7 +39,7 @@ class Category extends AbstractMapping implements MappingInterface
private $generalMapping;

/**
* @var AttributeDataProvider
* @var LoadAttributes
*/
private $resourceModel;

Expand All @@ -59,14 +59,14 @@ class Category extends AbstractMapping implements MappingInterface
* @param EventManager $eventManager
* @param GeneralMapping $generalMapping
* @param CategoryChildAttributes $categoryChildAttributes
* @param AttributeDataProvider $resourceModel
* @param LoadAttributes $resourceModel
* @param array $staticFieldMapping
*/
public function __construct(
EventManager $eventManager,
GeneralMapping $generalMapping,
CategoryChildAttributes $categoryChildAttributes,
AttributeDataProvider $resourceModel,
LoadAttributes $resourceModel,
array $staticFieldMapping
) {
$this->eventManager = $eventManager;
Expand Down Expand Up @@ -161,6 +161,6 @@ private function getChildrenDataMapping(array $allAttributesMapping, array $comm
*/
public function getAttributes()
{
return $this->resourceModel->initAttributes();
return $this->resourceModel->execute();
}
}
10 changes: 5 additions & 5 deletions src/module-vsbridge-indexer-catalog/Index/Mapping/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Divante\VsbridgeIndexerCore\Api\MappingInterface;
use Divante\VsbridgeIndexerCore\Index\Mapping\GeneralMapping;
use Divante\VsbridgeIndexerCatalog\Model\Attributes\ConfigurableAttributes;
use Divante\VsbridgeIndexerCatalog\Model\ResourceModel\Product\AttributeDataProvider;
use Divante\VsbridgeIndexerCatalog\Model\ResourceModel\Product\LoadAttributes;
use Magento\Framework\Event\ManagerInterface as EventManager;

/**
Expand All @@ -30,7 +30,7 @@ class Product extends AbstractMapping implements MappingInterface
private $properties;

/**
* @var AttributeDataProvider
* @var LoadAttributes
*/
private $resourceModel;

Expand All @@ -45,14 +45,14 @@ class Product extends AbstractMapping implements MappingInterface
* @param EventManager $eventManager
* @param GeneralMapping $generalMapping
* @param ConfigurableAttributes $configurableAttributes
* @param AttributeDataProvider $resourceModel
* @param LoadAttributes $resourceModel
* @param array $staticFieldMapping
*/
public function __construct(
EventManager $eventManager,
GeneralMapping $generalMapping,
ConfigurableAttributes $configurableAttributes,
AttributeDataProvider $resourceModel,
LoadAttributes $resourceModel,
array $staticFieldMapping
) {
$this->eventManager = $eventManager;
Expand Down Expand Up @@ -327,6 +327,6 @@ private function getTierPricesMapping(): array
*/
public function getAttributes()
{
return $this->resourceModel->getAttributesById();
return $this->resourceModel->execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private function loadOptions(Attribute $attribute): array
$options = $source->getAllOptions();
} else {
$loadSwatches = $this->isVisualSwatch($attribute);
$optionCollection = $this->getOptionCollection($attribute, $loadSwatches);
$optionCollection = $this->getOptionCollection($attribute);
$additionalFields = [];

if ($loadSwatches) {
Expand Down Expand Up @@ -127,8 +127,9 @@ private function useSourceModel(Attribute $attribute)
*
* @return OptionCollection
*/
private function getOptionCollection(Attribute $attribute, $loadSwatches)
private function getOptionCollection(Attribute $attribute)
{
$loadSwatches = $this->isVisualSwatch($attribute);
$attributeId = $attribute->getAttributeId();
$storeId = $attribute->getStoreId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
namespace Divante\VsbridgeIndexerCatalog\Model\Indexer\Action;

use Divante\VsbridgeIndexerCatalog\Model\ResourceModel\Attribute as ResourceModel;
use Divante\VsbridgeIndexerCatalog\Index\Mapping\Attribute as AttributeMapping;
use Divante\VsbridgeIndexerCore\Api\ConvertValueInterface;

/**
* Class Attribute
Expand All @@ -20,14 +22,31 @@ class Attribute
*/
private $resourceModel;

/**
* @var AttributeMapping
*/
private $attributeMapping;

/**
* @var ConvertValueInterface
*/
private $convertValue;

/**
* Attribute constructor.
*
* @param ConvertValueInterface $convertValue
* @param AttributeMapping $attributeMapping
* @param ResourceModel $resourceModel
*/
public function __construct(ResourceModel $resourceModel)
{
public function __construct(
ConvertValueInterface $convertValue,
AttributeMapping $attributeMapping,
ResourceModel $resourceModel
) {
$this->convertValue = $convertValue;
$this->resourceModel = $resourceModel;
$this->attributeMapping = $attributeMapping;
}

/**
Expand Down Expand Up @@ -59,8 +78,8 @@ public function rebuild(array $attributeIds = [])
*/
private function filterData(array $attributeData)
{
if (isset($attributeData['position'])) {
$attributeData['position'] = (int)$attributeData['position'];
foreach ($attributeData as $key => &$value) {
$this->convertValue->execute($this->attributeMapping, $key, $value);
}

return $attributeData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ public function rebuild($storeId = 1, array $productIds = [])

/** @var array $product */
foreach ($products as $product) {
$lastProductId = $product['entity_id'];
$product['id'] = (int)$product['entity_id'];
$lastProductId = (int)$product['entity_id'];
$product['id'] = $lastProductId;

$product['attribute_set_id'] = (int)$product['attribute_set_id'];
unset($product['required_options']);
unset($product['has_options']);
yield $lastProductId => $product;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,20 @@ public function addData(array $indexData, $storeId)

foreach ($priceData as $priceDataRow) {
$productId = $priceDataRow['entity_id'];
$indexData[$productId]['final_price'] = $priceDataRow['final_price'];
$indexData[$productId]['regular_price'] = $priceDataRow['price'];
$indexData[$productId]['final_price'] = $this->preparePrice($priceDataRow['final_price']);
$indexData[$productId]['regular_price'] = $this->preparePrice($priceDataRow['price']);
}

return $this->tierPriceProcessor->applyTierGroupPrices($indexData, $storeId);
}

/**
* @param string $value
*
* @return float
*/
private function preparePrice($value)
{
return (float)$value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Divante\VsbridgeIndexerCatalog\Model\ResourceModel;

use Divante\VsbridgeIndexerCore\Api\ConvertValueInterface;
use Divante\VsbridgeIndexerCore\Api\MappingInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\EntityManager\EntityMetadataInterface;
Expand All @@ -22,6 +24,7 @@ abstract class AbstractEavAttributes implements EavAttributesInterface
*/
private $restrictedAttribute = [
'quantity_and_stock_status',
'options_container',
];

/**
Expand Down Expand Up @@ -50,20 +53,36 @@ abstract class AbstractEavAttributes implements EavAttributesInterface
private $metadataPool;

/**
* EavAttributes constructor.
* @var MappingInterface
*/
private $mapping;

/**
* @var ConvertValueInterface
*/
private $convertValue;

/**
* AbstractEavAttributes constructor.
*
* @param ResourceConnection $resourceConnection
* @param MetadataPool $metadataPool
* @param ConvertValueInterface $convertValue
* @param MappingInterface $mapping
* @param string $entityType
*/
public function __construct(
ResourceConnection $resourceConnection,
MetadataPool $metadataPool,
ConvertValueInterface $convertValue,
MappingInterface $mapping,
$entityType
) {
$this->resourceConnection = $resourceConnection;
$this->metadataPool = $metadataPool;
$this->entityType = $entityType;
$this->convertValue = $convertValue;
$this->mapping = $mapping;
}

/**
Expand Down Expand Up @@ -107,7 +126,7 @@ public function loadAttributesData($storeId, array $entityIds, array $requiredAt
if (!empty($selects)) {
foreach ($selects as $select) {
$values = $this->getConnection()->fetchAll($select);
$this->prepareValues($values);
$this->processValues($values);
}
}

Expand Down Expand Up @@ -144,12 +163,13 @@ public function canIndexAttribute(\Magento\Eav\Model\Entity\Attribute $attribute
* @return array
* @throws \Exception
*/
private function prepareValues(array $values)
private function processValues(array $values)
{
foreach ($values as $value) {
$entityIdField = $this->getEntityMetaData()->getIdentifierField();
$entityId = $value[$entityIdField];
$attribute = $this->attributesById[$value['attribute_id']];
$attributeCode = $attribute->getAttributeCode();

if ($attribute->getFrontendInput() === 'multiselect') {
$options = explode(',', $value['value']);
Expand All @@ -159,15 +179,31 @@ private function prepareValues(array $values)
}

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

$attributeCode = $attribute->getAttributeCode();
$this->valuesByEntityId[$entityId][$attributeCode] = $value['value'];
}

return $this->valuesByEntityId;
}

/**
* @param string $attributeCode
* @param array|string $value
*
* @return array|string|int|float
* @throws \Exception
*/
private function prepareValue(string $attributeCode, $value)
{
return $this->convertValue->execute($this->mapping, $attributeCode, $value);
}

/**
* Parse the option value - Cast to int if it's numeric
* otherwise leave it as-is
Expand Down
Loading

0 comments on commit 67b0977

Please sign in to comment.