-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored pushing items to prewarm queue to seperate notifier class,…
… added plugin for mass update attributes call
- Loading branch information
Showing
4 changed files
with
118 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Elgentos\LargeConfigProducts\Model; | ||
|
||
use Magento\Catalog\Model\ProductFactory; | ||
use Magento\ConfigurableProduct\Model\Product\Type\Configurable; | ||
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable as ConfigurableResourceModel; | ||
use Rcason\Mq\Api\PublisherInterface; | ||
use Magento\Framework\Module\Manager as ModuleManager; | ||
|
||
class PublisherNotifier { | ||
|
||
/** | ||
* @var PublisherInterface | ||
*/ | ||
private $publisher; | ||
/** | ||
* @var ConfigurableResourceModel | ||
*/ | ||
private $configurableResourceModel; | ||
/** | ||
* @var ModuleManager | ||
*/ | ||
private $moduleManager; | ||
|
||
/** | ||
* @var ProductFactory | ||
*/ | ||
private $productFactory; | ||
|
||
/** | ||
* @param PublisherInterface $publisher | ||
* @param ConfigurableResourceModel $configurableResourceModel | ||
* @param ModuleManager $moduleManager | ||
* @param ProductFactory $productFactory | ||
*/ | ||
public function __construct( | ||
PublisherInterface $publisher, | ||
ConfigurableResourceModel $configurableResourceModel, | ||
ModuleManager $moduleManager, | ||
ProductFactory $productFactory | ||
) { | ||
$this->publisher = $publisher; | ||
$this->configurableResourceModel = $configurableResourceModel; | ||
$this->moduleManager = $moduleManager; | ||
$this->productFactory = $productFactory; | ||
} | ||
|
||
/** | ||
* @param $productIds array | ||
*/ | ||
public function notify(array $productIds) { | ||
if ($this->moduleManager->isEnabled('Rcason_Mq')) { | ||
foreach ($productIds as $productId) { | ||
$product = $this->productFactory->create()->load($productId); | ||
if ($product->getTypeId() == Configurable::TYPE_CODE) { | ||
$this->publisher->publish('lcp.product.prewarm', $productId); | ||
} elseif ($product->getTypeId() == 'simple') { | ||
$parentIds = $this->configurableResourceModel->getParentIdsByChild($productId); | ||
foreach ($parentIds as $parentId) { | ||
$this->publisher->publish('lcp.product.prewarm', $parentId); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Elgentos\LargeConfigProducts\Plugin\Product\Action; | ||
|
||
use Elgentos\LargeConfigProducts\Model\PublisherNotifier; | ||
use Magento\Catalog\Model\Product\Action as ProductAction; | ||
|
||
class AfterUpdateAttributesPlugin { | ||
|
||
/** | ||
* AfterUpdateAttributesPlugin constructor. | ||
* @param PublisherNotifier $publisherNotifier | ||
*/ | ||
public function __construct(PublisherNotifier $publisherNotifier) { | ||
$this->publisherNotifier = $publisherNotifier; | ||
} | ||
|
||
/** | ||
* @param ProductAction $subject | ||
* @param ProductAction $action | ||
* @param $productIds | ||
* @param $attrData | ||
* @param $storeId | ||
* @return ProductAction | ||
*/ | ||
public function afterUpdateAttributes( | ||
ProductAction $subject, | ||
ProductAction $action, | ||
$productIds, | ||
$attrData, | ||
$storeId | ||
) { | ||
$this->publisherNotifier->notify($productIds); | ||
|
||
return $action; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters