Fix product price typecasting and improve product parsing in productsRoute
- Corrected typecasting for product prices to ensure consistent integer values. - Enhanced product parsing logic for better modularity and data handling in `productsRoute`.
This commit is contained in:
@@ -270,7 +270,7 @@ class products_o extends db
|
||||
$discount_percentage = $customer->getProductDiscountPercentage($product['id']);
|
||||
// Apply the discount to the product price
|
||||
if ($discount_percentage > 0) {
|
||||
$product['price'] = round($product['price'] * (1 - ($discount_percentage / 100)));
|
||||
$product['price'] = (int)(round($product['price'] * (1 - ($discount_percentage / 100))));
|
||||
}
|
||||
return $product;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ class productsRoute
|
||||
// Update the option with the new product
|
||||
$options[$key]['product'] = $product;
|
||||
// Set the price of the option to the price of the product
|
||||
$options[$key]['price'] = $product['price'];
|
||||
$options[$key]['price'] = (int)$product['price'];
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
@@ -187,7 +187,7 @@ class productsRoute
|
||||
// Get all products
|
||||
$products = (array)(new products_o())->listObjectsWithPaginationIfSet(
|
||||
function ($product) {
|
||||
return $product;
|
||||
return parseProduct($product);
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -200,7 +200,7 @@ class productsRoute
|
||||
$result = array_map(function ($product) use ($customer, $departmentId) {
|
||||
$productArray = parseProduct($product);
|
||||
// Get the price of the product with the department pricing and customer discounts applied
|
||||
$productArray = self::parseProductsPrice([$productArray], $customer, $departmentId)[0];
|
||||
$productArray = parseProduct(self::parseProductsPrice([$productArray], $customer, $departmentId)[0]);
|
||||
// Get the options for the product
|
||||
$productArray['addons'] = self::parseOptionsPrice($productArray['addons'], $customer, $departmentId);
|
||||
// Return the product with the updated price
|
||||
|
||||
Reference in New Issue
Block a user