Skip to content

Commit

Permalink
Merge branch '2.10.x' into 2.11.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rbayet committed Sep 16, 2024
2 parents 7c4820f + d3f8eae commit 2f54d24
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
*/
class SaveProductsPositions extends AbstractIndexerPlugin
{
/**
* @var \Magento\Framework\Message\ManagerInterface
*/
protected $messageManager;

/**
* @var \Magento\Framework\Json\Helper\Data
*/
Expand All @@ -44,17 +49,20 @@ class SaveProductsPositions extends AbstractIndexerPlugin
* @param \Smile\ElasticsuiteVirtualCategory\Model\ResourceModel\Category\Product\Position $saveHandler Product position
* save handler.
* @param \Magento\Framework\Json\Helper\Data $jsonHelper JSON Helper.
* @param \Magento\Framework\Message\ManagerInterface $messageManager Message Manager.
*/
public function __construct(
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
FullIndexer $fullIndexer,
\Smile\ElasticsuiteVirtualCategory\Model\ResourceModel\Category\Product\Position $saveHandler,
\Magento\Framework\Json\Helper\Data $jsonHelper
\Magento\Framework\Json\Helper\Data $jsonHelper,
\Magento\Framework\Message\ManagerInterface $messageManager
) {
parent::__construct($indexerRegistry, $fullIndexer);

$this->jsonHelper = $jsonHelper;
$this->saveHandler = $saveHandler;
$this->messageManager = $messageManager;
}

/**
Expand Down Expand Up @@ -145,17 +153,23 @@ private function getAffectedProductIds($category)
*
* @param \Magento\Catalog\Model\Category $category Category
*
* @return array
* @return $this
*/
private function unserializeProductPositions(\Magento\Catalog\Model\Category $category)
{
// Get product positions from the category.
$productPositions = $category->getSortedProducts() ? $category->getSortedProducts() : [];

if (is_string($productPositions)) {
try {
$productPositions = $this->jsonHelper->jsonDecode($productPositions);
} catch (\Exception $e) {
$productPositions = [];
$this->messageManager->addWarningMessage(
__('Something went wrong while saving your product positions, they have been switched back to their last known state.')
);

// Fallback to the last known valid product positions.
$productPositions = $this->saveHandler->getProductPositionsByCategory($category);
}
}

Expand Down

0 comments on commit 2f54d24

Please sign in to comment.