Refactor productsRoute response generation logic to support single-product retrieval and optimize price parsing.
This commit is contained in:
@@ -175,13 +175,17 @@ class productsRoute
|
||||
// return parseProduct($product);
|
||||
// }, self::parseProductsPrice($products, $customer, $departmentId))
|
||||
//);
|
||||
$response->success(array_map(function ($product) use ($customer, $departmentId) {
|
||||
$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];
|
||||
// Get the options for the product
|
||||
$productArray['addons'] = self::parseOptionsPrice($productArray['addons'], $customer, $departmentId);
|
||||
// Return the product with the updated price
|
||||
return $productArray;
|
||||
}, $products));
|
||||
}, $products);
|
||||
// If the productId is set, return a single object instead of an array
|
||||
$response->success($productId && count($result) > 0 ? $result[0] : $result);
|
||||
}
|
||||
// Check if the id is set in the request (to get a specific product)
|
||||
if (self::isParametersSet(['id'])) {
|
||||
|
||||
Reference in New Issue
Block a user