Skip to content

Commit

Permalink
inserting the product id into the attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
markmiddleton committed Nov 15, 2023
1 parent 02d7831 commit 575bcb0
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/services/AlgoliaSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,14 +529,13 @@ public function prepareAlgoliaSyncElement($element, $action = 'save', $algoliaMe
AlgoliaSync::$plugin->algoliaSyncService->logger("Variant is being loaded", basename(__FILE__) , __LINE__);

$thisVariantQuery = \craft\commerce\elements\Variant::find()->id($element->id);
// pulling the product allows us to get the product id to add to the variant info
$myProduct = craft\commerce\elements\Product::find()->hasVariant($thisVariantQuery)->one();

// lets get the product id and the sale price of the product...

$recordUpdate['productId'] = $myProduct->id;
$recordUpdate['elementType'] = ucwords($elementTypeSlug);
$recordUpdate['handle'] = $elementInfo['sectionHandle'];
$recordUpdate['attributes']['title'] = $element->title;
$recordUpdate['attributes']['productId'] = $myProduct->id;
if (!empty($element->SKU)) {
$recordUpdate['attributes']['SKU'] = $element->sku;
}
Expand All @@ -556,10 +555,9 @@ public function prepareAlgoliaSyncElement($element, $action = 'save', $algoliaMe
$recordUpdate['attributes']['minQty'] = (float)$element->minQty;
$recordUpdate['attributes']['maxQty'] = (float)$element->maxQty;


break;

}
}

// Fire event for tracking before the sync event.
$event = new beforeAlgoliaSyncEvent([
Expand Down

0 comments on commit 575bcb0

Please sign in to comment.