diff --git a/src/elements/CommerceProduct.php b/src/elements/CommerceProduct.php index dd58176c..39843487 100644 --- a/src/elements/CommerceProduct.php +++ b/src/elements/CommerceProduct.php @@ -13,6 +13,8 @@ use craft\commerce\models\inventory\UpdateInventoryLevel; use craft\commerce\models\InventoryLevel; use craft\commerce\Plugin as Commerce; +use craft\commerce\Plugin as CommercePlugin; +use craft\commerce\services\CatalogPricing; use craft\db\Query; use craft\feedme\base\Element; use craft\feedme\events\FeedProcessEvent; @@ -52,6 +54,11 @@ class CommerceProduct extends Element */ public static string $class = ProductElement::class; + /** + * @var bool + */ + private bool $_runCatalogPricingJob = false; + // Templates // ========================================================================= @@ -126,6 +133,17 @@ public function init(): void $this->_inventoryUpdate($event); } }); + + if (defined(CatalogPricing::class . '::EVENT_BEFORE_CREATE_CATALOG_PRICING_JOB')) { + Event::on(CatalogPricing::class, CatalogPricing::EVENT_BEFORE_CREATE_CATALOG_PRICING_JOB, function($event) { + $event->isValid = $this->_runCatalogPricingJob; + }); + } + + Event::on(Process::class, Process::EVENT_AFTER_PROCESS_FEED, function(FeedProcessEvent $event) { + $this->_runCatalogPricingJob = true; + CommercePlugin::getInstance()->getCatalogPricing()->createCatalogPricingJob(); + }); } /**