From ad4a83abcca0ffeb62cf5e3ad04d1e3dfac053d5 Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Tue, 12 Nov 2024 16:44:20 +0800 Subject: [PATCH 1/2] WIP --- src/elements/CommerceProduct.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/elements/CommerceProduct.php b/src/elements/CommerceProduct.php index dd58176c..32449696 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(); + }); } /** From 1d80fc7b3b44688faa8f3fcf92ea618a2eef1edf Mon Sep 17 00:00:00 2001 From: Luke Holder Date: Wed, 13 Nov 2024 13:23:03 +0800 Subject: [PATCH 2/2] Cleanup --- src/elements/CommerceProduct.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elements/CommerceProduct.php b/src/elements/CommerceProduct.php index 32449696..39843487 100644 --- a/src/elements/CommerceProduct.php +++ b/src/elements/CommerceProduct.php @@ -134,8 +134,8 @@ public function init(): void } }); - if(defined(CatalogPricing::class.'::EVENT_BEFORE_CREATE_CATALOG_PRICING_JOB')){ - Event::on(CatalogPricing::class, CatalogPricing::EVENT_BEFORE_CREATE_CATALOG_PRICING_JOB, function( $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; }); }