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 #125 from bartoszherba/abstact-mapper-refactor
Browse files Browse the repository at this point in the history
Rework abstract mapper to allow configure static type map in di.xml
  • Loading branch information
afirlejczyk authored Oct 11, 2019
2 parents a40bc0a + 5eb6992 commit 0bd2fc6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ abstract class AbstractMapping
/**
* @var array
*/
private $staticFieldMapping = [
'status' => FieldInterface::TYPE_INTEGER,
'visibility' => FieldInterface::TYPE_INTEGER,
'position' => FieldInterface::TYPE_LONG,
'level' => FieldInterface::TYPE_INTEGER,
'category_ids' => FieldInterface::TYPE_LONG,
'sku' => FieldInterface::TYPE_KEYWORD,
'url_path' => FieldInterface::TYPE_KEYWORD,
'url_key' => FieldInterface::TYPE_KEYWORD,
];
private $staticFieldMapping;

/**
* AbstractMapping constructor.
*
* @param array $staticFieldMapping
*/
public function __construct(array $staticFieldMapping)
{
$this->staticFieldMapping = $staticFieldMapping;
}

/**
* @var array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
*/
class Category extends AbstractMapping implements MappingInterface
{

/**
* @var array
*/
Expand Down Expand Up @@ -61,17 +60,20 @@ class Category extends AbstractMapping implements MappingInterface
* @param GeneralMapping $generalMapping
* @param CategoryChildAttributes $categoryChildAttributes
* @param AttributeDataProvider $resourceModel
* @param array $staticFieldMapping
*/
public function __construct(
EventManager $eventManager,
GeneralMapping $generalMapping,
CategoryChildAttributes $categoryChildAttributes,
AttributeDataProvider $resourceModel
AttributeDataProvider $resourceModel,
array $staticFieldMapping
) {
$this->eventManager = $eventManager;
$this->generalMapping = $generalMapping;
$this->resourceModel = $resourceModel;
$this->childAttributes = $categoryChildAttributes;
parent::__construct($staticFieldMapping);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/module-vsbridge-indexer-catalog/Index/Mapping/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/
class Product extends AbstractMapping implements MappingInterface
{

/**
* @var EventManager
*/
Expand Down Expand Up @@ -52,12 +51,14 @@ public function __construct(
EventManager $eventManager,
GeneralMapping $generalMapping,
ConfigurableAttributes $configurableAttributes,
AttributeDataProvider $resourceModel
AttributeDataProvider $resourceModel,
array $staticFieldMapping
) {
$this->eventManager = $eventManager;
$this->generalMapping = $generalMapping;
$this->resourceModel = $resourceModel;
$this->configurableAttributes = $configurableAttributes;
parent::__construct($staticFieldMapping);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions src/module-vsbridge-indexer-catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,18 @@
<type name="Magento\CatalogInventory\Observer\ReindexQuoteInventoryObserver">
<plugin name="update_product_in_es" type="Divante\VsbridgeIndexerCatalog\Plugin\Indexer\CatalogInventory\ReindexQuoteInventoryObserverPlugin"/>
</type>
<type name="Divante\VsbridgeIndexerCatalog\Index\Mapping\AbstractMapping">
<arguments>
<argument name="staticFieldMapping" xsi:type="array">
<item name="status" xsi:type="const">Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface::TYPE_INTEGER</item>
<item name="visibility" xsi:type="const">Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface::TYPE_INTEGER</item>
<item name="position" xsi:type="const">Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface::TYPE_LONG</item>
<item name="level" xsi:type="const">Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface::TYPE_INTEGER</item>
<item name="category_ids" xsi:type="const">Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface::TYPE_LONG</item>
<item name="sku" xsi:type="const">Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface::TYPE_KEYWORD</item>
<item name="url_path" xsi:type="const">Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface::TYPE_KEYWORD</item>
<item name="url_key" xsi:type="const">Divante\VsbridgeIndexerCore\Api\Mapping\FieldInterface::TYPE_KEYWORD</item>
</argument>
</arguments>
</type>
</config>

0 comments on commit 0bd2fc6

Please sign in to comment.