Refactor service product pricing to use getServiceProductPrice()
This commit is contained in:
@@ -4245,21 +4245,23 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$objServiceProductOption = new ServiceProductOption();
|
||||
foreach ($products as $key => &$product) {
|
||||
$idHotelAddress = Cart::getIdAddressForTaxCalculation($product['id_product'], $idHotel);
|
||||
$product['price_tax_incl'] = RoomTypeServiceProductPrice::getPrice($product['id_product'], $idHotel, null, true);
|
||||
$product['price_tax_excl'] = RoomTypeServiceProductPrice::getPrice($product['id_product'], $idHotel, null, false);
|
||||
$product['price_tax_incl'] = Product::getServiceProductPrice($product['id_product'], null, $idHotel, false, true);
|
||||
$product['price_tax_excl'] = Product::getServiceProductPrice($product['id_product'], null, $idHotel, false, false);
|
||||
|
||||
// if product has options then set the price of the first selected option of the product
|
||||
if ($product['options'] = $objServiceProductOption->getProductOptions($product['id_product'])) {
|
||||
$product['price_tax_incl'] = RoomTypeServiceProductPrice::getPrice(
|
||||
$product['price_tax_incl'] = Product::getServiceProductPrice(
|
||||
$product['id_product'],
|
||||
$idHotel,
|
||||
$product['options'][0]['id_product_option'],
|
||||
$idHotel,
|
||||
false,
|
||||
true
|
||||
);
|
||||
$product['price_tax_excl'] = RoomTypeServiceProductPrice::getPrice(
|
||||
$product['price_tax_excl'] = Product::getServiceProductPrice(
|
||||
$product['id_product'],
|
||||
$idHotel,
|
||||
$product['options'][0]['id_product_option'],
|
||||
$idHotel,
|
||||
false,
|
||||
false
|
||||
);
|
||||
}
|
||||
@@ -4394,8 +4396,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$currency = new Currency((int)$order->id_currency);
|
||||
if ($idHotel = $addressTax->id_hotel) {
|
||||
if ($id_product_option = $addProduct['product_option']) {
|
||||
$price_tax_incl = RoomTypeServiceProductPrice::getPrice($addProduct['product_id'], $idHotel, $id_product_option, true);
|
||||
$price_tax_excl = RoomTypeServiceProductPrice::getPrice($addProduct['product_id'], $idHotel, $id_product_option, false);
|
||||
$price_tax_incl = Product::getServiceProductPrice($addProduct['product_id'], $id_product_option, $idHotel, false, true);
|
||||
$price_tax_excl = Product::getServiceProductPrice($addProduct['product_id'], $id_product_option, $idHotel, false, false);
|
||||
|
||||
// convert price to order currency
|
||||
$price_tax_excl = Tools::ps_round(Tools::convertPrice($price_tax_excl, $currency), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
@@ -4409,8 +4411,8 @@ class AdminOrdersControllerCore extends AdminController
|
||||
}
|
||||
} else {
|
||||
if ($id_product_option = $addProduct['product_option']) {
|
||||
$price_tax_incl = RoomTypeServiceProductPrice::getPrice($addProduct['product_id'], false, $id_product_option, true);
|
||||
$price_tax_excl = RoomTypeServiceProductPrice::getPrice($addProduct['product_id'], false, $id_product_option, false);
|
||||
$price_tax_incl = Product::getServiceProductPrice($addProduct['product_id'], $id_product_option, false, false, true);
|
||||
$price_tax_excl = Product::getServiceProductPrice($addProduct['product_id'], $id_product_option, false, false, false);
|
||||
|
||||
// convert price to order currency
|
||||
$price_tax_excl = Tools::ps_round(Tools::convertPrice($price_tax_excl, $currency), _PS_PRICE_COMPUTE_PRECISION_);
|
||||
|
||||
@@ -951,10 +951,11 @@ class ProductControllerCore extends FrontController
|
||||
if ($idProductOption == null) {
|
||||
$idProductOption = $serviceProductOption['id_product_option'];
|
||||
}
|
||||
$serviceProductOption['price'] = RoomTypeServiceProductPrice::getPrice(
|
||||
$serviceProductOption['price'] = Product::getServiceProductPrice(
|
||||
$this->product->id,
|
||||
$idHotel,
|
||||
$serviceProductOption['id_product_option'],
|
||||
$idHotel,
|
||||
false,
|
||||
$useTax,
|
||||
1
|
||||
);
|
||||
@@ -962,19 +963,25 @@ class ProductControllerCore extends FrontController
|
||||
|
||||
}
|
||||
$smartyVars['product_option'] = $serviceProductOptions;
|
||||
$smartyVars['service_price'] = RoomTypeServiceProductPrice::getPrice(
|
||||
$smartyVars['service_price'] = Product::getServiceProductPrice(
|
||||
$this->product->id,
|
||||
$idHotel,
|
||||
$idProductOption,
|
||||
$idHotel,
|
||||
false,
|
||||
$useTax,
|
||||
$quantity
|
||||
);
|
||||
$smartyVars['service_price_without_reduction'] = RoomTypeServiceProductPrice::getPrice(
|
||||
$smartyVars['service_price_without_reduction'] = Product::getServiceProductPrice(
|
||||
$this->product->id,
|
||||
$idHotel,
|
||||
$idProductOption,
|
||||
$idHotel,
|
||||
false,
|
||||
$useTax,
|
||||
$quantity,
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
false
|
||||
);
|
||||
if ($quantity) {
|
||||
|
||||
@@ -326,10 +326,11 @@ class Blockcart extends Module
|
||||
$canSellStandalone = Product::isSellableAsStandalone($objProduct->id);
|
||||
|
||||
if ($canSellWithHotel && !empty($addedProduct['id_hotel'])) {
|
||||
$addedProduct['unit_price'] = RoomTypeServiceProductPrice::getPrice(
|
||||
$addedProduct['unit_price'] = Product::getServiceProductPrice(
|
||||
$objProduct->id,
|
||||
$addedProduct['id_hotel'],
|
||||
isset($addedProduct['id_product_option']) ? $addedProduct['id_product_option'] : null,
|
||||
$addedProduct['id_hotel'],
|
||||
false,
|
||||
$useTax,
|
||||
$addedProduct['qty']
|
||||
);
|
||||
@@ -343,10 +344,11 @@ class Blockcart extends Module
|
||||
$addedProduct['option_name'] = $productOption->name;
|
||||
}
|
||||
} elseif ($canSellStandalone) {
|
||||
$addedProduct['unit_price'] = RoomTypeServiceProductPrice::getPrice(
|
||||
$addedProduct['unit_price'] = Product::getServiceProductPrice(
|
||||
$objProduct->id,
|
||||
0,
|
||||
isset($addedProduct['id_product_option']) ? $addedProduct['id_product_option'] : null,
|
||||
0,
|
||||
false,
|
||||
$useTax,
|
||||
$addedProduct['qty']
|
||||
);
|
||||
|
||||
@@ -120,31 +120,5 @@ class RoomTypeServiceProductPrice extends ObjectModel
|
||||
);
|
||||
}
|
||||
|
||||
public static function getPrice(
|
||||
$idProduct,
|
||||
$idHotel,
|
||||
$idProductOption = null,
|
||||
$useTax = null,
|
||||
$quantity = 1,
|
||||
$useReduc = true
|
||||
) {
|
||||
$idHotelAddress = Cart::getIdAddressForTaxCalculation($idProduct, $idHotel);
|
||||
$price = Product::getPriceStatic(
|
||||
$idProduct,
|
||||
$useTax,
|
||||
$idProductOption,
|
||||
6,
|
||||
null,
|
||||
false,
|
||||
$useReduc,
|
||||
$quantity,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
$idHotelAddress
|
||||
);
|
||||
|
||||
return $price * (int)$quantity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user