Skip to content

Commit

Permalink
adding saleprice and product id to the commerce product data
Browse files Browse the repository at this point in the history
  • Loading branch information
markmiddleton committed Nov 15, 2023
1 parent 0f3dc6e commit 02d7831
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/services/AlgoliaSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function algoliaElementSynced($element)
$thisVariantQuery = \craft\commerce\elements\Variant::find()->id($element->id);
$myProduct = craft\commerce\elements\Product::find()->hasVariant($thisVariantQuery)->one();

AlgoliaSync::$plugin->algoliaSyncService->logger("Product Title: ".$myProduct->title, basename(__FILE__) , __LINE__);
AlgoliaSync::$plugin->algoliaSyncService->logger("Product Title: ".$myProduct->title.", Product ID: ".$myProduct->id, basename(__FILE__) , __LINE__);

if (
isset($algoliaSettings['algoliaElements'][$elementInfo['type']][$elementInfo['sectionId'][0]]['sync'])
Expand Down Expand Up @@ -527,8 +527,13 @@ public function prepareAlgoliaSyncElement($element, $action = 'save', $algoliaMe
case 'variant':

AlgoliaSync::$plugin->algoliaSyncService->logger("Variant is being loaded", basename(__FILE__) , __LINE__);
// AlgoliaSync::$plugin->algoliaSyncService->logger(print_r($element,true), basename(__FILE__) , __LINE__);

$thisVariantQuery = \craft\commerce\elements\Variant::find()->id($element->id);
$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;
Expand All @@ -540,6 +545,7 @@ public function prepareAlgoliaSyncElement($element, $action = 'save', $algoliaMe
}
$recordUpdate['attributes']['isDefault'] = (bool)$element->isDefault;
$recordUpdate['attributes']['price'] = (float)$element->price;
$recordUpdate['attributes']['salePrice'] = (float)$element->salePrice;
$recordUpdate['attributes']['sortOrder'] = $element->sortOrder;
$recordUpdate['attributes']['width'] = $element->width;
$recordUpdate['attributes']['height'] = $element->height;
Expand Down

0 comments on commit 02d7831

Please sign in to comment.