diff --git a/src/jobs/AlgoliaBulkLoadTask.php b/src/jobs/AlgoliaBulkLoadTask.php index abbf57f..3c0bdfe 100644 --- a/src/jobs/AlgoliaBulkLoadTask.php +++ b/src/jobs/AlgoliaBulkLoadTask.php @@ -132,7 +132,7 @@ public function execute($queue) break; - CASE 'variant': + CASE 'product': // loading too many causes a timeout and memory issue... // breaking these updates into 100 record chunks @@ -142,13 +142,13 @@ public function execute($queue) if ($commercePlugin) { // this is the total number of variants in the system - $variantCount = \craft\commerce\elements\Variant::find()->typeId($sectionId)->count(); + $productCount = \craft\commerce\elements\Product::find()->typeId($sectionId)->count(); - AlgoliaSync::$plugin->algoliaSyncService->logger("there are ".$variantCount." products to load who match sectionId: ".$sectionId, basename(__FILE__) , __LINE__); + AlgoliaSync::$plugin->algoliaSyncService->logger("there are ".$productCount." products to load who match sectionId: ".$sectionId, basename(__FILE__) , __LINE__); $queue = Craft::$app->getQueue(); - for ($x=0; $x<$variantCount; $x=$x+$this->standardLimit) { + for ($x=0; $x<$productCount; $x=$x+$this->standardLimit) { $queue->push(new AlgoliaChunkLoadTask([ 'description' => Craft::t('algolia-sync', 'Queueing a chunk of '.$elementType.' records to process start ('.$x.') limit ('.$this->standardLimit.')'), 'loadRecordType' => $this->loadRecordType, diff --git a/src/jobs/AlgoliaChunkLoadTask.php b/src/jobs/AlgoliaChunkLoadTask.php index 513fa48..939d9e9 100644 --- a/src/jobs/AlgoliaChunkLoadTask.php +++ b/src/jobs/AlgoliaChunkLoadTask.php @@ -96,28 +96,26 @@ public function execute($queue) SWITCH ($elementType) { - CASE 'variant': + CASE 'product': - AlgoliaSync::$plugin->algoliaSyncService->logger("loading a chunk of product variants (with type ID = ".$sectionId.") into the Algolia sync queue. OffsetCount=".$offsetCount.", limitCount=".$limitCount, basename(__FILE__) , __LINE__); + AlgoliaSync::$plugin->algoliaSyncService->logger("loading a chunk of products (with type ID = ".$sectionId.") into the Algolia sync queue. OffsetCount=".$offsetCount.", limitCount=".$limitCount, basename(__FILE__) , __LINE__); $commercePlugin = Craft::$app->plugins->getPlugin('commerce'); if ($commercePlugin) { - $recordCount = \craft\commerce\elements\Variant::find()->typeId($sectionId)->offset($offsetCount)->limit($limitCount)->status('enabled')->count(); - $variants = \craft\commerce\elements\Variant::find()->typeId($sectionId)->offset($offsetCount)->limit($limitCount)->status('enabled')->all(); + $recordCount = \craft\commerce\elements\Product::find()->typeId($sectionId)->offset($offsetCount)->limit($limitCount)->status('enabled')->count(); + $products = \craft\commerce\elements\Product::find()->typeId($sectionId)->offset($offsetCount)->limit($limitCount)->status('enabled')->all(); if ($recordCount > 0) { AlgoliaSync::$plugin->algoliaSyncService->logger("We found ".$recordCount." products that need to be synced in this batch to be synced", basename(__FILE__) , __LINE__); $currentLoopCount = 0; - foreach ($variants as $variant) { + foreach ($products as $product) { $progress = $currentLoopCount / $recordCount; $this->setProgress($queue, $progress); - // AlgoliaSync::$plugin->algoliaSyncService->logger(print_r($variant, true), basename(__FILE__) , __LINE__); - - AlgoliaSync::$plugin->algoliaSyncService->prepareAlgoliaSyncElement($variant); + AlgoliaSync::$plugin->algoliaSyncService->prepareAlgoliaSyncElement($product); $currentLoopCount++; } } diff --git a/src/services/AlgoliaSyncService.php b/src/services/AlgoliaSyncService.php index d44d9ff..3646299 100644 --- a/src/services/AlgoliaSyncService.php +++ b/src/services/AlgoliaSyncService.php @@ -669,7 +669,7 @@ public function prepareAlgoliaSyncElement($element, $action = 'save', $algoliaMe $variantInfo['weight'] = (float)$variantDetails->weight; $variantInfo['hasUnlimitedStock'] = (bool)$variantDetails->hasUnlimitedStock; $variantInfo['minQty'] = (int)$variantDetails->minQty; - $variantInfo['minQty'] = (int)$variantDetails->minQty; + $variantInfo['maxQty'] = (int)$variantDetails->maxQty; // nest each variant under the product info $recordUpdate['attributes']['variants'][] = $variantInfo;