// Multishipping : on opc, on putting multi-shipping to off, the cart is set to one address delivery

This commit is contained in:
mDeflotte
2011-11-22 17:18:30 +00:00
parent 52c1cf43f3
commit 9c76b35ec4
5 changed files with 60 additions and 7 deletions
+15 -2
View File
@@ -1480,6 +1480,19 @@ class CartCore extends ObjectModel
return $delivery_option_list; return $delivery_option_list;
} }
/**
* Does the cart use multiple
*/
public function isMultiAddressDelivery()
{
$sql = new DbQuery();
$sql->select('count(distinct id_address_delivery)');
$sql->from('cart_product as cp');
$sql->where('id_cart = '.(int)$this->id);
return (boolean)(Db::getInstance()->getValue($sql) > 1);
}
/** /**
* Get all delivery addresses object for the current cart * Get all delivery addresses object for the current cart
*/ */
@@ -1916,7 +1929,6 @@ class CartCore extends ObjectModel
'invoice' => $invoice, 'invoice' => $invoice,
'invoice_state' => State::getNameById($invoice->id_state), 'invoice_state' => State::getNameById($invoice->id_state),
'formattedAddresses' => $formattedAddresses, 'formattedAddresses' => $formattedAddresses,
//'carrier' => new Carrier($this->id_carrier, $id_lang),
'products' => $this->getProducts(false), 'products' => $this->getProducts(false),
'discounts' => $this->getCartRules(), 'discounts' => $this->getCartRules(),
'is_virtual_cart' => (int)$this->isVirtualCart(), 'is_virtual_cart' => (int)$this->isVirtualCart(),
@@ -1930,7 +1942,8 @@ class CartCore extends ObjectModel
'total_products' => $this->getOrderTotal(false, Cart::ONLY_PRODUCTS), 'total_products' => $this->getOrderTotal(false, Cart::ONLY_PRODUCTS),
'total_price' => $this->getOrderTotal(), 'total_price' => $this->getOrderTotal(),
'total_tax' => $total_tax, 'total_tax' => $total_tax,
'total_price_without_tax' => $this->getOrderTotal(false)); 'total_price_without_tax' => $this->getOrderTotal(false),
'is_multi_address_delivery' => $this->isMultiAddressDelivery());
} }
public function checkQuantities() public function checkQuantities()
-2
View File
@@ -294,10 +294,8 @@ class AuthControllerCore extends FrontController
} }
} }
} }
elog('here???');
if ($this->ajax) if ($this->ajax)
{ {
elog(Tools::getToken(false));
$return = array( $return = array(
'hasError' => !empty($this->errors), 'hasError' => !empty($this->errors),
'errors' => $this->errors, 'errors' => $this->errors,
+9
View File
@@ -40,6 +40,9 @@ class OrderOpcControllerCore extends ParentOrderController
if ($this->nbProducts) if ($this->nbProducts)
$this->context->smarty->assign('virtual_cart', false); $this->context->smarty->assign('virtual_cart', false);
$this->context->smarty->assign('is_multi_address_delivery', $this->context->cart->isMultiAddressDelivery());
$this->isLogged = (bool)($this->context->customer->id AND Customer::customerIdExistsStatic((int)($this->context->cookie->id_customer))); $this->isLogged = (bool)($this->context->customer->id AND Customer::customerIdExistsStatic((int)($this->context->cookie->id_customer)));
if ($this->context->cart->nbProducts()) if ($this->context->cart->nbProducts())
@@ -211,6 +214,7 @@ class OrderOpcControllerCore extends ParentOrderController
$this->setTemplate(_PS_THEME_DIR_.'order-address-multishipping-products.tpl'); $this->setTemplate(_PS_THEME_DIR_.'order-address-multishipping-products.tpl');
$this->display(); $this->display();
die(); die();
break;
case 'cartReload': case 'cartReload':
$this->_assignSummaryInformations(); $this->_assignSummaryInformations();
if ($this->context->customer->id) if ($this->context->customer->id)
@@ -221,6 +225,11 @@ class OrderOpcControllerCore extends ParentOrderController
$this->setTemplate(_PS_THEME_DIR_.'shopping-cart.tpl'); $this->setTemplate(_PS_THEME_DIR_.'shopping-cart.tpl');
$this->display(); $this->display();
die(); die();
break;
case 'noMultiAddressDelivery':
$this->context->cart->setNoMultishipping();
die();
break;
default: default:
throw new PrestashopException('Unknown method "'.Tools::getValue('method').'"'); throw new PrestashopException('Unknown method "'.Tools::getValue('method').'"');
} }
+29 -3
View File
@@ -29,7 +29,7 @@ function updateCarrierList(json)
var carriers = json.carriers; var carriers = json.carriers;
/* contains all carrier available for this address */ /* contains all carrier available for this address */
if (carriers.length == 0) if (!carriers || carriers.length == 0)
{ {
checkedCarrier = 0; checkedCarrier = 0;
$('input[name=id_carrier]:checked').attr('checked', false); $('input[name=id_carrier]:checked').attr('checked', false);
@@ -750,15 +750,16 @@ function multishippingMode(it)
'type': 'ajax', 'type': 'ajax',
'onClosed': function() 'onClosed': function()
{ {
// Relaod the cart // Reload the cart
$.ajax({ $.ajax({
url: orderOpcUrl, url: orderOpcUrl,
data: 'ajax=true&method=cartReload', data: 'ajax=true&method=cartReload',
dataType : 'html', dataType : 'html',
cache: false,
success: function(data) { success: function(data) {
$('#cart_summary').replaceWith($(data).find('#cart_summary')); $('#cart_summary').replaceWith($(data).find('#cart_summary'));
} }
}) });
updateCarrierSelectionAndGift(); updateCarrierSelectionAndGift();
}, },
'onStart': function() 'onStart': function()
@@ -781,5 +782,30 @@ function multishippingMode(it)
$('#address_invoice').removeClass('item').addClass('alternate_item'); $('#address_invoice').removeClass('item').addClass('alternate_item');
$(it).removeClass('on'); $(it).removeClass('on');
$('#link_multishipping_form').hide(); $('#link_multishipping_form').hide();
// Disable multi address shipping
$.ajax({
url: orderOpcUrl,
async: false,
cache: false,
data: 'ajax=true&method=noMultiAddressDelivery',
});
// Reload the cart
$.ajax({
url: orderOpcUrl,
async: false,
cache: false,
data: 'ajax=true&method=cartReload',
dataType : 'html',
success: function(data) {
$('#cart_summary').replaceWith($(data).find('#cart_summary'));
}
});
} }
} }
$(document).ready(function() {
if (multishipping_mode)
$('#multishipping_mode').click();
});
+7
View File
@@ -178,6 +178,13 @@
<a href="{$link->getPageLink('order-opc', true, NULL, 'ajax=1&multi-shipping=1&method=multishipping')}" id="link_multishipping_form" title="{l s='Choose the delivery addresses'}" class="button exclusive" style="display:none"> <a href="{$link->getPageLink('order-opc', true, NULL, 'ajax=1&multi-shipping=1&method=multishipping')}" id="link_multishipping_form" title="{l s='Choose the delivery addresses'}" class="button exclusive" style="display:none">
{l s='Choose the delivery addresses'} {l s='Choose the delivery addresses'}
</a> </a>
<script type="text/javascript">
{if $is_multi_address_delivery}
var multishipping_mode = true;
{else}
var multishipping_mode = false;
{/if}
</script>
</div> </div>
<div id="opc_account" class="opc-main-block"> <div id="opc_account" class="opc-main-block">
<div id="opc_account-overlay" class="opc-overlay" style="display: none;"></div> <div id="opc_account-overlay" class="opc-overlay" style="display: none;"></div>