From 4261dbc0df0ceb1c96675a9ac2c7d29c5285755d Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Wed, 23 Nov 2011 09:57:21 +0000 Subject: [PATCH] // Multishipping : Refresh carrier list git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10502 b9a71923-0436-4b27-9f14-aed3839534dd --- controllers/front/OrderOpcController.php | 29 +++++++- themes/prestashop/js/cart-summary.js | 8 +-- themes/prestashop/js/order-opc.js | 92 +++--------------------- themes/prestashop/order-carrier.tpl | 7 +- 4 files changed, 45 insertions(+), 91 deletions(-) diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 5c3a44325..da74d332f 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -139,7 +139,7 @@ class OrderOpcControllerCore extends ParentOrderController 'summary' => $this->context->cart->getSummaryDetails(), 'order_opc_adress' => $this->context->smarty->fetch(_PS_THEME_DIR_.'order-address.tpl'), 'block_user_info' => (isset($blockUserInfo) ? $blockUserInfo->hookTop(array()) : ''), - 'carrier_list' => $this->_getCarrierList(), + 'carrier_data' => $this->_getCarrierList(), 'HOOK_TOP_PAYMENT' => Hook::exec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'no_address' => 0, @@ -195,7 +195,8 @@ class OrderOpcControllerCore extends ParentOrderController 'summary' => $this->context->cart->getSummaryDetails(), 'HOOK_TOP_PAYMENT' => Hook::exec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), - 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)($this->context->cookie->id_currency)))) + 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)($this->context->cookie->id_currency)))), + 'carrier_data' => $this->_getCarrierList() )); die(Tools::jsonEncode($result)); } @@ -422,6 +423,28 @@ class OrderOpcControllerCore extends ParentOrderController protected function _getCarrierList() { $address_delivery = new Address($this->context->cart->id_address_delivery); + + $cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $this->context->language->id); + $link_conditions = $this->context->link->getCMSLink($cms, $cms->link_rewrite, true); + if (!strpos($link_conditions, '?')) + $link_conditions .= '?content_only=1'; + else + $link_conditions .= '&content_only=1'; + + $this->context->smarty->assign(array( + 'checkedTOS' => (int)($this->context->cookie->checkedTOS), + 'recyclablePackAllowed' => (int)(Configuration::get('PS_RECYCLABLE_PACK')), + 'giftAllowed' => (int)(Configuration::get('PS_GIFT_WRAPPING')), + 'cms_id' => (int)(Configuration::get('PS_CONDITIONS_CMS_ID')), + 'conditions' => (int)(Configuration::get('PS_CONDITIONS')), + 'link_conditions' => $link_conditions, + 'recyclable' => (int)($this->context->cart->recyclable), + 'gift_wrapping_price' => (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')), + 'delivery_option_list' => $this->context->cart->getDeliveryOptionList(), + 'delivery_option' => $this->context->cart->getDeliveryOption(), + 'address_collection' => $this->context->cart->getAddressCollection(), + 'opc' => true)); + if ($this->context->customer->id) $groups = $this->context->customer->getGroups(); else @@ -433,12 +456,14 @@ class OrderOpcControllerCore extends ParentOrderController else { $carriers = Carrier::getCarriersForOrder((int)Address::getZoneById((int)($address_delivery->id)), $groups); + $result = array( 'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array( 'carriers' => $carriers, 'delivery_option_list' => $this->context->cart->getDeliveryOptionList(), 'delivery_option' => $this->context->cart->getDeliveryOption() )), + 'carrier_block' => $this->context->smarty->fetch(_PS_THEME_DIR_.'order-carrier.tpl'), 'HOOK_EXTRACARRIER' => Hook::exec('extraCarrier', array('address' => $address_delivery)) ); return $result; diff --git a/themes/prestashop/js/cart-summary.js b/themes/prestashop/js/cart-summary.js index fdd94eed1..a7b1a7488 100644 --- a/themes/prestashop/js/cart-summary.js +++ b/themes/prestashop/js/cart-summary.js @@ -109,7 +109,7 @@ function changeAddressDelivery(obj) updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); if (jsonData.carriers != null) - updateCarrierList(jsonData); + getCarrierListAndUpdate(); // @todo reverse the remove order // This effect remove the current line, but it's better to remove the other one, and refresshing this one @@ -299,7 +299,7 @@ function deleteProductFromSummary(id) updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); updateCustomizedDatas(jsonData.customizedDatas); if (jsonData.carriers != null) - updateCarrierList(jsonData); + getCarrierListAndUpdate(); } }, error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} @@ -349,7 +349,7 @@ function upQuantity(id, qty) updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); if (jsonData.carriers != null) - updateCarrierList(jsonData); + getCarrierListAndUpdate(); } }, error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} @@ -408,7 +408,7 @@ function downQuantity(id, qty) updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); if (jsonData.carriers != null) - updateCarrierList(jsonData); + getCarrierListAndUpdate(); } }, error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} diff --git a/themes/prestashop/js/order-opc.js b/themes/prestashop/js/order-opc.js index 3abb505e3..a6f4ae720 100755 --- a/themes/prestashop/js/order-opc.js +++ b/themes/prestashop/js/order-opc.js @@ -26,79 +26,12 @@ function updateCarrierList(json) { - var carriers = json.carriers; + var html = json.carrier_block; - /* contains all carrier available for this address */ - if (!carriers || carriers.length == 0) - { - checkedCarrier = 0; - $('input[name=id_carrier]:checked').attr('checked', false); - $('#noCarrierWarning').show(); - $('#extra_carrier').hide(); - $('#recyclable_block').hide(); - $('table#carrierTable:visible').hide(); - } - else - { - checkedCarrier = json.checked; - var html = ''; - for (i=0;i'; - - if (carriers[i].is_module > 0 && !isLogged) - var extraHtml = 'disabled="disabled"'; - else if (checkedCarrier == carriers[i].id_carrier) - var extraHtml = 'checked="checked"'; - else - var extraHtml = ''; - - if (carriers[i].price == 0) - var price = txtFree; - else - { - if (taxEnabled && displayPrice == 0) - var price = ''+formatCurrency(carriers[i].price, currencyFormat, currencySign, currencyBlank)+''; - else - var price = ''+formatCurrency(carriers[i].price_tax_exc, currencyFormat, currencySign, currencyBlank)+''; - } - - html = html + - ''+ - ''+ - ''+ - ''+(carriers[i].delay != null ? carriers[i].delay : '')+''+ - ''+price; - if (carriers[i].price != 0) - { - if (taxEnabled && displayPrice == 0) - html = html + ' ' + txtWithTax; - else - html = html + ' ' + txtWithoutTax; - } - html = html + ''+ - ''; - } - if (json.HOOK_EXTRACARRIER !== null && json.HOOK_EXTRACARRIER != undefined) html += json.HOOK_EXTRACARRIER; - $('#noCarrierWarning').hide(); - $('#extra_carrier:hidden').show(); - $('table#carrierTable tbody').html(html); - $('table#carrierTable:hidden').show(); - $('#recyclable_block:hidden').show(); - } + if (json.HOOK_EXTRACARRIER !== null && json.HOOK_EXTRACARRIER != undefined) + html += json.HOOK_EXTRACARRIER; + + $('#carrier_area').replaceWith(html); /* update hooks for carrier module */ $('#HOOK_BEFORECARRIER').html(json.HOOK_BEFORECARRIER); @@ -139,7 +72,7 @@ function updateAddressSelection() } else { - updateCarrierList(jsonData); + updateCarrierList(jsonData.carrier_data); updatePaymentMethods(jsonData); updateCartSummary(jsonData.summary); updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); @@ -193,13 +126,14 @@ function updateCarrierSelectionAndGift() var recyclablePackage = 0; var gift = 0; var giftMessage = ''; - var idCarrier = 0; var delivery_option_radio = $('.delivery_option_radio'); var delivery_option_params = '&'; $.each(delivery_option_radio, function(i) { delivery_option_params += $(delivery_option_radio[i]).attr('name') + '=' + $(delivery_option_radio[i]).val() + '&'; }); + if (delivery_option_params == '&') + delivery_option_params = '&delivery_option=&' if ($('input#recyclable:checked').length) recyclablePackage = 1; @@ -209,12 +143,6 @@ function updateCarrierSelectionAndGift() giftMessage = encodeURIComponent($('textarea#gift_message').val()); } - if ($('input[name=id_carrier]:checked').length) - { - idCarrier = $('input[name=id_carrier]:checked').val(); - checkedCarrier = idCarrier; - } - $('#opc_payment_methods-overlay').fadeIn('slow'); $('#opc_delivery_methods-overlay').fadeIn('slow'); $.ajax({ @@ -390,7 +318,7 @@ function updateNewAccountToAddressBlock() $('#opc_new_account').fadeIn('fast', function() { updateCartSummary(json.summary); updateAddressesDisplay(true); - updateCarrierList(json.carrier_list); + updateCarrierList(json.carrier_data); updatePaymentMethods(json); if ($('#gift-price').length == 1) $('#gift-price').html(json.gift_price); @@ -806,6 +734,6 @@ function multishippingMode(it) } $(document).ready(function() { - if (multishipping_mode) + if (typeof(multishipping_mode) != 'undefined' && multishipping_mode) $('#multishipping_mode').click(); }); \ No newline at end of file diff --git a/themes/prestashop/order-carrier.tpl b/themes/prestashop/order-carrier.tpl index d491760c5..3d19aa5cb 100644 --- a/themes/prestashop/order-carrier.tpl +++ b/themes/prestashop/order-carrier.tpl @@ -23,7 +23,7 @@ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA *} - +
{if !$opc} @@ -240,3 +240,4 @@
{/if} +