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

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10458 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
mDeflotte
2011-11-22 17:18:30 +00:00
parent 4dc0ebb2de
commit 5532f12d80
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;
}
/**
* 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
*/
@@ -1916,7 +1929,6 @@ class CartCore extends ObjectModel
'invoice' => $invoice,
'invoice_state' => State::getNameById($invoice->id_state),
'formattedAddresses' => $formattedAddresses,
//'carrier' => new Carrier($this->id_carrier, $id_lang),
'products' => $this->getProducts(false),
'discounts' => $this->getCartRules(),
'is_virtual_cart' => (int)$this->isVirtualCart(),
@@ -1930,7 +1942,8 @@ class CartCore extends ObjectModel
'total_products' => $this->getOrderTotal(false, Cart::ONLY_PRODUCTS),
'total_price' => $this->getOrderTotal(),
'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()
-2
View File
@@ -294,10 +294,8 @@ class AuthControllerCore extends FrontController
}
}
}
elog('here???');
if ($this->ajax)
{
elog(Tools::getToken(false));
$return = array(
'hasError' => !empty($this->errors),
'errors' => $this->errors,
+9
View File
@@ -40,6 +40,9 @@ class OrderOpcControllerCore extends ParentOrderController
if ($this->nbProducts)
$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)));
if ($this->context->cart->nbProducts())
@@ -211,6 +214,7 @@ class OrderOpcControllerCore extends ParentOrderController
$this->setTemplate(_PS_THEME_DIR_.'order-address-multishipping-products.tpl');
$this->display();
die();
break;
case 'cartReload':
$this->_assignSummaryInformations();
if ($this->context->customer->id)
@@ -221,6 +225,11 @@ class OrderOpcControllerCore extends ParentOrderController
$this->setTemplate(_PS_THEME_DIR_.'shopping-cart.tpl');
$this->display();
die();
break;
case 'noMultiAddressDelivery':
$this->context->cart->setNoMultishipping();
die();
break;
default:
throw new PrestashopException('Unknown method "'.Tools::getValue('method').'"');
}
+29 -3
View File
@@ -29,7 +29,7 @@ function updateCarrierList(json)
var carriers = json.carriers;
/* contains all carrier available for this address */
if (carriers.length == 0)
if (!carriers || carriers.length == 0)
{
checkedCarrier = 0;
$('input[name=id_carrier]:checked').attr('checked', false);
@@ -750,15 +750,16 @@ function multishippingMode(it)
'type': 'ajax',
'onClosed': function()
{
// Relaod the cart
// Reload the cart
$.ajax({
url: orderOpcUrl,
data: 'ajax=true&method=cartReload',
dataType : 'html',
cache: false,
success: function(data) {
$('#cart_summary').replaceWith($(data).find('#cart_summary'));
}
})
});
updateCarrierSelectionAndGift();
},
'onStart': function()
@@ -781,5 +782,30 @@ function multishippingMode(it)
$('#address_invoice').removeClass('item').addClass('alternate_item');
$(it).removeClass('on');
$('#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">
{l s='Choose the delivery addresses'}
</a>
<script type="text/javascript">
{if $is_multi_address_delivery}
var multishipping_mode = true;
{else}
var multishipping_mode = false;
{/if}
</script>
</div>
<div id="opc_account" class="opc-main-block">
<div id="opc_account-overlay" class="opc-overlay" style="display: none;"></div>