diff --git a/config/smarty.config.inc.php b/config/smarty.config.inc.php
index 286403d39..6afcb59dd 100644
--- a/config/smarty.config.inc.php
+++ b/config/smarty.config.inc.php
@@ -31,7 +31,7 @@
global $smarty;
if (Configuration::get('PS_SMARTY_LOCAL')) {
$smarty = new SmartyCustom();
-} elseif (_PS_MODE_DEV_) {
+} elseif (_PS_MODE_DEV_ && !defined('_PS_ADMIN_DIR_')) {
$smarty = new SmartyDev();
} else {
$smarty = new Smarty();
diff --git a/controllers/front/CartController.php b/controllers/front/CartController.php
index 4ee5f81cd..03daed365 100644
--- a/controllers/front/CartController.php
+++ b/controllers/front/CartController.php
@@ -270,64 +270,7 @@ protected function processChangeProductInCart()
$id_cart = $this->context->cart->id;
$id_guest = $this->context->cart->id_guest;
- // By Webkul : This code is to check available quantity of Room before adding it to cart.
- if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) {
- require_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php';
- $objRoomType = new HotelRoomType();
- if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($this->id_product)) {
- if ($id_hotel = $roomTypeInfo['id_hotel']) {
- if (strtotime($date_from) < strtotime(date('Y-m-d'))) {
- $this->errors[] = Tools::displayError('You can\'t book room before current date');
- } elseif (strtotime($date_from) >= strtotime($date_to)) {
- $this->errors[] = Tools::displayError('Check-out date must be after check-in date');
- } elseif ($maxOrdDate = HotelOrderRestrictDate::getMaxOrderDate($id_hotel)) {
- // Check Order restrict condition before adding in to cart
- if (strtotime('-1 day', strtotime($maxOrdDate)) < strtotime($date_from)
- || strtotime($maxOrdDate) < strtotime($date_to)
- ) {
- $maxOrdDate = date('d-m-Y', strtotime($maxOrdDate));
- $this->errors[] = Tools::displayError('You can\'t book room after date '.$maxOrdDate);
- }
- }
- if (!$this->errors) {
- $objBookingDtl = new HotelBookingDetail();
- $num_days = $objBookingDtl->getNumberOfDays($date_from, $date_to);
- $req_rm = $this->qty;
- $this->qty = $this->qty * (int) $num_days;
- $obj_booking_dtl = new HotelBookingDetail();
- if ($hotel_room_data = $obj_booking_dtl->DataForFrontSearch(
- $date_from,
- $date_to,
- $id_hotel,
- $this->id_product,
- 1,
- 0,
- 0,
- -1,
- 0,
- 0,
- $id_cart,
- $id_guest
- )) {
- if (isset($hotel_room_data['stats']['num_avail'])) {
- $total_available_rooms = $hotel_room_data['stats']['num_avail'];
- if ($total_available_rooms < $req_rm) {
- die(json_encode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms)));
- }
- } else {
- $this->errors[] = Tools::displayError('Rooms are unavailable. Please try with different dates');
- }
- } else {
- $this->errors[] = Tools::displayError('Rooms are unavailable. Please try with different dates');
- }
- }
- } else {
- die(json_encode(array('status' => 'failed3')));
- }
- } else {
- die(json_encode(array('status' => 'failed4')));
- }
- }
+
if ($this->qty == 0) {
$this->errors[] = Tools::displayError('Null quantity.', !Tools::getValue('ajax'));
@@ -344,6 +287,68 @@ protected function processChangeProductInCart()
$qty_to_check = $this->qty;
$cart_products = $this->context->cart->getProducts();
+ // By Webkul : This code is to check available quantity of Room before adding it to cart.
+ // only check availability if qty is increasing
+ if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) {
+ require_once _PS_MODULE_DIR_.'hotelreservationsystem/define.php';
+ $objRoomType = new HotelRoomType();
+ if ($roomTypeInfo = $objRoomType->getRoomTypeInfoByIdProduct($this->id_product)) {
+ if ($id_hotel = $roomTypeInfo['id_hotel']) {
+ if (strtotime($date_from) < strtotime(date('Y-m-d'))) {
+ $this->errors[] = Tools::displayError('You can\'t book room before current date');
+ } elseif (strtotime($date_from) >= strtotime($date_to)) {
+ $this->errors[] = Tools::displayError('Check-out date must be after check-in date');
+ } elseif ($maxOrdDate = HotelOrderRestrictDate::getMaxOrderDate($id_hotel)) {
+ // Check Order restrict condition before adding in to cart
+ if (strtotime('-1 day', strtotime($maxOrdDate)) < strtotime($date_from)
+ || strtotime($maxOrdDate) < strtotime($date_to)
+ ) {
+ $maxOrdDate = date('d-m-Y', strtotime($maxOrdDate));
+ $this->errors[] = Tools::displayError('You can\'t book room after date '.$maxOrdDate);
+ }
+ }
+ if (!$this->errors) {
+ $objBookingDtl = new HotelBookingDetail();
+ $num_days = $objBookingDtl->getNumberOfDays($date_from, $date_to);
+ $req_rm = $this->qty;
+ $this->qty = $this->qty * (int) $num_days;
+ $obj_booking_dtl = new HotelBookingDetail();
+ if ($hotel_room_data = $obj_booking_dtl->DataForFrontSearch(
+ $date_from,
+ $date_to,
+ $id_hotel,
+ $this->id_product,
+ 1,
+ 0,
+ 0,
+ -1,
+ 0,
+ 0,
+ $id_cart,
+ $id_guest
+ )) {
+ if (isset($hotel_room_data['stats']['num_avail'])) {
+ $total_available_rooms = $hotel_room_data['stats']['num_avail'];
+ if (Tools::getValue('op', 'up') == 'up') {
+ if ($total_available_rooms < $req_rm) {
+ die(json_encode(array('status' => 'unavailable_quantity', 'avail_rooms' => $total_available_rooms)));
+ }
+ }
+ } else {
+ $this->errors[] = Tools::displayError('Rooms are unavailable. Please try with different dates');
+ }
+ } else {
+ $this->errors[] = Tools::displayError('Rooms are unavailable. Please try with different dates');
+ }
+ }
+ } else {
+ die(json_encode(array('status' => 'failed3')));
+ }
+ } else {
+ die(json_encode(array('status' => 'failed4')));
+ }
+ }
+
if (is_array($cart_products)) {
foreach ($cart_products as $cart_product) {
if ((!isset($this->id_product_attribute) || $cart_product['id_product_attribute'] == $this->id_product_attribute) &&
@@ -401,44 +406,59 @@ protected function processChangeProductInCart()
if (!$this->errors) {
$cart_rules = $this->context->cart->getCartRules();
$available_cart_rules = CartRule::getCustomerCartRules($this->context->language->id, (isset($this->context->customer->id) ? $this->context->customer->id : 0), true, true, true, $this->context->cart, false, true);
- $update_quantity = $this->context->cart->updateQty($this->qty, $this->id_product, $this->id_product_attribute, $this->customization_id, Tools::getValue('op', 'up'), $this->id_address_delivery);
/*------ BY Webkul ------*/
/*
* To add Rooms in hotel cart
*/
- $this->availQty = false;
- $id_customer = $this->context->cart->id_customer;
- $id_currency = $this->context->cart->id_currency;
-
- $hotel_room_info_arr = $hotel_room_data['rm_data'][0]['data']['available'];
- $chkQty = 0;
- foreach ($hotel_room_info_arr as $key_hotel_room_info => $val_hotel_room_info) {
- if ($chkQty < $req_rm) {
- $roomDemand = Tools::getValue('roomDemands');
- $roomDemand = json_decode($roomDemand, true);
- $roomDemand = json_encode($roomDemand);
- $obj_htl_cart_booking_data = new HotelCartBookingData();
- $obj_htl_cart_booking_data->id_cart = $this->context->cart->id;
- $obj_htl_cart_booking_data->id_guest = $this->context->cart->id_guest;
- $obj_htl_cart_booking_data->id_customer = $id_customer;
- $obj_htl_cart_booking_data->id_currency = $id_currency;
- $obj_htl_cart_booking_data->id_product = $val_hotel_room_info['id_product'];
- $obj_htl_cart_booking_data->id_room = $val_hotel_room_info['id_room'];
- $obj_htl_cart_booking_data->id_hotel = $val_hotel_room_info['id_hotel'];
- $obj_htl_cart_booking_data->booking_type = 1;
- $obj_htl_cart_booking_data->quantity = $num_days;
- $obj_htl_cart_booking_data->extra_demands = $roomDemand;
- $obj_htl_cart_booking_data->date_from = $date_from;
- $obj_htl_cart_booking_data->date_to = $date_to;
- $obj_htl_cart_booking_data->save();
- ++$chkQty;
+ if (Module::isInstalled('hotelreservationsystem') && Module::isEnabled('hotelreservationsystem')) {
+ if (Tools::getValue('op', 'up') == 'up') {
+ $update_quantity = $this->context->cart->updateQty($this->qty, $this->id_product, $this->id_product_attribute, $this->customization_id, Tools::getValue('op', 'up'), $this->id_address_delivery);
+ $this->availQty = false;
+ $id_customer = $this->context->cart->id_customer;
+ $id_currency = $this->context->cart->id_currency;
+
+ $hotel_room_info_arr = $hotel_room_data['rm_data'][0]['data']['available'];
+ $chkQty = 0;
+ foreach ($hotel_room_info_arr as $key_hotel_room_info => $val_hotel_room_info) {
+ if ($chkQty < $req_rm) {
+ $roomDemand = Tools::getValue('roomDemands');
+ $roomDemand = json_decode($roomDemand, true);
+ $roomDemand = json_encode($roomDemand);
+ $obj_htl_cart_booking_data = new HotelCartBookingData();
+ $obj_htl_cart_booking_data->id_cart = $this->context->cart->id;
+ $obj_htl_cart_booking_data->id_guest = $this->context->cart->id_guest;
+ $obj_htl_cart_booking_data->id_customer = $id_customer;
+ $obj_htl_cart_booking_data->id_currency = $id_currency;
+ $obj_htl_cart_booking_data->id_product = $val_hotel_room_info['id_product'];
+ $obj_htl_cart_booking_data->id_room = $val_hotel_room_info['id_room'];
+ $obj_htl_cart_booking_data->id_hotel = $val_hotel_room_info['id_hotel'];
+ $obj_htl_cart_booking_data->booking_type = 1;
+ $obj_htl_cart_booking_data->quantity = $num_days;
+ $obj_htl_cart_booking_data->extra_demands = $roomDemand;
+ $obj_htl_cart_booking_data->date_from = $date_from;
+ $obj_htl_cart_booking_data->date_to = $date_to;
+ $obj_htl_cart_booking_data->save();
+ ++$chkQty;
+ } else {
+ break;
+ }
+ }
+ $this->availQty = $total_available_rooms - $req_rm;
} else {
- break;
+ $objCartBooking = new HotelCartBookingData();
+ $update_quantity = $objCartBooking->deleteCartBookingData(
+ $id_cart,
+ $this->id_product,
+ 0,
+ $date_from,
+ $date_to
+ );
+ $this->availQty = $total_available_rooms + $req_rm;
+
}
+ $this->context->cookie->avail_rooms = $this->availQty;
}
- $this->availQty = $total_available_rooms - $req_rm;
- $this->context->cookie->avail_rooms = $this->availQty;
/*------ BY Webkul ------*/
if ($update_quantity < 0) {
diff --git a/modules/blockcart/ajax-cart.js b/modules/blockcart/ajax-cart.js
index 2715f6669..11f7b90fc 100644
--- a/modules/blockcart/ajax-cart.js
+++ b/modules/blockcart/ajax-cart.js
@@ -166,76 +166,12 @@ var ajaxCart = {
if ($('#booking_dates_container_' + id_product).find('.rooms_remove_container .remove_rooms_from_cart_link').length == 1) {
$(this).closest(".rooms_remove_container").parents("div.cart_prod_cont").siblings(".remove_link").find("a.ajax_cart_block_remove_link").click();
} else {
+
var date_from = $(this).attr('date_from');
var date_to = $(this).attr('date_to');
var num_rooms = $(this).attr('num_rooms');
var $current = $(this);
- $.ajax({
- type: 'POST',
- url: rm_avail_process_lnk,
- async: false,
- dataType: 'JSON',
- data: 'delete_room_form_cart=1&id_product=' + id_product + '&num_rooms=' + num_rooms + '&date_from=' + date_from + '&date_to=' + date_to,
- success: function(data) {
- if (data.status = 'success') {
- var total_cart_price = $('.ajax_block_cart_total').attr('total_cart_price');
- var total_prod_prc = parseFloat($(".rm_product_info_" + id_product + " .price").attr('ttl_prod_price'));
- var room_prc = parseFloat($current.attr('rm_price'));
- var new_ttl = parseFloat($(".rm_product_info_" + id_product + " .price").attr('ttl_prod_price')) - parseFloat($current.attr('rm_price'));
- var nw_ttl_cart_price = parseFloat(total_cart_price) - parseFloat(room_prc);
-
- $('.ajax_block_cart_total').text(formatCurrency(parseFloat(nw_ttl_cart_price), currency_format, currency_sign, currency_blank));
- $('.ajax_block_cart_total').attr('total_cart_price', nw_ttl_cart_price);
-
- $(".rm_product_info_" + id_product + " .price").attr('ttl_prod_price', new_ttl);
-
-
- $(".rm_product_info_" + id_product + " .price").text(formatCurrency(parseFloat(new_ttl), currency_format, currency_sign, currency_blank));
-
- $(".rm_product_info_" + id_product + " .quantity-formated .quantity").text(parseInt($(".rm_product_info_" + id_product + " .quantity-formated .quantity").text()) - parseInt(num_rooms));
- if ($(".shopping_cart .ajax_cart_quantity").text() == '')
- var prev_ajax_cart_quantity = 0;
- else
- var prev_ajax_cart_quantity = parseInt($(".shopping_cart .ajax_cart_quantity").text());
-
- $(".shopping_cart .ajax_cart_quantity").text(prev_ajax_cart_quantity - parseInt(num_rooms));
-
- if (pagename == 'product') {
- var date_checkIn = $('#room_check_in').val();
- var date_checkOut = $('#room_check_out').val();
- if (data.avail_rooms <= room_warning_num) {
- $('.num_quantity_alert').show();
- } else {
- $('.num_quantity_alert').hide();
- }
- var product_page_id_product = $('#product_page_product_id').val();
-
- if (id_product == product_page_id_product && date_from < date_checkOut && date_to >= date_checkIn) {
- $("#max_avail_type_qty").val(data.avail_rooms);
- $(".num_searched_avail_rooms").text(data.avail_rooms);
- $('.sold_out_alert').hide();
- disableRoomTypeDemands(0);
- $('.unvail_rooms_cond_display').show();
- }
- } else {
- var date_checkIn = $('#check_in_time').val();
- var date_checkOut = $('#check_out_time').val();
- if (data.avail_rooms <= room_warning_num) {
- $(".cat_remain_rm_qty_" + id_product).closest('.rm_left').show();
- } else {
- $(".cat_remain_rm_qty_" + id_product).closest('.rm_left').hide();
- }
- if (id_product && date_from < date_checkOut && date_to >= date_checkIn) {
- $(".cat_remain_rm_qty_" + id_product).text(data.avail_rooms);
- $(".cat_remain_rm_qty_" + id_product).closest('.room_cont').show();
- }
- }
- $current.closest(".rooms_remove_container").remove();
- } else {
- alert(someErrorCondition);
- }
- }
- });
+ ajaxCart.update(id_product, false, false, true, num_rooms, false, date_from, date_to);
}
});
@@ -415,14 +351,9 @@ var ajaxCart = {
if ($('.cart_block_list').hasClass('collapsed'))
this.expand();
+
// get the selected extra demands by customer
- var roomDemands = [];
- $('input:checkbox.id_room_type_demand:checked').each(function () {
- roomDemands.push({
- 'id_global_demand':$(this).val(),
- 'id_option': $(this).closest('.room_demand_block').find('.id_option').val()
- });
- });
+ var roomDemands = getRoomsExtraDemands();
//send the ajax request to the server
$.ajax({
type: 'POST',
@@ -538,6 +469,101 @@ var ajaxCart = {
});
},
+ update: function(idProduct, idCombination, customizationId, updatedFromProductPage, quantity, whishlist, dateFrom, dateTo) {
+ if (updatedFromProductPage && !checkCustomizations()) {
+ if (contentOnly) {
+ var productUrl = window.document.location.href + '';
+ var data = productUrl.replace('content_only=1', '');
+ window.parent.document.location.href = data;
+ return;
+ }
+ if (!!$.prototype.fancybox)
+ $.fancybox.open([{
+ type: 'inline',
+ autoScale: true,
+ minHeight: 30,
+ content: '
' + fieldRequired + '
'
+ }], {
+ padding: 0
+ });
+ else
+ alert(fieldRequired);
+ return;
+ }
+ $.ajax({
+ type: 'POST',
+ headers: {
+ "cache-control": "no-cache"
+ },
+ url: baseUri + '?rand=' + new Date().getTime(),
+ async: true,
+ cache: false,
+ dataType: "json",
+ data: 'controller=cart&add=1&op=down&dateFrom=' + dateFrom + '&dateTo=' + dateTo + '&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ((parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination) : '' + '&id_customization=' + ((typeof customizationId !== 'undefined') ? customizationId : 0)),
+ success: function(jsonData, textStatus, jqXHR) {
+ /*by webkul checking and setting availability of rooms*/
+ /*for product page add to cart quantity management*/
+ if (pagename == 'product') {
+ var date_checkIn = $('#room_check_in').val();
+ var date_checkOut = $('#room_check_out').val();
+ var product_page_id_product = $('#product_page_product_id').val();
+ if (idProduct == product_page_id_product && dateFrom < date_checkOut && dateTo >= date_checkIn) {
+ if (jsonData.avail_rooms <= room_warning_num) {
+ $('.num_quantity_alert').show();
+ } else {
+ $('.num_quantity_alert').hide();
+ }
+ $("#max_avail_type_qty").val(jsonData.avail_rooms);
+ $(".num_searched_avail_rooms").text(jsonData.avail_rooms);
+
+ if (jsonData.avail_rooms == 0) {
+ $('.num_quantity_alert').hide();
+ $('.sold_out_alert').show();
+ disableRoomTypeDemands(1);
+ $('.unvail_rooms_cond_display').hide();
+ }
+ }
+ }
+
+ if (pagename == 'category') {
+ if (jsonData.avail_rooms <= room_warning_num) {
+ $(".cat_remain_rm_qty_" + idProduct).closest('.rm_left').show();
+ } else {
+ $("cat_remain_rm_qty_" + idProduct).closest('.rm_left').hide();
+ }
+
+ /*for category page add to cart quantity management*/
+
+ $(".cat_remain_rm_qty_" + idProduct).text(jsonData.avail_rooms);
+ if (jsonData.avail_rooms == 0) {
+ $(".cat_remain_rm_qty_" + idProduct).closest('.room_cont').hide();
+ }
+ }
+
+ ajaxCart.updateCart(jsonData);
+ },
+ error: function(XMLHttpRequest, textStatus, errorThrown) {
+ var error = "Impossible to add the room to the cart.
textStatus: '" + textStatus + "'
errorThrown: '" + errorThrown + "'
responseText:
" + XMLHttpRequest.responseText;
+ if (!!$.prototype.fancybox)
+ $.fancybox.open([{
+ type: 'inline',
+ autoScale: true,
+ minHeight: 30,
+ content: '' + error + '
'
+ }], {
+ padding: 0
+ });
+ else
+ alert(error);
+ //reactive the button when adding has finished
+ if (addedFromProductPage)
+ $('#add_to_cart button').removeProp('disabled').removeClass('disabled');
+ else
+ $(callerElement).removeProp('disabled');
+ }
+ });
+ },
+
//remove a product from the cart via ajax
remove: function(idProduct, idCombination, customizationId, idAddressDelivery, dateFrom, dateTo) {
//send the ajax request to the server
@@ -578,7 +604,9 @@ var ajaxCart = {
}
});
}
-
+ if (pagename == 'orderopc') {
+ location.reload();
+ }
ajaxCart.updateCart(jsonData);
// @TODO in future to sync with shopping cart delete from order-opc
@@ -810,17 +838,18 @@ var ajaxCart = {
content += ' | ';
content += '';
-
- $.each(cart_booking_data[key].date_diff, function(date_diff_k, date_diff_v) {
- content += '';
- content += '' + $.datepicker.formatDate('dd-mm-yy', new Date(date_diff_v.data_form)) + ' - ' + $.datepicker.formatDate('dd-mm-yy', new Date(date_diff_v.data_to)) + ' | ';
- content += '' + date_diff_v.num_rm + ' | ';
- content += '' + formatCurrency(parseFloat(date_diff_v.amount), currency_format, currency_sign, currency_blank) + ' | ';
- content += '';
- content += '';
- content += ' | ';
- content += '
';
- });
+ if (cart_booking_data[key].date_diff !== 'undefined') {
+ $.each(cart_booking_data[key].date_diff, function(date_diff_k, date_diff_v) {
+ content += '';
+ content += '' + $.datepicker.formatDate('dd-mm-yy', new Date(date_diff_v.data_form)) + ' - ' + $.datepicker.formatDate('dd-mm-yy', new Date(date_diff_v.data_to)) + ' | ';
+ content += '' + date_diff_v.num_rm + ' | ';
+ content += '' + formatCurrency(parseFloat(date_diff_v.amount), currency_format, currency_sign, currency_blank) + ' | ';
+ content += '';
+ content += '';
+ content += ' | ';
+ content += '
';
+ });
+ }
content += '';
content += '';
content += '';
@@ -846,17 +875,18 @@ var ajaxCart = {
var product_price_float = this.price_float;
-
- $.each(cart_booking_data[key].date_diff, function(date_diff_k1, date_diff_v1) {
- booking_dates_content += '';
- booking_dates_content += '' + $.datepicker.formatDate('dd-mm-yy', new Date(date_diff_v1.data_form)) + ' - ' + $.datepicker.formatDate('dd-mm-yy', new Date(date_diff_v1.data_to)) + ' | ';
- booking_dates_content += '' + date_diff_v1.num_rm + ' | ';
- booking_dates_content += '' + formatCurrency(parseFloat(date_diff_v1.amount), currency_format, currency_sign, currency_blank) + ' | ';
- booking_dates_content += '';
- booking_dates_content += '';
- booking_dates_content += ' | ';
- booking_dates_content += '
';
- });
+ if (cart_booking_data[key].date_diff !== 'undefined') {
+ $.each(cart_booking_data[key].date_diff, function(date_diff_k1, date_diff_v1) {
+ booking_dates_content += '';
+ booking_dates_content += '' + $.datepicker.formatDate('dd-mm-yy', new Date(date_diff_v1.data_form)) + ' - ' + $.datepicker.formatDate('dd-mm-yy', new Date(date_diff_v1.data_to)) + ' | ';
+ booking_dates_content += '' + date_diff_v1.num_rm + ' | ';
+ booking_dates_content += '' + formatCurrency(parseFloat(date_diff_v1.amount), currency_format, currency_sign, currency_blank) + ' | ';
+ booking_dates_content += '';
+ booking_dates_content += '';
+ booking_dates_content += ' | ';
+ booking_dates_content += '
';
+ });
+ }
$("#booking_dates_container_" + this.id).find("table.table tbody").append(booking_dates_content);
//end
@@ -959,12 +989,12 @@ var ajaxCart = {
//by webkul has to work on it more..
if (pagename == 'product') {
- $('#layer_cart_product_time_duration').text($('#room_check_in').val() + '-' + $('#room_check_out').val());
+ $('#layer_cart_product_time_duration').text($('#room_check_in').val() + ' - ' + $('#room_check_out').val());
$('#layer_cart_product_quantity').text($('#quantity_wanted').val());
$('#quantity_wanted').val(1);
}
if (pagename == 'category') {
- $('#layer_cart_product_time_duration').text($('#check_in_time').val() + '-' + $('#check_out_time').val());
+ $('#layer_cart_product_time_duration').text($('#check_in_time').val() + ' - ' + $('#check_out_time').val());
$('#layer_cart_product_quantity').text($('#cat_quantity_wanted_' + product.id).val());
$('#cat_quantity_wanted_' + product.id).val(1);
@@ -1019,13 +1049,13 @@ var ajaxCart = {
//update general cart informations everywhere in the page
updateCartEverywhere: function(jsonData) {
- $('.ajax_cart_total').text($.trim(jsonData.productTotal));
+ $('.ajax_cart_total').text($.trim(jsonData.product_total));
if (typeof hasDeliveryAddress == 'undefined')
hasDeliveryAddress = false;
- if (parseFloat(jsonData.shippingCostFloat) > 0)
- $('.ajax_cart_shipping_cost').text(jsonData.shippingCost).parent().find('.unvisible').show();
+ if (parseFloat(jsonData.shipping_cost_float) > 0)
+ $('.ajax_cart_shipping_cost').text(jsonData.shipping_cost).parent().find('.unvisible').show();
else if ((hasDeliveryAddress || typeof(orderProcess) !== 'undefined' && orderProcess == 'order-opc') && typeof(freeShippingTranslation) != 'undefined')
$('.ajax_cart_shipping_cost').html(freeShippingTranslation);
else if (!hasDeliveryAddress)
@@ -1035,30 +1065,30 @@ var ajaxCart = {
$('.ajax_cart_shipping_cost').parent().find('.unvisible').show();
$('.ajax_cart_tax_cost').text(jsonData.taxCost);
- $('.cart_block_wrapping_cost').text(jsonData.wrappingCost);
+ $('.cart_block_wrapping_cost').text(jsonData.wrapping_cost);
$('.ajax_block_cart_total').text(jsonData.total);
$('.ajax_block_cart_total').attr('total_cart_price', jsonData.totalToPay);
- $('.ajax_block_products_total').text(jsonData.productTotal);
- $('.ajax_cart_extra_demands_cost').text(jsonData.totalDemandsPriceFormat);
+ $('.ajax_block_products_total').text(jsonData.product_total);
+ $('.ajax_cart_extra_demands_cost').text(jsonData.total_extra_demands_format);
$('.ajax_total_price_wt').text(jsonData.total_price_wt);
- if (parseFloat(jsonData.freeShippingFloat) > 0) {
- $('.ajax_cart_free_shipping').html(jsonData.freeShipping);
+ if (parseFloat(jsonData.free_shipping_float) > 0) {
+ $('.ajax_cart_free_shipping').html(jsonData.free_shipping);
$('.freeshipping').fadeIn(0);
- } else if (parseFloat(jsonData.freeShippingFloat) == 0)
+ } else if (parseFloat(jsonData.free_shipping_float) == 0)
$('.freeshipping').fadeOut(0);
- this.nb_total_products = jsonData.nbTotalProducts;
+ this.nb_total_products = jsonData.nb_total_products;
- if (parseInt(jsonData.nbTotalProducts) > 0) {
+ if (parseInt(jsonData.nb_total_products) > 0) {
$('.ajax_cart_no_product').hide();
$('.ajax_cart_quantity').text(jsonData.total_rooms_in_cart);
$('.ajax_cart_quantity').fadeIn('slow');
$('.ajax_cart_total').fadeIn('slow');
- if (parseInt(jsonData.nbTotalProducts) > 1) {
+ if (parseInt(jsonData.nb_total_products) > 1) {
$('.ajax_cart_product_txt').each(function() {
$(this).hide();
});
@@ -1124,3 +1154,17 @@ function disableRoomTypeDemands(show) {
$('.room_demands_container').find('.checker').removeClass('disabled');
}
}
+
+function getRoomsExtraDemands()
+{
+ var roomDemands = [];
+
+ $('input:checkbox.id_room_type_demand:checked').each(function () {
+ roomDemands.push({
+ 'id_global_demand':$(this).val(),
+ 'id_option': $(this).closest('.room_demand_block').find('.id_option').val()
+ });
+ });
+
+ return roomDemands;
+}
\ No newline at end of file
diff --git a/modules/blockcart/blockcart-json.tpl b/modules/blockcart/blockcart-json.tpl
deleted file mode 100644
index b7516f187..000000000
--- a/modules/blockcart/blockcart-json.tpl
+++ /dev/null
@@ -1,122 +0,0 @@
-{*
-* 2007-2017 PrestaShop
-*
-* NOTICE OF LICENSE
-*
-* This source file is subject to the Academic Free License (AFL 3.0)
-* that is bundled with this package in the file LICENSE.txt.
-* It is also available through the world-wide-web at this URL:
-* http://opensource.org/licenses/afl-3.0.php
-* If you did not receive a copy of the license and are unable to
-* obtain it through the world-wide-web, please send an email
-* to license@prestashop.com so we can send you a copy immediately.
-*
-* DISCLAIMER
-*
-* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
-* versions in the future. If you wish to customize PrestaShop for your
-* needs please refer to http://www.prestashop.com for more information.
-*
-* @author PrestaShop SA
-* @copyright 2007-2017 PrestaShop SA
-* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
-* International Registered Trademark & Property of PrestaShop SA
-*}
-{ldelim}
-"products": [
-{if $products}
-{foreach from=$products item=product name='products'}
-{assign var='productId' value=$product.id_product}
-{assign var='productAttributeId' value=$product.id_product_attribute}
- {ldelim}
- "id": {$product.id_product|intval},
- "link": {$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|json_encode},
- "quantity": {$product.cart_quantity|intval},
- "image": {$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')|json_encode},
- "image_cart": {$link->getImageLink($product.link_rewrite, $product.id_image, 'cart_default')|json_encode},
- "priceByLine": {if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|json_encode p=$product.total}{else}{displayWtPrice|json_encode p=$product.total_wt}{/if},
- "name": {$product.name|trim|html_entity_decode:2:'UTF-8'|json_encode},
- "price": {if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|json_encode p=$product.total}{else}{displayWtPrice|json_encode p=$product.total_wt}{/if},
- "price_float": {$product.total|floatval|json_encode},
- "total_product_price": {if $priceDisplay == $smarty.const.PS_TAX_EXC}{$product.total|floatval|json_encode}{else}{$product.total_wt|floatval|json_encode}{/if},
- "idCombination": {if isset($product.attributes_small)}{$productAttributeId|intval}{else}0{/if},
- "idAddressDelivery": {if isset($product.id_address_delivery)}{$product.id_address_delivery|intval}{else}0{/if},
- "is_gift": {if isset($product.is_gift) && $product.is_gift}true{else}false{/if},
-{if isset($product.attributes_small)}
- "hasAttributes": true,
- "attributes": {$product.attributes_small|json_encode},
-{else}
- "hasAttributes": false,
-{/if}
- "hasCustomizedDatas": {if isset($customizedDatas.$productId.$productAttributeId)}true{else}false{/if},
- "customizedDatas": [
- {if isset($customizedDatas.$productId.$productAttributeId[$product.id_address_delivery])}
- {foreach from=$customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] key='id_customization' item='customization' name='customizedDatas'}{ldelim}
-{* This empty line was made in purpose (product addition debug), please leave it here *}
- "customizationId": {$id_customization|intval},
- "quantity": {$customization.quantity|intval},
- "datas": [
- {foreach from=$customization.datas key='type' item='datas' name='customization'}
- {ldelim}
- "type": {$type|json_encode},
- "datas": [
- {foreach from=$datas key='index' item='data' name='datas'}
- {ldelim}
- "index": {$index|intval},
- "value": {Tools::nl2br($data.value)|json_encode},
- "truncatedValue": {Tools::nl2br($data.value|truncate:28:'...')|json_encode}
- {rdelim}{if !$smarty.foreach.datas.last},{/if}
- {/foreach}]
- {rdelim}{if !$smarty.foreach.customization.last},{/if}
- {/foreach}
- ]
- {rdelim}{if !$smarty.foreach.customizedDatas.last},{/if}
- {/foreach}
- {/if}
- ]
- {rdelim}{if !$smarty.foreach.products.last},{/if}
-{/foreach}{/if}
-],
-"discounts": [
-{if $discounts}{foreach from=$discounts item=discount name='discounts'}
- {ldelim}
- "id": {$discount.id_discount|intval},
- "name": {$discount.name|trim|truncate:18:'...'|json_encode},
- "description": {$discount.description|json_encode},
- "nameDescription": {$discount.name|cat:' : '|cat:$discount.description|trim|truncate:18:'...'|json_encode},
- "code": {$discount.code|json_encode},
- "link": {$link->getPageLink("$order_process", true, NULL, "deleteDiscount={$discount.id_discount}")|json_encode},
- "price": {if $priceDisplay == 1}{convertPrice|json_encode price=$discount.value_tax_exc}{else}{convertPrice|json_encode price=$discount.value_real}{/if},
- "price_float": {if $priceDisplay == 1}{$discount.value_tax_exc|json_encode}{else}{$discount.value_real|json_encode}{/if}
- {rdelim}
- {if !$smarty.foreach.discounts.last},{/if}
-{/foreach}{/if}
-],
-"shippingCost": {$shipping_cost|json_encode},
-"shippingCostFloat": {$shipping_cost_float|json_encode},
-{if isset($tax_cost)}
-"taxCost": {$tax_cost|json_encode},
-{/if}
-"wrappingCost": {$wrapping_cost|json_encode},
-"nbTotalProducts": {$nb_total_products|intval},
-"total": {$total|json_encode},
-"totalToPay": {$totalToPay|floatval|json_encode},
-"productTotal": {$product_total|json_encode},
-"totalDemandsPrice": {$total_extra_demands|json_encode},
-"totalDemandsPriceFormat": {$total_extra_demands_format|json_encode},
-"freeShipping": {displayWtPrice|json_encode p=$free_shipping},
-"freeShippingFloat": {$free_shipping|json_encode},
-{if isset($errors) && $errors}
-"hasError" : true,
-"errors" : [
-{foreach from=$errors key=k item=error name='errors'}
- {$error|json_encode}
- {if !$smarty.foreach.errors.last},{/if}
-{/foreach}
-],
-{else}
-"hasError" : false,
-{/if}
-"cart_booking_data" :{$cart_htl_data|json_encode},
-"total_rooms_in_cart" :{$total_rooms_in_cart|json_encode}
-{rdelim}
diff --git a/modules/blockcart/blockcart.css b/modules/blockcart/blockcart.css
index 1c74332b5..fa6ae376e 100644
--- a/modules/blockcart/blockcart.css
+++ b/modules/blockcart/blockcart.css
@@ -186,7 +186,7 @@
width: 300px; } }
@media (max-width: 355px) {
#header .cart_block {
- width: 270px; } }
+ width: 270px; } }
/* @media (max-width: 1200px) {
#header .cart_block {
width: 100%; } }*/
@@ -233,7 +233,8 @@
.cart_block .cart_block_shipping_cost,
.cart_block .cart_block_tax_cost,
.cart_block .cart_block_total,
-.cart_block .cart_block_wrapping_cost {
+.cart_block .cart_block_wrapping_cost,
+.cart_block .cart_block_additional_facilities_cost {
float: right; }
.cart_block table.vouchers {
@@ -501,14 +502,14 @@
color: #EDEDED;
}
-#header .cart_block .product_info_data
+#header .cart_block .product_info_data
{
font-size: 14px;
font-weight: 400;
color: #AEAEAE;
}
-#header .cart_block .product-name
+#header .cart_block .product-name
{
font-size: 16px;
font-weight: 700;
@@ -517,7 +518,7 @@
.cart-info-sec
{
- padding-bottom: 1px;
+ padding-bottom: 1px;
}
.cart_block .cart_prod_cont .table td, .cart_prod_cont .table th
@@ -531,18 +532,18 @@
margin-bottom: 0px;
}
-.cart_block .table-responsive
+.cart_block .table-responsive
{
overflow-x:auto;
}
@media (max-width: 768px) {
- .cart_block .table-responsive > .table
+ .cart_block .table-responsive > .table
{
background-color: transparent;
}
- .cart_block .table-responsive
+ .cart_block .table-responsive
{
border: none;
}
diff --git a/modules/blockcart/blockcart.php b/modules/blockcart/blockcart.php
index 7a3fe31ad..694dd6754 100644
--- a/modules/blockcart/blockcart.php
+++ b/modules/blockcart/blockcart.php
@@ -46,7 +46,7 @@ public function __construct()
$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
}
- public function assignContentVars($params)
+ public function getContentVars($params)
{
global $errors;
@@ -60,6 +60,7 @@ public function assignContentVars($params)
$taxCalculationMethod = Group::getPriceDisplayMethod((int) Group::getCurrent()->id);
$useTax = !($taxCalculationMethod == PS_TAX_EXC);
+ $showTax = (int) (Configuration::get('PS_TAX_DISPLAY') == 1 && (int) Configuration::get('PS_TAX'));
$products = $params['cart']->getProducts(true);
@@ -70,8 +71,44 @@ public function assignContentVars($params)
}
}
+ $priceDisplayMethod = Product::getTaxCalculationMethod((int)$this->context->cookie->id_customer);
$nbTotalProducts = 0;
- foreach ($products as $product) {
+ foreach ($products as &$product) {
+ $product['id'] = $product['id_product'];
+ $product['link'] = $this->context->link->getProductLink(
+ $product['id_product'],
+ $product['link_rewrite'],
+ $product['category'],
+ null,
+ null,
+ $product['id_shop'],
+ $product['id_product_attribute']
+ );
+ $product['image'] = $this->context->link->getImageLink(
+ $product['link_rewrite'],
+ $product['id_image'],
+ 'home_default'
+ );
+ $product['image_cart'] = $this->context->link->getImageLink(
+ $product['link_rewrite'],
+ $product['id_image'],
+ 'cart_default'
+ );
+ if ($priceDisplayMethod == PS_TAX_EXC) {
+ $product['priceByLine'] = Tools::displayPrice($product['total']);
+ $product['price'] = Tools::displayPrice($product['total']);
+ $product['total_product_price'] = $product['total'];
+ } else {
+ $product['priceByLine'] = Tools::displayPrice($product['total_wt']);
+ $product['price'] = Tools::displayPrice($product['total_wt']);
+ $product['total_product_price'] = $product['total_wt'];
+ }
+ $product['price_float'] = $product['total'];
+ $product['idCombination'] = isset($product['attributes_small']) ? $product['attributes_small'] : 0;
+ $product['idAddressDelivery'] = isset($product['id_address_delivery']) ? $product['id_address_delivery'] : 0;
+ $product['is_gift'] = (isset($product['is_gift']) && $product['is_gift'] )? true : false;
+ $product['hasCustomizedDatas'] = false;
+ $product['hasAttributes'] = false;
$nbTotalProducts += (int) $product['cart_quantity'];
}
$cart_rules = $params['cart']->getCartRules();
@@ -91,12 +128,14 @@ public function assignContentVars($params)
$shipping_cost_float = Tools::convertPrice($base_shipping, $currency);
$wrappingCost = (float) ($params['cart']->getOrderTotal($useTax, Cart::ONLY_WRAPPING));
$totalToPay = $params['cart']->getOrderTotal($useTax);
- if ($useTax && Configuration::get('PS_TAX_DISPLAY') == 1) {
+ $tax_cost = 0;
+ if ($showTax) {
$totalToPayWithoutTaxes = $params['cart']->getOrderTotal(false);
- $this->smarty->assign('tax_cost', Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency));
+ $tax_cost = Tools::displayPrice($totalToPay - $totalToPayWithoutTaxes, $currency);
}
// The cart content is altered for display
+ $orderProcess = Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order';
foreach ($cart_rules as &$cart_rule) {
if ($cart_rule['free_shipping']) {
$shipping_cost = Tools::displayPrice(0, $currency);
@@ -121,6 +160,16 @@ public function assignContentVars($params)
}
}
}
+ $cart_rule['id'] = $cart_rule['id_discount'];
+ $cart_rule['link'] = $this->context->link->getPageLink($orderProcess, true, NULL, "deleteDiscount=".$cart_rule['id_discount']);
+ if ($priceDisplayMethod == PS_TAX_EXC) {
+ $cart_rule['price'] = Tools::displayPrice($cart_rule['value_tax_exc']);
+ $cart_rule['price_float'] = $cart_rule['value_tax_exc'];
+ } else {
+ $cart_rule['price'] = Tools::displayPrice($cart_rule['value_real']);
+ $cart_rule['price_float'] = $cart_rule['value_real'];
+ }
+
}
$total_free_shipping = 0;
@@ -146,7 +195,7 @@ public function assignContentVars($params)
1
);
- $this->smarty->assign(array(
+ $response = array(
'products' => $products,
'customizedDatas' => Product::getAllCustomizedDatas((int) ($params['cart']->id)),
'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE,
@@ -156,26 +205,40 @@ public function assignContentVars($params)
'shipping_cost' => $shipping_cost,
'shipping_cost_float' => $shipping_cost_float,
'show_wrapping' => $wrappingCost > 0 ? true : false,
- 'show_tax' => (int) (Configuration::get('PS_TAX_DISPLAY') == 1 && (int) Configuration::get('PS_TAX')),
+ 'show_tax' => $showTax,
+ 'tax_cost' => $tax_cost,
'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency),
'product_total' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::ONLY_PRODUCTS), $currency),
'totalToPay' => $totalToPay,
'total_extra_demands' => $totalDemandsPrice,
'total_extra_demands_format' => Tools::displayPrice($totalDemandsPrice, $currency),
'total' => Tools::displayPrice($totalToPay, $currency),
- 'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order',
+ 'order_process' => $orderProcess,
'ajax_allowed' => (int) (Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false,
'static_token' => Tools::getToken(false),
- 'free_shipping' => $total_free_shipping,
- 'cart_htl_data' => $htlCartData,
+ 'free_shipping' => Tools::displayPrice($total_free_shipping),
+ 'free_shipping_float' => $total_free_shipping,
+
+ 'cart_booking_data' => $htlCartData,
'total_rooms_in_cart' => $totalRooms,
- ));
+ );
+
+ if (isset($params['cookie']->avail_rooms)) {
+ $response['avail_rooms'] = $params['cookie']->avail_rooms;
+ unset($this->context->cookie->avail_rooms);
+ }
+
+ $response['hasError'] = false;
if (is_array($errors) && count($errors)) {
- $this->smarty->assign('errors', $errors);
+ $response['hasError'] = true;
+ $response['errors'] = $errors;
}
+
if (isset($this->context->cookie->ajax_blockcart_display)) {
- $this->smarty->assign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display);
+ $response['colapseExpandStatus'] = $this->context->cookie->ajax_blockcart_display;
}
+
+ return $response;
}
public function getContent()
@@ -223,24 +286,14 @@ public function hookAjaxCall($params)
return;
}
- $this->assignContentVars($params);
-
- $res = json_decode(Tools::removeHtmlComments($this->display(__FILE__, 'blockcart-json.tpl')), true);
-
- if (isset($params['cookie']->avail_rooms)) {
- $res['avail_rooms'] = $params['cookie']->avail_rooms;
- unset($this->context->cookie->avail_rooms);
- }
-
+ $res = $this->getContentVars($params);
if (is_array($res) && ($id_product = Tools::getValue('id_product')) && Configuration::get('PS_BLOCK_CART_SHOW_CROSSSELLING')) {
$this->smarty->assign('orderProducts', OrderDetail::getCrossSells($id_product, $this->context->language->id, Configuration::get('PS_BLOCK_CART_XSELL_LIMIT')));
$res['crossSelling'] = $this->display(__FILE__, 'crossselling.tpl');
}
- $res = json_encode($res);
-
- return $res;
+ return json_encode($res);
}
public function hookActionCartListOverride($params)
@@ -249,8 +302,8 @@ public function hookActionCartListOverride($params)
return;
}
- $this->assignContentVars(array('cookie' => $this->context->cookie, 'cart' => $this->context->cart));
- $params['json'] = Tools::removeHtmlComments($this->display(__FILE__, 'blockcart-json.tpl'));
+ $res = $this->getContentVars(array('cookie' => $this->context->cookie, 'cart' => $this->context->cart));
+ $params['json'] = json_encode($res);
}
public function hookHeader()
@@ -305,7 +358,9 @@ public function hookTop($params)
'order_page' => (strpos($_SERVER['PHP_SELF'], 'order') !== false),
'blockcart_top' => (isset($params['blockcart_top']) && $params['blockcart_top']) ? true : false,
));
- $this->assignContentVars($params);
+ $res = $this->getContentVars($params);
+
+ $this->context->smarty->assign($res);
return $this->display(__FILE__, 'blockcart.tpl');
}
diff --git a/modules/blockcart/blockcart.tpl b/modules/blockcart/blockcart.tpl
index 4686716eb..3f23b012f 100644
--- a/modules/blockcart/blockcart.tpl
+++ b/modules/blockcart/blockcart.tpl
@@ -27,7 +27,7 @@