Merge pull request #1172 from vishal-singh-webkul/gli-2232

Fixed: Errors occurring while updating the order from back office.
This commit is contained in:
Rohit Jain
2024-08-22 20:07:37 +05:30
committed by GitHub
8 changed files with 64 additions and 49 deletions

View File

@@ -4656,8 +4656,6 @@ class AdminOrdersControllerCore extends AdminController
$res = true;
$id_order = (int) Tools::getValue('id_order');
$order = new Order($id_order);
$cart = new Cart($order->id_cart);
$customer = new Cart($order->id_customer);
//$order_detail = new OrderDetail((int)Tools::getValue('product_id_order_detail'));
$order_detail = new OrderDetail((int) Tools::getValue('id_order_detail'));//by webkul id_order_detail from our table
$this->doEditRoomValidation($order_detail, $order, isset($order_invoice) ? $order_invoice : null);
@@ -4666,6 +4664,9 @@ class AdminOrdersControllerCore extends AdminController
$order_invoice = new OrderInvoice((int) Tools::getValue('product_invoice'));
}
/*By webkul To edit Order and cart entries when edit rooms from the orderLine when editing the order*/
$obj_booking_detail = new HotelBookingDetail((int) Tools::getValue('id_booking_detail'));
$cart = new Cart($obj_booking_detail->id_cart);
$product_informations = $_POST['edit_product'];
$new_date_from = trim(date('Y-m-d', strtotime($product_informations['date_from'])));
$new_date_to = trim(date('Y-m-d', strtotime($product_informations['date_to'])));
@@ -4675,7 +4676,6 @@ class AdminOrdersControllerCore extends AdminController
$id_room = trim(Tools::getValue('id_room'));
$id_product = trim(Tools::getValue('id_product'));
$room_unit_price = trim(Tools::getValue('room_unit_price'));
$obj_booking_detail = new HotelBookingDetail();
$product_quantity = (int) $obj_booking_detail->getNumberOfDays($new_date_from, $new_date_to);
$old_product_quantity = (int) $obj_booking_detail->getNumberOfDays($old_date_from, $old_date_to);
$qty_diff = $product_quantity - $old_product_quantity;
@@ -4857,6 +4857,17 @@ class AdminOrdersControllerCore extends AdminController
$res &= $order_invoice->update();
}
if ($qty_diff != 0) {
$cartQty = $qty_diff;
$op = 'up';
if ($qty_diff < 0) {
$op = 'down';
$cartQty = -$cartQty;
}
$cart->updateQty($cartQty, $obj_booking_detail->id_product, null, false, $op, 0, null, true);
}
// Update product available quantity
StockAvailable::updateQuantity($order_detail->product_id, $order_detail->product_attribute_id, ($old_quantity - $order_detail->product_quantity), $order->id_shop);
@@ -4926,7 +4937,10 @@ class AdminOrdersControllerCore extends AdminController
$id_room,
0,
null,
null
null,
null,
0,
$obj_booking_detail->id
);
$extraDemands = $objBookingDemand->getRoomTypeBookingExtraDemands(
@@ -4934,7 +4948,11 @@ class AdminOrdersControllerCore extends AdminController
0,
$id_room,
$old_date_from,
$old_date_to
$old_date_to,
1,
0,
1,
$obj_booking_detail->id
);
// set occupancy details
@@ -4950,7 +4968,7 @@ class AdminOrdersControllerCore extends AdminController
'tax_incl' => $totalRoomPriceAfterTI,
);
if ($update_htl_tables = $obj_booking_detail->UpdateHotelCartHotelOrderOnOrderEdit(
if ($obj_booking_detail->updateHotelCartHotelOrderOnOrderEdit(
$id_order,
$id_room,
$old_date_from,
@@ -4958,7 +4976,8 @@ class AdminOrdersControllerCore extends AdminController
$new_date_from,
$new_date_to,
$occupancy,
$new_total_price
$new_total_price,
$obj_booking_detail->id
)) {
// update extra demands total prices if dates are changes (price calc method for each day)
if ($extraDemands) {
@@ -5495,6 +5514,10 @@ class AdminOrdersControllerCore extends AdminController
// delete refund request of the room if exists.
OrderReturnDetail::deleteReturnDetailByIdBookingDetail($id_order, $idHotelBooking);
// Reducing the quantity from the cart after removing the room from the order
$objCart = new Cart($objBookingDetail->id_cart);
$objCart->updateQty($product_quantity, $objBookingDetail->id_product, null, false, 'down', 0, null, true);
// Assign to smarty informations in order to show the new product line
$this->context->smarty->assign(array(
'order' => $order,
@@ -6238,7 +6261,7 @@ class AdminOrdersControllerCore extends AdminController
$oldTotalPriceTaxExcl = $objRoomTypeServiceProductOrderDetail->total_price_tax_excl;
$oldTotalPriceTaxIncl = $objRoomTypeServiceProductOrderDetail->total_price_tax_incl;
$oldQuantity = $objRoomTypeServiceProductOrderDetail->quantity;
if ($oldPriceTaxExcl > 0) {
if ($oldUnitPriceTaxExcl > 0) {
$oldTaxMultiplier = $oldUnitPriceTaxIncl / $oldUnitPriceTaxExcl;
} else {
$oldTaxMultiplier = 1;
@@ -6424,10 +6447,10 @@ class AdminOrdersControllerCore extends AdminController
);
// add services in room
$order = new Order($objHotelBookingDetail->id_order);
if (!$response['hasError']) {
$this->context->currency = new Currency($order->id_currency);
foreach ($selectedServices as $service) {
$order = new Order($objHotelBookingDetail->id_order);
// Create new cart
$cart = new Cart();
$cart->id_shop_group = $order->id_shop_group;
@@ -6499,49 +6522,33 @@ class AdminOrdersControllerCore extends AdminController
$roomHtlCartInfo['id'])
) {
$objRoomTypeServiceProductCartDetail = new RoomTypeServiceProductCartDetail((int) $id_room_type_service_product_cart_detail);
$totalPriceChangeTaxExcl += $totalPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
$objRoomTypeServiceProductCartDetail->quantity,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
false,
$cart->id
);
$totalPriceChangeTaxIncl += $totalPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
$objRoomTypeServiceProductCartDetail->quantity,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
true,
$cart->id
);
$numDays = 1;
if (Product::getProductPriceCalculation($product['id_product']) == Product::PRICE_CALCULATION_METHOD_PER_DAY) {
$numDays = HotelHelper::getNumberOfDays($objHotelBookingDetail->date_from, $objHotelBookingDetail->date_to);
}
$product['cart_quantity'] = $objRoomTypeServiceProductCartDetail->quantity * $numDays;
$product['cart_quantity'] = $objRoomTypeServiceProductCartDetail->quantity * $numDays;
$unitPriceTaxExcl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
$roomHtlCartInfo['id_product'],
1,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
null,
null,
false,
$cart->id
)/ $numDays;
);
$unitPriceTaxIncl = $objRoomTypeServiceProductPrice->getServicePrice(
(int)$product['id_product'],
0,
$roomHtlCartInfo['id_product'],
1,
$objHotelBookingDetail->date_from,
$objHotelBookingDetail->date_to,
null,
null,
true,
$cart->id
)/ $numDays;
);
$totalPriceChangeTaxExcl += $totalPriceTaxExcl = ($unitPriceTaxExcl * $product['cart_quantity']);
$totalPriceChangeTaxIncl += $totalPriceTaxIncl = ($unitPriceTaxIncl * $product['cart_quantity']);
switch (Configuration::get('PS_ROUND_TYPE')) {
case Order::ROUND_TOTAL:
$product['total'] = $totalPriceTaxExcl;