From 415619f50ecb5cc348dec4cffeb8bf0ff179f313 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Tue, 22 Nov 2011 09:28:22 +0000 Subject: [PATCH] // BugFix id_carrier in cart not defined + choosing address delivery for multishiping on opc --- classes/Cart.php | 10 +- controllers/front/OrderOpcController.php | 43 ++++-- controllers/front/ParentOrderController.php | 12 +- modules/blockcart/blockcart.php | 1 - themes/prestashop/js/order-opc.js | 45 ++++++ .../order-address-multishipping-products.tpl | 101 +++++++++++++ .../order-address-multishipping.tpl | 77 +--------- themes/prestashop/order-address.tpl | 8 + themes/prestashop/order-carrier.tpl | 140 +++++++++--------- 9 files changed, 271 insertions(+), 166 deletions(-) create mode 100644 themes/prestashop/order-address-multishipping-products.tpl diff --git a/classes/Cart.php b/classes/Cart.php index b854227b6..41a09b063 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1529,10 +1529,12 @@ class CartCore extends ObjectModel $delivery_option_list = $this->getDeliveryOptionList(); foreach ($delivery_option as $id_address => $key) { - if ($useTax) - $total_shipping += $delivery_option_list[$id_address][$key]['total_price_with_tax']; - else - $total_shipping += $delivery_option_list[$id_address][$key]['total_price_without_tax']; + if ($id_address == 0) + continue; + if ($useTax) + $total_shipping += $delivery_option_list[$id_address][$key]['total_price_with_tax']; + else + $total_shipping += $delivery_option_list[$id_address][$key]['total_price_without_tax']; } return $total_shipping; } diff --git a/controllers/front/OrderOpcController.php b/controllers/front/OrderOpcController.php index 9eddbd427..c2c3cbd67 100644 --- a/controllers/front/OrderOpcController.php +++ b/controllers/front/OrderOpcController.php @@ -202,15 +202,35 @@ class OrderOpcControllerCore extends ParentOrderController } die(Tools::displayError()); break; + case 'multishipping': + $this->_assignSummaryInformations(); + if ($this->context->customer->id) + $this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id)); + else + $this->context->smarty->assign('address_list', array()); + $this->setTemplate(_PS_THEME_DIR_.'order-address-multishipping-products.tpl'); + $this->display(); + die(); + case 'cartReload': + $this->_assignSummaryInformations(); + if ($this->context->customer->id) + $this->context->smarty->assign('address_list', $this->context->customer->getAddresses($this->context->language->id)); + else + $this->context->smarty->assign('address_list', array()); + $this->context->smarty->assign('opc', true); + $this->setTemplate(_PS_THEME_DIR_.'shopping-cart.tpl'); + $this->display(); + die(); default: - exit; + throw new PrestashopException('Unknown method "'.Tools::getValue('method').'"'); } } - exit; + else + throw new PrestashopException('Method is not defined'.Tools::isSubmit('method')); } } elseif (Tools::isSubmit('ajax')) - exit; + throw new PrestashopException('Method is not defined'); } public function setMedia() @@ -329,11 +349,12 @@ class OrderOpcControllerCore extends ParentOrderController { $carriers = Carrier::getCarriersForOrder(Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT'))); $this->context->smarty->assign(array( - 'checked' => $this->_setDefaultCarrierSelection($carriers), - 'carriers' => $carriers, - 'default_carrier' => (int)(Configuration::get('PS_CARRIER_DEFAULT')), 'HOOK_EXTRACARRIER' => NULL, - 'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array('carriers' => $carriers)) + 'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array( + 'carriers' => $carriers, + 'delivery_option_list' => $this->context->cart->getDeliveryOptionList(), + 'delivery_option' => $this->context->cart->getDeliveryOption() + )) )); } else @@ -404,9 +425,11 @@ class OrderOpcControllerCore extends ParentOrderController { $carriers = Carrier::getCarriersForOrder((int)Address::getZoneById((int)($address_delivery->id)), $groups); $result = array( - 'checked' => $this->_setDefaultCarrierSelection($carriers), - 'carriers' => $carriers, - 'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array('carriers' => $carriers)), + 'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array( + 'carriers' => $carriers, + 'delivery_option_list' => $this->context->cart->getDeliveryOptionList(), + 'delivery_option' => $this->context->cart->getDeliveryOption() + )), 'HOOK_EXTRACARRIER' => Hook::exec('extraCarrier', array('address' => $address_delivery)) ); return $result; diff --git a/controllers/front/ParentOrderController.php b/controllers/front/ParentOrderController.php index b02e3456c..b0054171e 100644 --- a/controllers/front/ParentOrderController.php +++ b/controllers/front/ParentOrderController.php @@ -379,18 +379,18 @@ class ParentOrderControllerCore extends FrontController $id_zone = Address::getZoneById($address->id); $carriers = Carrier::getCarriersForOrder($id_zone, $this->context->customer->getGroups()); - $this->context->smarty->assign(array( - 'checked' => $this->setDefaultCarrierSelection($carriers), - 'carriers' => $carriers, 'address_collection' => $this->context->cart->getAddressCollection(), 'delivery_option_list' => $this->context->cart->getDeliveryOptionList(), - 'delivery_option' => $this->context->cart->getDeliveryOption(), - 'default_carrier' => (int)(Configuration::get('PS_CARRIER_DEFAULT')) + 'delivery_option' => $this->context->cart->getDeliveryOption() )); $this->context->smarty->assign(array( 'HOOK_EXTRACARRIER' => Hook::exec('extraCarrier', array('address' => $address)), - 'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array('carriers' => $carriers)) + 'HOOK_BEFORECARRIER' => Hook::exec('beforeCarrier', array( + 'carriers' => $carriers, + 'delivery_option_list' => $this->context->cart->getDeliveryOptionList(), + 'delivery_option' => $this->context->cart->getDeliveryOption() + )) )); } diff --git a/modules/blockcart/blockcart.php b/modules/blockcart/blockcart.php index e41bbbca0..b2e6a9994 100644 --- a/modules/blockcart/blockcart.php +++ b/modules/blockcart/blockcart.php @@ -93,7 +93,6 @@ class BlockCart extends Module 'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency), 'product_total' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING), $currency), 'total' => Tools::displayPrice($totalToPay, $currency), - 'id_carrier' => (int)($params['cart']->id_carrier), 'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order', 'ajax_allowed' => (int)(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false )); diff --git a/themes/prestashop/js/order-opc.js b/themes/prestashop/js/order-opc.js index 060cdd23d..f81e0746a 100755 --- a/themes/prestashop/js/order-opc.js +++ b/themes/prestashop/js/order-opc.js @@ -734,3 +734,48 @@ $(function() { }); }); + +function multishippingMode(it) +{ + if (!$(it).hasClass('on')) + { + $('#address_delivery').hide(); + $('#address_invoice').removeClass('alternate_item').addClass('item'); + $(it).addClass('on'); + $('#link_multishipping_form').show(); + + $('#link_multishipping_form').fancybox({ + 'transitionIn' : 'elastic', + 'transitionOut' : 'elastic', + 'type' : 'ajax', + 'onClosed' : function() + { + // Relaod the cart + $.ajax({ + url: orderOpcUrl, + data: 'ajax=true&method=cartReload', + dataType : 'html', + success: function(data) { + $('#cart_summary').replaceWith($(data).find('#cart_summary')); + } + }) + updateCarrierSelectionAndGift(); + }, + 'onStart' : function() + { + // Removing all ids on the cart to avoid conflic with the new one on the fancybox + // This action could "break" the cart design, if css rules use ids of the cart + $.each($('#cart_summary *'), function(it, el) { + $(el).attr('id', ''); + }); + } + }); + } + else + { + $('#address_delivery').show(); + $('#address_invoice').removeClass('item').addClass('alternate_item'); + $(it).removeClass('on'); + $('#link_multishipping_form').hide(); + } +} diff --git a/themes/prestashop/order-address-multishipping-products.tpl b/themes/prestashop/order-address-multishipping-products.tpl new file mode 100644 index 000000000..5644b15ef --- /dev/null +++ b/themes/prestashop/order-address-multishipping-products.tpl @@ -0,0 +1,101 @@ +{* +* 2007-2011 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-2011 PrestaShop SA +* @version Release: $Revision$ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +

{l s='Choose the delivery addresses:'}

+ +
+ + + + + + + + + + + + {foreach from=$products item=product name=productLoop} + {assign var='productId' value=$product.id_product} + {assign var='productAttributeId' value=$product.id_product_attribute} + {assign var='quantityDisplayed' value=0} + {* Display the product line *} + {include file="$tpl_dir./order-address-product-line.tpl" productLast=$smarty.foreach.productLoop.last productFirst=$smarty.foreach.productLoop.first} + {* Then the customized datas ones*} + {if isset($customizedDatas.$productId.$productAttributeId)} + {foreach from=$customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] key='id_customization' item='customization'} + + + + + + {assign var='quantityDisplayed' value=$quantityDisplayed+$customization.quantity} + {/foreach} + {* If it exists also some uncustomized products *} + {if $product.quantity-$quantityDisplayed > 0} + {include file="$tpl_dir./order-address-product-line.tpl" productLast=$smarty.foreach.productLoop.last productFirst=$smarty.foreach.productLoop.first} + {/if} + + {/if} + {/foreach} + +
{l s='Product'}{l s='Description'}{l s='Ref.'}{l s='Qty'}{l s='Shipping address'}
+ {foreach from=$customization.datas key='type' item='datas'} + {if $type == $CUSTOMIZE_FILE} +
+
    + {foreach from=$datas item='picture'}
  • {/foreach} +
+
+ {elseif $type == $CUSTOMIZE_TEXTFIELD} +
    + {foreach from=$datas item='textField' name='typedText'}
  • {if $textField.name}{$textField.name}{else}{l s='Text #'}{$smarty.foreach.typedText.index+1}{/if}{l s=':'} {$textField.value}
  • {/foreach} +
+ {/if} + {/foreach} +
+ {if isset($cannotModify) AND $cannotModify == 1} + {if $quantityDisplayed == 0 AND isset($customizedDatas.$productId.$productAttributeId)}{$customizedDatas.$productId.$productAttributeId|@count}{else}{$product.cart_quantity-$quantityDisplayed}{/if} + {else} +
+ {l s='Delete'} +
+
+ {l s='Add'}
+ {if $product.minimal_quantity < ($customization.quantity -$quantityDisplayed) OR $product.minimal_quantity <= 1} + + {l s='Subtract'} + + {else} + + {l s='Subtract'} + + {/if} +
+ + + {/if} +
+
diff --git a/themes/prestashop/order-address-multishipping.tpl b/themes/prestashop/order-address-multishipping.tpl index 870bc07ee..eb6dc1467 100644 --- a/themes/prestashop/order-address-multishipping.tpl +++ b/themes/prestashop/order-address-multishipping.tpl @@ -152,82 +152,7 @@ {include file="$tpl_dir./order-steps.tpl"} {include file="$tpl_dir./errors.tpl"} -

{l s='Choose the delivery addresses:'}

- -
- - - - - - - - - - - - {foreach from=$products item=product name=productLoop} - {assign var='productId' value=$product.id_product} - {assign var='productAttributeId' value=$product.id_product_attribute} - {assign var='quantityDisplayed' value=0} - {* Display the product line *} - {include file="$tpl_dir./order-address-product-line.tpl" productLast=$smarty.foreach.productLoop.last productFirst=$smarty.foreach.productLoop.first} - {* Then the customized datas ones*} - {if isset($customizedDatas.$productId.$productAttributeId)} - {foreach from=$customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] key='id_customization' item='customization'} - - - - - - {assign var='quantityDisplayed' value=$quantityDisplayed+$customization.quantity} - {/foreach} - {* If it exists also some uncustomized products *} - {if $product.quantity-$quantityDisplayed > 0} - {include file="$tpl_dir./order-address-product-line.tpl" productLast=$smarty.foreach.productLoop.last productFirst=$smarty.foreach.productLoop.first} - {/if} - - {/if} - {/foreach} - -
{l s='Product'}{l s='Description'}{l s='Ref.'}{l s='Qty'}{l s='Shipping address'}
- {foreach from=$customization.datas key='type' item='datas'} - {if $type == $CUSTOMIZE_FILE} -
-
    - {foreach from=$datas item='picture'}
  • {/foreach} -
-
- {elseif $type == $CUSTOMIZE_TEXTFIELD} -
    - {foreach from=$datas item='textField' name='typedText'}
  • {if $textField.name}{$textField.name}{else}{l s='Text #'}{$smarty.foreach.typedText.index+1}{/if}{l s=':'} {$textField.value}
  • {/foreach} -
- {/if} - {/foreach} -
- {if isset($cannotModify) AND $cannotModify == 1} - {if $quantityDisplayed == 0 AND isset($customizedDatas.$productId.$productAttributeId)}{$customizedDatas.$productId.$productAttributeId|@count}{else}{$product.cart_quantity-$quantityDisplayed}{/if} - {else} -
- {l s='Delete'} -
-
- {l s='Add'}
- {if $product.minimal_quantity < ($customization.quantity -$quantityDisplayed) OR $product.minimal_quantity <= 1} - - {l s='Subtract'} - - {else} - - {l s='Subtract'} - - {/if} -
- - - {/if} -
-
+{include file="$tpl_dir./order-address-multishipping-products.tpl"}
{else} diff --git a/themes/prestashop/order-address.tpl b/themes/prestashop/order-address.tpl index bc38a041f..7e6690eac 100644 --- a/themes/prestashop/order-address.tpl +++ b/themes/prestashop/order-address.tpl @@ -171,6 +171,14 @@ {else} +
{/if} diff --git a/themes/prestashop/order-carrier.tpl b/themes/prestashop/order-carrier.tpl index 6a196c335..d491760c5 100644 --- a/themes/prestashop/order-carrier.tpl +++ b/themes/prestashop/order-carrier.tpl @@ -113,81 +113,83 @@

{/if}
- {foreach $delivery_option_list as $id_address => $option_list} -

{$address_collection[$id_address]->alias}

-
- {foreach $option_list as $key => $option} -
- - +
+ {/foreach}
{/foreach} -
- {/foreach} + {/if}