Skip to content

Commit c164dbc

Browse files
authored
Merge pull request #908 from sumitwebkul/order_status_changes
Improved: Order Status changes, Refund issues resolved and order and cancellation process improved
2 parents 321284e + d3aaf3f commit c164dbc

File tree

48 files changed

+711
-413
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+711
-413
lines changed

admin/themes/default/sass/controllers/_order.sass

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@
2727
max-height: 55px
2828
max-width: 55px
2929

30-
30+
.room_status_info_form
31+
.room_status
32+
white-space: normal

admin/themes/default/template/controllers/orders/_product_line.tpl

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
* International Registered Trademark & Property of PrestaShop SA
2424
*}
2525

26-
<tr class="product-line-row" data-id_room="{$data.id_room}" data-id_product="{$data.id_product}" data-id_hotel="{$data.id_hotel}" data-date_from="{$data.date_from}" data-date_to="{$data.date_to}" data-product_price="{$data.unit_amt_tax_incl}" data-id_order_detail="{$data.id_order_detail}">
26+
<tr class="product-line-row" data-id_htl_booking="{$data.id|escape:'html':'UTF-8'}" data-id_room="{$data.id_room}" data-id_product="{$data.id_product}" data-id_hotel="{$data.id_hotel}" data-date_from="{$data.date_from}" data-date_to="{$data.date_to}" data-product_price="{$data.unit_amt_tax_incl}" data-id_order_detail="{$data.id_order_detail}">
2727
{if $refund_allowed}
2828
<td class="standard_refund_fields" style="display:none">
29-
<input type="checkbox" name="id_htl_booking[]" value="{$data.id|escape:'html':'UTF-8'}" {if isset($refundReqBookings) && ($data.id|in_array:$refundReqBookings)}disabled{/if}/>
29+
<input type="checkbox" name="id_htl_booking[]" value="{$data.id|escape:'html':'UTF-8'}" {if (isset($refundReqBookings) && ($data.id|in_array:$refundReqBookings)) || $data.is_refunded}disabled{/if}/>
3030
</td>
3131
{/if}
3232
<td class="text-center">
@@ -261,7 +261,7 @@
261261
<li>
262262
<a href="#" data-toggle="modal" data-target="#mySwappigModal" data-id_order="{$order->id}" data-room_num='{$data.room_num}' data-date_from='{$data.date_from}' data-date_to='{$data.date_to}' data-id_room='{$data.id_room}' data-cust_name='{$data.alloted_cust_name}' data-cust_email='{$data.alloted_cust_email}' data-avail_rm_swap='{$data.avail_rooms_to_swap|@json_encode}' data-avail_rm_realloc='{$data.avail_rooms_to_realloc|@json_encode}'>
263263
<i class="icon-refresh"></i>
264-
{l s='Reallocate Room'}
264+
{l s='Reallocate/Swap Room'}
265265
</a>
266266
</li>
267267
<li>
@@ -283,4 +283,4 @@
283283
</button>
284284
</td>
285285
{/if}
286-
</tr>
286+
</tr>

admin/themes/default/template/controllers/orders/helpers/view/view.tpl

+98-85
Large diffs are not rendered by default.

classes/Cart.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,6 @@ public function getPackageList($flush = false)
23872387
$array[$selectedProduct['id_hotel']] = array(
23882388
'quantity' => $selectedProduct['quantity'],
23892389
'id_hotel' => $selectedProduct['id_hotel'],
2390-
'unit_price_tax_incl' => $selectedProduct['unit_price_tax_incl'],
23912390
'total_price_tax_excl' => $selectedProduct['total_price_tax_excl'],
23922391
'total_price_tax_incl' => $selectedProduct['total_price_tax_incl'],
23932392
);
@@ -2397,7 +2396,8 @@ public function getPackageList($flush = false)
23972396
$product['cart_quantity'] = $selectedProduct['quantity'];
23982397
$product['total'] = $selectedProduct['total_price_tax_excl'];
23992398
$product['total_wt'] = $selectedProduct['total_price_tax_incl'];
2400-
$product['price_wt'] = $selectedProduct['unit_price_tax_incl'];
2399+
$product['price_wt'] = $selectedProduct['total_price_tax_incl'] / $product['cart_quantity'];
2400+
$product['price'] = $selectedProduct['total_price_tax_excl'] / $product['cart_quantity'];
24012401
$product['id_hotel'] = $selectedProduct['id_hotel'];
24022402
$orderPackage[$id_address][$selectedProduct['id_hotel']]['product_list'][] = $product;
24032403
if (!isset($orderPackage[$id_address][$selectedProduct['id_hotel']]['id_hotel'])) {
@@ -2431,6 +2431,7 @@ public function getPackageList($flush = false)
24312431
$unitPriceWt = $objHotelServiceProductCartDetail->getHotelProductUnitPrice($this->id, $product['id_product'], $hotelProduct['id_hotel'], true);
24322432
$serviceProduct['total'] = $unitPrice * $hotelProduct['quantity'];
24332433
$serviceProduct['total_wt'] = $unitPriceWt * $hotelProduct['quantity'];
2434+
$serviceProduct['price'] = $unitPrice;
24342435
$serviceProduct['price_wt'] = $unitPriceWt;
24352436
// if (!empty($hotelProducts['products'])) {
24362437
// foreach($hotelProducts['products'] as $hotelProduct) {

classes/PaymentModule.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -1008,11 +1008,9 @@ public function validateOrder($id_cart, $id_order_state, $amount_paid, $payment_
10081008
// Set the order status
10091009
$new_history = new OrderHistory();
10101010
$new_history->id_order = (int)$order->id;
1011-
if ($order_status->logable && $order->is_advance_payment && $order->advance_paid_amount < $order->total_paid_tax_incl) {
1012-
$new_history->changeIdOrderState((int)Configuration::get('PS_OS_PARTIAL_PAYMENT_ACCEPTED'), $order, true);
1013-
} else {
1014-
$new_history->changeIdOrderState((int)$id_order_state, $order, true);
1015-
}
1011+
1012+
$new_history->changeIdOrderState((int)$id_order_state, $order, true);
1013+
10161014
$new_history->addWithemail(true, $extra_vars);
10171015

10181016
// Switch to back order if needed

classes/order/Order.php

+43-37
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class OrderCore extends ObjectModel
3434
const ORDER_PAYMENT_TYPE_FULL = 1;
3535
const ORDER_PAYMENT_TYPE_ADVANCE = 2;
3636

37+
const ORDER_COMPLETE_REFUND_FLAG = 1;
38+
const ORDER_COMPLETE_CANCELLATION_FLAG = 2;
39+
const ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG = 3;
40+
3741
/** @var int Delivery address id */
3842
public $id_address_delivery;
3943

@@ -2602,56 +2606,58 @@ public static function getAllOrdersByCartId($id_cart)
26022606
return Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'orders WHERE id_cart = '.(int)$id_cart);
26032607
}
26042608

2605-
// Order is considered as refunded if all bookings are requested for refund and all are with refunded status
2606-
// $refundFlag [ORDER_RETURN_STATE_FLAG_REFUNDED || ORDER_RETURN_STATE_FLAG_DENIED]
2607-
public function hasCompletelyRefunded($refundFlag = 0)
2609+
/**
2610+
* Function to check if order has been completely refunded
2611+
* @param integer action: can have 3 values as below
2612+
* Order::ORDER_COMPLETE_REFUND_FLAG for complete refunded and
2613+
* Order::ORDER_COMPLETE_CANCELLATION_FLAG for completely cancelled and
2614+
* Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG for all rooms are either cancelled or requested for refunded
2615+
* @return boolean: true if order has been completely refunded as per requested parameters or false
2616+
*/
2617+
public function hasCompletelyRefunded($action = 0)
26082618
{
26092619
$objHotelBooking = new HotelBookingdetail();
2610-
if ($refundBookings = OrderReturn::getOrdersReturnDetail($this->id)) {
2611-
if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
2612-
if (count($refundBookings) == count($orderBookings)) {
2613-
if ($refundFlag) {
2614-
foreach ($refundBookings as $refundRow) {
2615-
if (Validate::isLoadedObject(
2616-
$objReturnState = new OrderReturnState($refundRow['state']
2617-
))) {
2618-
if ($refundFlag == OrderReturnState::ORDER_RETURN_STATE_FLAG_REFUNDED
2619-
&& !$objReturnState->refunded
2620-
) {
2621-
return false;
2622-
}
2623-
if ($refundFlag == OrderReturnState::ORDER_RETURN_STATE_FLAG_DENIED
2624-
&& !$objReturnState->denied
2625-
) {
2626-
return false;
2627-
}
2628-
}
2620+
if ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
2621+
// If action is Order::ORDER_COMPLETE_REFUND_FLAG (for refunded) then we will check
2622+
// that all rooms must be refunded and at least one booking is not cancelled
2623+
if ($action == Order::ORDER_COMPLETE_REFUND_FLAG) {
2624+
$uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_refunded'));
2625+
if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) {
2626+
foreach ($orderBookings as $booking) {
2627+
if ($booking['is_cancelled'] == 0) {
2628+
return true;
26292629
}
26302630
}
2631+
}
2632+
// If action is Order::ORDER_COMPLETE_CANCELLATION_FLAG (for cancelled) then we will check that all rooms must be cancelled
2633+
} elseif ($action == Order::ORDER_COMPLETE_CANCELLATION_FLAG) {
2634+
$uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_cancelled'));
2635+
if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) {
26312636
return true;
26322637
}
2633-
}
2634-
} elseif ($orderBookings = $objHotelBooking->getOrderCurrentDataByOrderId($this->id)) {
2635-
if (count(array_unique(array_column($orderBookings, 'is_cancelled'))) === 1
2636-
&& array_unique(array_column($orderBookings, 'is_cancelled'))[0] != 0
2637-
) {
2638+
// If action is Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG (for cancelled and refund requests) then we will check that all rooms are either cancelled or requested for refund
2639+
} elseif ($action == Order::ORDER_COMPLETE_CANCELLATION_OR_REFUND_REQUEST_FLAG) {
2640+
foreach ($orderBookings as $booking) {
2641+
if (!$booking['is_refunded']) {
2642+
if (!OrderReturn::getOrdersReturnDetail($this->id, 0, $booking['id'])) {
2643+
return false;
2644+
}
2645+
}
2646+
}
26382647
return true;
2648+
// Default process to check if order is fully refunded or cancelled or not
2649+
} else {
2650+
// if is_refunded is 1 means booking either is cancelled or refunded. So check all bookings must have is_refunded = 1
2651+
$uniqueRefundedBookings = array_unique(array_column($orderBookings, 'is_refunded'));
2652+
if (count($uniqueRefundedBookings) == 1 && $uniqueRefundedBookings[0] == 1) {
2653+
return true;
2654+
}
26392655
}
26402656
}
26412657

26422658
return false;
26432659
}
26442660

2645-
// Order is considered as denied if all bookings are requested for refund and all are with denied status
2646-
public function orderRefundHasBeenDenied()
2647-
{
2648-
if (OrderReturn::getOrdersReturn($this->id_customer, $this->id)) {
2649-
2650-
}
2651-
2652-
return false;
2653-
}
2654-
26552661
public function getWsBookings()
26562662
{
26572663
return Db::getInstance()->executeS(

classes/order/OrderHistory.php

+25-5
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ public function changeIdOrderState($new_order_state, $id_order, $use_existing_pa
313313

314314
// set orders as paid
315315
if ($new_os->paid == 1) {
316-
$invoices = $order->getInvoicesCollection();
317316
if ($order->total_paid != 0) {
318317
// if order is created by API then create a direct object instead of creating an object from module
319318
if ($order->module == 'wsorder') {
@@ -323,22 +322,43 @@ public function changeIdOrderState($new_order_state, $id_order, $use_existing_pa
323322
}
324323
}
325324

326-
foreach ($invoices as $invoice) {
327-
/** @var OrderInvoice $invoice */
328-
$rest_paid = $invoice->getRestPaid();
325+
// if order has invoices then create payment entry for all the invoices
326+
if ($invoices = $order->getInvoicesCollection()->getResults()) {
327+
foreach ($invoices as $invoice) {
328+
/** @var OrderInvoice $invoice */
329+
$rest_paid = $invoice->getRestPaid();
330+
if ($rest_paid > 0) {
331+
if ($order->total_paid != 0) {
332+
$payment_method = $payment_method->displayName;
333+
} else {
334+
$payment_method = null;
335+
}
336+
$order->addOrderPayment(
337+
$rest_paid,
338+
$payment_method,
339+
null,
340+
null,
341+
null,
342+
$invoice
343+
);
344+
}
345+
}
346+
} else {
347+
$rest_paid = $order->total_paid_tax_incl - $order->total_paid_real;
329348
if ($rest_paid > 0) {
330349
if ($order->total_paid != 0) {
331350
$payment_method = $payment_method->displayName;
332351
} else {
333352
$payment_method = null;
334353
}
354+
335355
$order->addOrderPayment(
336356
$rest_paid,
337357
$payment_method,
338358
null,
339359
null,
340360
null,
341-
$invoice
361+
null
342362
);
343363
}
344364
}

classes/order/OrderReturn.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ public function checkEnoughProduct($order_detail_list, $product_qty_list, $custo
158158
public function hasBeenCompleted()
159159
{
160160
if (Validate::isLoadedObject($objReturnState = new OrderReturnState($this->state))) {
161-
if ($objReturnState->denied || $objReturnState->refunded) {
161+
// refund process will be considered as completed when the state is "Refunded"
162+
if ($objReturnState->refunded) {
162163
return true;
163164
}
164165
}

0 commit comments

Comments
 (0)