Skip to content

Commit

Permalink
Merge pull request #4 from tuyennn/feature/Smile-SA-compatibility
Browse files Browse the repository at this point in the history
Feature/smile sa compatibility
  • Loading branch information
tuyennn authored May 19, 2021
2 parents 164876a + 0812e3a commit e938ee2
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 3 deletions.
29 changes: 29 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
name: Bug report
about: Technical issue with the Module

---

### Preconditions (*)
<!---
Provide the exact Magento version (example: 2.2.5) and any important information on the environment where bug is reproducible.
-->
1.
2.

### Steps to reproduce (*)
<!---
Important: Provide a set of clear steps to reproduce this bug. We can not provide support without clear instructions on how to reproduce.
-->
1.
2.

### Expected result (*)
<!--- Tell us what do you expect to happen. -->
1. [Screenshots, logs or description]
2.

### Actual result (*)
<!--- Tell us what happened instead. Include error messages and issues. -->
1. [Screenshots, logs or description]
2.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function afterMap(
$this->inventory->saveRelation(array_keys($documents));

foreach ($documents as $productId => $document) {
$context['document'] = $document;
//@codingStandardsIgnoreLine
$document = array_merge($document, $this->stockDataMapper->map($productId, $storeId));
$documents[$productId] = $document;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
declare(strict_types=1);

namespace GhoSter\OutOfStockAtLast\Plugin\Model\Product\Indexer\Fulltext\Datasource;

use GhoSter\OutOfStockAtLast\Model\Elasticsearch\Adapter\DataMapper\Stock as StockDataMapper;
use GhoSter\OutOfStockAtLast\Model\ResourceModel\Inventory;
use Magento\Framework\Exception\NoSuchEntityException;

class AttributeDataPlugin
{
/**
* @var StockDataMapper
*/
protected $stockDataMapper;

/**
* @var Inventory
*/
protected $inventory;

/**
* AttributeDataPlugin constructor.
* @param StockDataMapper $stockDataMapper
* @param Inventory $inventory
*/
public function __construct(StockDataMapper $stockDataMapper, Inventory $inventory)
{
$this->stockDataMapper = $stockDataMapper;
$this->inventory = $inventory;
}

/**
* @param $subject
* @param array $result
* @param $storeId
* @param array $indexData
* @return array
* @throws NoSuchEntityException
*/
public function afterAddData(
$subject,
array $result,
$storeId,
array $indexData
): array {
$this->inventory->saveRelation(array_keys($indexData));
foreach ($result as $productId => $item) {
//@codingStandardsIgnoreLine
$item = array_merge($item, $this->stockDataMapper->map($productId, $storeId));
$result[$productId] = $item;
}
$this->inventory->clearRelation();

return $result;
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.me/thinghost)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/63baac1389b34c8d8b1005a087f8f2ab)](https://www.codacy.com/gh/tuyennn/magento2-outofstockatlast/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=tuyennn/magento2-outofstockatlast&amp;utm_campaign=Badge_Grade)
[![Build Status](https://travis-ci.org/tuyennn/magento2-outofstockatlast.svg?branch=master)](https://travis-ci.org/tuyennn/magento2-outofstockatlast)
![Version 1.0.0](https://img.shields.io/badge/Version-1.0.0-green.svg)

Expand All @@ -13,6 +14,7 @@

## Main Functionalities
- Sort Out Of Stock Product At last the product list
- Compatibility with `smile/elasticsuite~2.10.0`
- Firstly `Display Out of Stock Products` Stores > Configuration > Catalog > Inventory > Stock must be set `Yes`
- Of course, we are talking about Elastic Search. We don't support *old search engine*

Expand Down
4 changes: 4 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
<plugin sortOrder="10" name="GhoSter_OutOfStockAtLast::add_data_to_mappers_result"
type="GhoSter\OutOfStockAtLast\Plugin\Model\Adapter\BatchDataMapper\ProductDataMapperPlugin"/>
</type>
<type name="Smile\ElasticsuiteCatalog\Model\Product\Indexer\Fulltext\Datasource\AttributeData">
<plugin sortOrder="10" name="GhoSter_OutOfStockAtLast::smile_add_data_to_mappers_result"
type="GhoSter\OutOfStockAtLast\Plugin\Model\Product\Indexer\Fulltext\Datasource\AttributeDataPlugin"/>
</type>
</config>
6 changes: 4 additions & 2 deletions etc/frontend/di.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\ResourceModel\Product\Collection">
<plugin name="GhoSter_OutOfStockAtLast::SortingMethodsProcessor" type="GhoSter\OutOfStockAtLast\Plugin\Model\ResourceModel\Product\CollectionPlugin"/>
<plugin sortOrder="10" name="GhoSter_OutOfStockAtLast::process_sort_collection"
type="GhoSter\OutOfStockAtLast\Plugin\Model\ResourceModel\Product\CollectionPlugin"/>
</type>
</config>

0 comments on commit e938ee2

Please sign in to comment.