Skip to content

Add interception to reindex products being affected by reservations #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
],
"require": {
"php": ">=7.0.2",
"divante/magento2-vsbridge-indexer-msi": "*"
"divante/magento2-vsbridge-indexer-msi": "*",
"magento/module-inventory-reservations": ">=1.0.6"
},
"autoload": {
"files": [
Expand Down
82 changes: 55 additions & 27 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions src/Plugin/ResourceModel/SaveMultiple.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Kodbruket\VsbridgeIndexerMsiReservation\Plugin\ResourceModel;

use Divante\VsbridgeIndexerCatalog\Model\Indexer\ProductProcessor;
use Magento\Catalog\Model\ProductRepository;

/**
* Save multiple
*
* Interception to make sure that products being reserved also get
* triggered for reindexing.
*/
class SaveMultiple
{
/**
* Product processor
*
* @var ProductProcessor
*/
private $productProcessor;

/**
* Product repository
*
* @var ProductRepository
*/
private $productRepository;

/**
* Constructor
*
* @param ProductProcessor $processor
* @param ProductRepository $productRepository
*
* @return void
*/
public function __construct(ProductProcessor $processor, ProductRepository $productRepository)
{
$this->productProcessor = $processor;
$this->productRepository = $productRepository;
}

/**
* After execute
*
* Interception to make sure that products being reserved also get
* triggered for reindexing.
*
* @param \Magento\InventoryReservations\Model\ResourceModel\SaveMultiple $subject
* @param null $result
* @param ReservationInterface[] $reservations
*
* @return void
*/
public function afterExecute(
\Magento\InventoryReservations\Model\ResourceModel\SaveMultiple $subject,
$result,
array $reservations
) {
foreach ($reservations as $reservation) {
$product = $this->productRepository->get($reservation->getSku());
$this->productProcessor->reindexRow($product->getId());
}
}
}
5 changes: 4 additions & 1 deletion src/etc/di.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?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="Divante\VsbridgeIndexerMsi\Model\ResourceModel\Product\Inventory">
<plugin name="kodbruket_vsbridgeindexermsireservaation_plugin_resourcemodel_product_inventory" type="Kodbruket\VsbridgeIndexerMsiReservation\Plugin\ResourceModel\Product\Inventory" />
<plugin name="kodbruket_vsbridgeindexermsireservation_plugin_resourcemodel_product_inventory" type="Kodbruket\VsbridgeIndexerMsiReservation\Plugin\ResourceModel\Product\Inventory" />
</type>
<type name="Magento\InventoryReservations\Model\ResourceModel\SaveMultiple">
<plugin name="kodbruket_vsbridgeindexermsireservation_plugin_resourcemodel_savemultiple" type="Kodbruket\VsbridgeIndexerMsiReservation\Plugin\ResourceModel\SaveMultiple" />
</type>
</config>