Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new Commerce events to disable pricing catalog generation until the import is complete #1544

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/elements/CommerceProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,6 +54,11 @@ class CommerceProduct extends Element
*/
public static string $class = ProductElement::class;

/**
* @var bool
*/
private bool $_runCatalogPricingJob = false;

// Templates
// =========================================================================

Expand Down Expand Up @@ -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();
});
}

/**
Expand Down
Loading