Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Update product position on category save.
Browse files Browse the repository at this point in the history
Multiple request on product save in backend - fix.
Fix getting value for stock_status.
  • Loading branch information
Agata Firlejczyk committed Jun 4, 2019
1 parent b538369 commit 13fddef
Show file tree
Hide file tree
Showing 20 changed files with 574 additions and 19 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ There is not need really, VSF only has to know if `product_count > 0`, so if you
category will be visible in menu sidebar.
- Add support for reviews. Reviews are exported without ratings (VSF does not support ratings for now)
- Add support for custom options.
- Add option to enable/disable exporting data to ES.
- Add option to enable/disable exporting data to ES.
- Add ProductCategory indexer to partially update product data in ES (category, category_ids fields). Trigger after changing products positions in category.
- Fix getting stock_status value for products
- Remove dependency from catalog_product_price and cataloginventory_stock indexer. On product save multiple request has been send

## [1.0.0] (2019.04.03)
First version
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ Module was not tested on version 2.3.
### TODO
- check the Vue Storefront - Magento 2 Indexer bridge for Magento 2.3 (for Commerce and Enterprise versions).
- add MSI support
- add rating review to ElasticSearch as a separate module @Agata
- add a limitation of the attributes (products, categories) sent to ElasticSearch
- add a limitation of the categories sent to ElasticSearch, by adding new configurations: send only categories visible in the menu, send only active categories @Agata
- add a new command enabling the full indexation, which will run all the indexes necessary for VSF
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @package Divante\VsbridgeIndexerCatalog
* @author Agata Firlejczyk <afirlejczyk@divante.pl>
* @copyright 2019 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/

namespace Divante\VsbridgeIndexerCatalog\Console\Command;

use Divante\VsbridgeIndexerCatalog\Model\Indexer\ProductCategoryProcessor;
use Symfony\Component\Console\Input\InputInterface;

/**
* Class IndexerReindexCommand
*/
class IndexerReindexCommand extends \Magento\Indexer\Console\Command\IndexerReindexCommand
{
/**
* @inheritdoc
*/
protected function getIndexers(InputInterface $input)

This comment has been minimized.

Copy link
@igloominusx

igloominusx Feb 4, 2020

This feature/fix is completely disabling the ability to reindex 'vsbridge_product_category' via CLI.
It gets called before any index gets run, and removes 'vsbridge_product_category' from the queue.

I am not aware of what issue this fixes, but in my current project the index is invalid, and it seems impossible to reindex by normal means.

This comment has been minimized.

Copy link
@afirlejczyk

afirlejczyk Feb 4, 2020

Contributor

Please take a look into this: #184
This indexer should be hidden in magento panel.

Status in magento panel is missleading but it not necessary to run. On Category save - if you change products assign to category only partial update will be done in ES. (instead of reindexing all products data)

It was done on purpose, because this partial re indexing is mean to run only for "Save mode".

I don't have time right now to fix issue #184.

This comment has been minimized.

Copy link
@igloominusx

igloominusx Feb 4, 2020

Thank you, I appreciate the quick and detailed response!
It is good to know that despite the 'Invalid' warning that the data is correct.
Due to the indexer problems here, I can't help wondering if it wouldn't make sense to move the functionality from the indexers and use category save events instead.

{
$indexers = parent::getIndexers($input);
unset($indexers[ProductCategoryProcessor::INDEXER_ID]);

return $indexers;
}
}
6 changes: 3 additions & 3 deletions src/module-vsbridge-indexer-catalog/Model/Indexer/Product.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php
/**
* @package magento-2-1.dev
* @author Agata Firlejczyk <afirlejczyk@divante.pl>
* @package Divante\VsbridgeIndexerCatalog
* @author Agata Firlejczyk <afirlejczyk@divante.pl>
* @copyright 2019 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
* @license See LICENSE_DIVANTE.txt for license details.
*/

namespace Divante\VsbridgeIndexerCatalog\Model\Indexer;
Expand Down
115 changes: 115 additions & 0 deletions src/module-vsbridge-indexer-catalog/Model/Indexer/ProductCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php
/**
* @package Divante\VsbridgeIndexerCatalog
* @author Agata Firlejczyk <afirlejczyk@divante.pl>
* @copyright 2019 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/

namespace Divante\VsbridgeIndexerCatalog\Model\Indexer;

use Divante\VsbridgeIndexerCatalog\Model\Indexer\Action\Product as ProductAction;
use Divante\VsbridgeIndexerCore\Indexer\GenericIndexerHandler;
use Divante\VsbridgeIndexerCore\Indexer\StoreManager;
use Divante\VsbridgeIndexerCore\Cache\Processor as CacheProcessor;

/**
* Class ProductCategory
*/
class ProductCategory implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
{
/**
* @var GenericIndexerHandler
*/
private $indexHandler;

/**
* @var ProductAction
*/
private $productAction;

/**
* @var StoreManager
*/
private $storeManager;

/**
* @var CacheProcessor
*/
private $cacheProcessor;

/**
* Category constructor.
*
* @param CacheProcessor $cacheProcessor
* @param GenericIndexerHandler $indexerHandler
* @param StoreManager $storeManager
* @param ProductAction $action
*/
public function __construct(
CacheProcessor $cacheProcessor,
GenericIndexerHandler $indexerHandler,
StoreManager $storeManager,
ProductAction $action
) {
$this->productAction = $action;
$this->storeManager = $storeManager;
$this->indexHandler = $indexerHandler;
$this->cacheProcessor = $cacheProcessor;
}

/**
* @inheritdoc
*/
public function execute($ids)
{
$stores = $this->storeManager->getStores();

foreach ($stores as $store) {
$this->rebuild($store, $ids);
}
}

/**
* @inheritdoc
*/
public function executeFull()
{
$stores = $this->storeManager->getStores();

foreach ($stores as $store) {
$this->rebuild($store);
}
}

/**
* @param \Magento\Store\Api\Data\StoreInterface $store
* @param array $productIds
*
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
private function rebuild($store, array $productIds = [])
{
$this->indexHandler->updateIndex(
$this->productAction->rebuild($store->getId(), $productIds),
$store,
['category_data']
);
}

/**
* @inheritdoc
*/
public function executeList(array $ids)
{
$this->execute($ids);
}

/**
* @inheritdoc
*/
public function executeRow($id)
{
$this->execute([$id]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* @package Divante\VsbridgeIndexerCatalog
* @author Agata Firlejczyk <afirlejczyk@divante.pl>
* @copyright 2019 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/

namespace Divante\VsbridgeIndexerCatalog\Model\Indexer;

/**
* Class ProductCategoryProcessor
*/
class ProductCategoryProcessor extends \Magento\Framework\Indexer\AbstractProcessor
{
/**
* Indexer ID
*/
const INDEXER_ID = 'vsbridge_product_category';

/**
* Mark Vsbridge Product indexer as invalid
*
* @return void
*/
public function markIndexerAsInvalid()
{
$this->getIndexer()->invalidate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@

use Magento\Framework\App\ResourceConnection;
use Magento\Store\Model\StoreManagerInterface;
use Magento\CatalogInventory\Api\StockConfigurationInterface;

/**
* Class Inventory
*/
class Inventory
{
/**
* @var StockConfigurationInterface
*/
private $stockConfiguration;

/**
* @var array
Expand Down Expand Up @@ -59,15 +64,18 @@ class Inventory
/**
* Inventory constructor.
*
* @param StockConfigurationInterface $stockConfiguration
* @param StoreManagerInterface $storeManager
* @param ResourceConnection $resourceModel
*/
public function __construct(
StockConfigurationInterface $stockConfiguration,
StoreManagerInterface $storeManager,
ResourceConnection $resourceModel
) {
$this->resource = $resourceModel;
$this->storeManager = $storeManager;
$this->stockConfiguration = $stockConfiguration;
}

/**
Expand Down Expand Up @@ -107,10 +115,11 @@ public function loadChildrenData($storeId, array $productIds)
* @param array $fields
*
* @return array
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
private function getInventoryData($storeId, array $productIds, array $fields)
{
$websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
$websiteId = $this->getWebsiteId();
$connection = $this->resource->getConnection();

$select = $connection->select()
Expand All @@ -136,4 +145,18 @@ private function getInventoryData($storeId, array $productIds, array $fields)

return $connection->fetchAssoc($select);
}

/**
* @param int|null $websiteId
*
* @return int|null
*/
private function getWebsiteId($websiteId = null)
{
if (null === $websiteId) {
$websiteId = $this->stockConfiguration->getDefaultScopeId();
}

return (int)$websiteId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ private function joinPositionAttribute(Select $select)
{
$alias = 'link_position';
$attributePosition = $this->fetchPositionAttributeData();

if (empty($attributePosition)) {
return $select;
}

$table = $this->resource->getTableName($this->getAttributeTypeTable($attributePosition['type']));

$joinCondition = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;

/**
* Class UpdateAttributeData
* Class UpdateAttributeDataPlugin
*/
class UpdateAttributeData
class UpdateAttributeDataPlugin
{
/**
* @var AttributeProcessor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* @package Divante\VsbridgeIndexerCatalog
* @author Agata Firlejczyk <afirlejczyk@divante.pl>
* @copyright 2019 Divante Sp. z o.o.
* @license See LICENSE_DIVANTE.txt for license details.
*/

namespace Divante\VsbridgeIndexerCatalog\Plugin\Indexer\CatalogInventory;

/**
* Class ProductsForReindex
*/
class ProductsForReindex
{
/**
* @var array
*/
private $productsForReindex = [];

/**
* @param array $items
* @return void
*/
public function setProducts(array $items)
{
$this->productsForReindex = $items;
}

/**
* @return array
*/
public function getProducts()
{
return $this->productsForReindex;
}

/**
* @return void
*/
public function clear()
{
$this->productsForReindex = [];
}
}
Loading

0 comments on commit 13fddef

Please sign in to comment.