Skip to content

Commit

Permalink
Merge pull request #20 from tuyennn/feature/issue15-query-shard-excep…
Browse files Browse the repository at this point in the history
…tion

Feature/issue15 query shard exception
  • Loading branch information
tuyennn authored Apr 14, 2022
2 parents c258ce6 + 962beaa commit a182058
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Model/Elasticsearch/Adapter/DataMapper/Stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public function __construct(
*
* @param mixed $entityId
* @param mixed $storeId
* @return bool[]|int[]
* @return int[]
* @throws NoSuchEntityException
*/
public function map($entityId, $storeId): array
{
$sku = $this->inventory->getSkuRelation((int)$entityId);

if (!$sku) {
return ['out_of_stock_at_last' => true];
return ['out_of_stock_at_last' => 1];
}

$value = $this->inventory->getStockStatus(
Expand Down
45 changes: 45 additions & 0 deletions Plugin/Model/Adapter/AdditionalFieldMapperPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace GhoSter\OutOfStockAtLast\Plugin\Model\Adapter;

/**
* phpcs:ignore Magento2.Legacy.Copyright.FoundCopyrightMissingOrWrongFormat
* Class AdditionalFieldMapperPlugin for es attributes mapping
*/
class AdditionalFieldMapperPlugin
{
/**
* @var string[]
*/
protected $allowedFields = [
'out_of_stock_at_last' => 'integer'
];

/**
* Missing mapped attribute code
*
* @param mixed $subject
* @param array $result
* @return array
*/
public function afterGetAllAttributesTypes($subject, array $result): array
{
foreach ($this->allowedFields as $fieldName => $fieldType) {
$result[$fieldName] = ['type' => $fieldType];
}

return $result;
}

/**
* 3rd module Compatibility
*
* @param mixed $subject
* @param array $result
* @return array
*/
public function afterBuildEntityFields($subject, array $result): array
{
return $this->afterGetAllAttributesTypes($subject, $result);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"magento/module-elasticsearch-7": "*"
},
"type": "magento2-module",
"version": "1.0.2",
"version": "1.0.3",
"authors": [
{
"name": "Tuyen Nguyen",
Expand Down
9 changes: 9 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Elasticsearch\Model\Adapter\FieldMapper\ProductFieldMapper">
<plugin sortOrder="10" name="GhoSter_OutOfStockAtLast::add_more_field"
type="GhoSter\OutOfStockAtLast\Plugin\Model\Adapter\AdditionalFieldMapperPlugin"/>
</type>
<type name="Magento\Elasticsearch\Elasticsearch5\Model\Adapter\FieldMapper\ProductFieldMapperProxy">
<plugin sortOrder="10" name="GhoSter_OutOfStockAtLast::add_more_field_deprecated"
type="GhoSter\OutOfStockAtLast\Plugin\Model\Adapter\AdditionalFieldMapperPlugin"/>
</type>

<type name="Magento\Elasticsearch\Model\Adapter\BatchDataMapper\ProductDataMapper">
<plugin sortOrder="10" name="GhoSter_OutOfStockAtLast::add_data_to_mappers_result"
type="GhoSter\OutOfStockAtLast\Plugin\Model\Adapter\BatchDataMapper\ProductDataMapperPlugin"/>
Expand Down

0 comments on commit a182058

Please sign in to comment.