Skip to content

Commit

Permalink
adding attributes for the default variant sale status, including the …
Browse files Browse the repository at this point in the history
…onSale boolean and the salePrice float
  • Loading branch information
markmiddleton committed Feb 19, 2024
1 parent 0937e94 commit fda291e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/services/AlgoliaSyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,17 @@ public function prepareAlgoliaSyncElement($element, $action = 'save', $algoliaMe

case 'product':

$defaultVariant = $element->defaultVariant;

if ($defaultVariant->onSale) {
$salePrice = (float)$defaultVariant->salePrice;
$onSale = true;
}
else {
$salePrice = null;
$onSale = false;
}

AlgoliaSync::$plugin->algoliaSyncService->logger("Product is being loaded", basename(__FILE__) , __LINE__);

// get the basic product info
Expand All @@ -643,6 +654,8 @@ public function prepareAlgoliaSyncElement($element, $action = 'save', $algoliaMe
$recordUpdate['attributes']['availableForPurchase'] = (bool)$element->availableForPurchase;
$recordUpdate['attributes']['defaultVariantId'] = (int)$element->defaultVariantId;
$recordUpdate['attributes']['defaultPrice'] = (float)$element->defaultPrice;
$recordUpdate['attributes']['onSale'] = $onSale;
$recordUpdate['attributes']['salePrice'] = $salePrice;
$recordUpdate['attributes']['defaultWidth'] = $element->defaultWidth;
$recordUpdate['attributes']['defaultHeight'] = $element->defaultHeight;
$recordUpdate['attributes']['defaultLength'] = $element->defaultLength;
Expand Down

0 comments on commit fda291e

Please sign in to comment.