// Fix some problems with multishipping
This commit is contained in:
1 parent
39ba22dc81
commit
d272c59c32
3 files changed
+30
-27
No files matched your search
@@ -294,6 +294,9 @@ class AddressCore extends ObjectModel
|
|||||||
|
|
||||||
public static function getFirstCustomerAddressId($id_customer, $active = true)
|
public static function getFirstCustomerAddressId($id_customer, $active = true)
|
||||||
{
|
{
|
||||||
|
if (!$id_customer)
|
||||||
|
return false;
|
||||||
|
|
||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||||
SELECT `id_address`
|
SELECT `id_address`
|
||||||
FROM `'._DB_PREFIX_.'address`
|
FROM `'._DB_PREFIX_.'address`
|
||||||
|
|||||||
+14
-19
@@ -737,6 +737,14 @@ class CartCore extends ObjectModel
|
|||||||
if (!$shop)
|
if (!$shop)
|
||||||
$shop = Context::getContext()->shop;
|
$shop = Context::getContext()->shop;
|
||||||
|
|
||||||
|
if (Context::getContext()->customer->id)
|
||||||
|
{
|
||||||
|
if ($id_address_delivery == 0) // The $id_address_delivery is null, get the default customer address
|
||||||
|
$id_address_delivery = (int)Address::getFirstCustomerAddressId((int)Context::getContext()->customer->id);
|
||||||
|
else if (!Customer::customerHasAddress(Context::getContext()->customer->id, $id_address_delivery)) // The $id_address_delivery must be linked with customer
|
||||||
|
$id_address_delivery = 0;
|
||||||
|
}
|
||||||
|
|
||||||
$quantity = (int)$quantity;
|
$quantity = (int)$quantity;
|
||||||
$id_product = (int)$id_product;
|
$id_product = (int)$id_product;
|
||||||
$id_product_attribute = (int)$id_product_attribute;
|
$id_product_attribute = (int)$id_product_attribute;
|
||||||
@@ -2972,32 +2980,19 @@ class CartCore extends ObjectModel
|
|||||||
*/
|
*/
|
||||||
public function autosetProductAddress()
|
public function autosetProductAddress()
|
||||||
{
|
{
|
||||||
|
$id_address_delivery = 0;
|
||||||
// Get the main address of the customer
|
// Get the main address of the customer
|
||||||
if ((int)$this->id_address_delivery > 0)
|
if ((int)$this->id_address_delivery > 0)
|
||||||
$id_address_deivery = (int)$this->id_address_delivery;
|
$id_address_delivery = (int)$this->id_address_delivery;
|
||||||
else
|
else
|
||||||
{
|
$id_address_delivery = (int)Address::getFirstCustomerAddressId(Context::getContext()->customer->id);
|
||||||
if ((int)$cart->id_customer == 0)
|
|
||||||
|
if (!$id_address_delivery)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$customer = new Customer((int)$cart->id_customer);
|
|
||||||
$addresses = $customer->getAddresses(Context::getContext()->language->id);
|
|
||||||
|
|
||||||
if (count($addresses) == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
$id_address_delivery = $addresses[0]['id_address'];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
$sql = 'UPDATE `'._DB_PREFIX_.'cart_product`
|
$sql = 'UPDATE `'._DB_PREFIX_.'cart_product`
|
||||||
SET `id_address_delivery` =
|
SET `id_address_delivery` = '.(int)$id_address_delivery.'
|
||||||
(
|
|
||||||
SELECT `id_address_delivery`
|
|
||||||
FROM `'._DB_PREFIX_.'cart`
|
|
||||||
WHERE `id_cart` = '.(int)$this->id.'
|
|
||||||
AND `id_shop` = '.(int)$this->id_shop.'
|
|
||||||
)
|
|
||||||
WHERE `id_cart` = '.(int)$this->id.'
|
WHERE `id_cart` = '.(int)$this->id.'
|
||||||
AND (`id_address_delivery` = 0 OR `id_address_delivery` IS NULL)
|
AND (`id_address_delivery` = 0 OR `id_address_delivery` IS NULL)
|
||||||
AND `id_shop` = '.(int)$this->id_shop;
|
AND `id_shop` = '.(int)$this->id_shop;
|
||||||
|
|||||||
@@ -294,18 +294,23 @@ class AuthControllerCore extends FrontController
|
|||||||
$this->context->cookie->is_guest = $customer->isGuest();
|
$this->context->cookie->is_guest = $customer->isGuest();
|
||||||
$this->context->cookie->passwd = $customer->passwd;
|
$this->context->cookie->passwd = $customer->passwd;
|
||||||
$this->context->cookie->email = $customer->email;
|
$this->context->cookie->email = $customer->email;
|
||||||
if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0))
|
|
||||||
$this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);
|
|
||||||
// Update cart address
|
|
||||||
$this->context->cart->setDeliveryOption(null);
|
|
||||||
$this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
|
|
||||||
$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
|
|
||||||
$this->context->cart->secure_key = $customer->secure_key;
|
|
||||||
$this->context->cart->update();
|
|
||||||
|
|
||||||
// Add customer to the context
|
// Add customer to the context
|
||||||
$this->context->customer = $customer;
|
$this->context->customer = $customer;
|
||||||
|
|
||||||
|
if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0))
|
||||||
|
$this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id);
|
||||||
|
|
||||||
|
// Update cart address
|
||||||
|
$this->context->cart->id = $this->context->cookie->id_cart;
|
||||||
|
$this->context->cart->setDeliveryOption(null);
|
||||||
|
$this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id));
|
||||||
|
|
||||||
|
$this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id));
|
||||||
|
$this->context->cart->secure_key = $customer->secure_key;
|
||||||
|
$this->context->cart->update();
|
||||||
|
$this->context->cart->autosetProductAddress();
|
||||||
|
|
||||||
Hook::exec('authentication');
|
Hook::exec('authentication');
|
||||||
|
|
||||||
// Login information have changed, so we check if the cart rules still apply
|
// Login information have changed, so we check if the cart rules still apply
|
||||||
|
|||||||
Reference in new issue
Block a user