// Fix some problems with multishipping

This commit is contained in:
mDeflotte
2011-12-21 16:27:02 +00:00
parent 39ba22dc81
commit d272c59c32
4 changed files with 127 additions and 124 deletions
+3
View File
@@ -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`
+16 -21
View File
@@ -736,6 +736,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;
@@ -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)
return; if (!$id_address_delivery)
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;
+95 -95
View File
@@ -200,10 +200,10 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Return customers list * Return customers list
* *
* @return array Customers * @return array Customers
*/ */
public static function getCustomers(Shop $shop = null) public static function getCustomers(Shop $shop = null)
{ {
if (!$shop) if (!$shop)
@@ -217,21 +217,21 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Return customer instance from its e-mail (optionnaly check password) * Return customer instance from its e-mail (optionnaly check password)
* *
* @param string $email e-mail * @param string $email e-mail
* @param string $passwd Password is also checked if specified * @param string $passwd Password is also checked if specified
* @return Customer instance * @return Customer instance
*/ */
public function getByEmail($email, $passwd = null, Shop $shop = null) public function getByEmail($email, $passwd = null, Shop $shop = null)
{ {
if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd))) if (!Validate::isEmail($email) || ($passwd && !Validate::isPasswd($passwd)))
die (Tools::displayError()); die (Tools::displayError());
if (!$shop) if (!$shop)
$shop = Context::getContext()->shop; $shop = Context::getContext()->shop;
$sql = 'SELECT * $sql = 'SELECT *
FROM `'._DB_PREFIX_.'customer` FROM `'._DB_PREFIX_.'customer`
WHERE `active` = 1 WHERE `active` = 1
AND `email` = \''.pSQL($email).'\' AND `email` = \''.pSQL($email).'\'
@@ -252,13 +252,13 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Check id the customer is active or not * Check id the customer is active or not
* *
* @return boolean customer validity * @return boolean customer validity
*/ */
public static function isBanned($id_customer) public static function isBanned($id_customer)
{ {
if (!Validate::isUnsignedId($id_customer)) if (!Validate::isUnsignedId($id_customer))
return true; return true;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT `id_customer` SELECT `id_customer`
@@ -268,26 +268,26 @@ class CustomerCore extends ObjectModel
AND `deleted` = 0'); AND `deleted` = 0');
if (isset($result['id_customer'])) if (isset($result['id_customer']))
return false; return false;
return true; return true;
} }
/** /**
* Check if e-mail is already registered in database * Check if e-mail is already registered in database
* *
* @param string $email e-mail * @param string $email e-mail
* @param $return_id boolean * @param $return_id boolean
* @param $ignore_guest boolean, to exclude guest customer * @param $ignore_guest boolean, to exclude guest customer
* @return Customer ID if found, false otherwise * @return Customer ID if found, false otherwise
*/ */
public static function customerExists($email, $return_id = false, $ignore_guest = true, Shop $shop = null) public static function customerExists($email, $return_id = false, $ignore_guest = true, Shop $shop = null)
{ {
if (!Validate::isEmail($email)) if (!Validate::isEmail($email))
die (Tools::displayError()); die (Tools::displayError());
if (!$shop) if (!$shop)
$shop = Context::getContext()->shop; $shop = Context::getContext()->shop;
$sql = 'SELECT `id_customer` $sql = 'SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer` FROM `'._DB_PREFIX_.'customer`
WHERE `email` = \''.pSQL($email).'\' WHERE `email` = \''.pSQL($email).'\'
'.$shop->addSqlRestriction(Shop::SHARE_CUSTOMER). '.$shop->addSqlRestriction(Shop::SHARE_CUSTOMER).
@@ -300,12 +300,12 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Check if an address is owned by a customer * Check if an address is owned by a customer
* *
* @param integer $id_customer Customer ID * @param integer $id_customer Customer ID
* @param integer $id_address Address ID * @param integer $id_address Address ID
* @return boolean result * @return boolean result
*/ */
public static function customerHasAddress($id_customer, $id_address) public static function customerHasAddress($id_customer, $id_address)
{ {
if (!array_key_exists($id_customer, self::$_customerHasAddress)) if (!array_key_exists($id_customer, self::$_customerHasAddress))
@@ -327,11 +327,11 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Return customer addresses * Return customer addresses
* *
* @param integer $id_lang Language ID * @param integer $id_lang Language ID
* @return array Addresses * @return array Addresses
*/ */
public function getAddresses($id_lang) public function getAddresses($id_lang)
{ {
$sql = 'SELECT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso $sql = 'SELECT a.*, cl.`name` AS country, s.name AS state, s.iso_code AS state_iso
@@ -344,11 +344,11 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Count the number of addresses for a customer * Count the number of addresses for a customer
* *
* @param integer $id_customer Customer ID * @param integer $id_customer Customer ID
* @return integer Number of addresses * @return integer Number of addresses
*/ */
public static function getAddressesTotalById($id_customer) public static function getAddressesTotalById($id_customer)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
@@ -360,17 +360,17 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Check if customer password is the right one * Check if customer password is the right one
* *
* @param string $passwd Password * @param string $passwd Password
* @return boolean result * @return boolean result
*/ */
public static function checkPassword($id_customer, $passwd) public static function checkPassword($id_customer, $passwd)
{ {
if (!Validate::isUnsignedId($id_customer) || !Validate::isMd5($passwd)) if (!Validate::isUnsignedId($id_customer) || !Validate::isMd5($passwd))
die (Tools::displayError()); die (Tools::displayError());
$sql = 'SELECT `id_customer` $sql = 'SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer` FROM `'._DB_PREFIX_.'customer`
WHERE `id_customer` = '.$id_customer.' WHERE `id_customer` = '.$id_customer.'
AND `passwd` = \''.$passwd.'\''; AND `passwd` = \''.$passwd.'\'';
@@ -378,11 +378,11 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Light back office search for customers * Light back office search for customers
* *
* @param string $query Searched string * @param string $query Searched string
* @return array Corresponding customers * @return array Corresponding customers
*/ */
public static function searchByName($query, Shop $shop = null) public static function searchByName($query, Shop $shop = null)
{ {
if (!$shop) if (!$shop)
@@ -400,10 +400,10 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Search for customers by ip address * Search for customers by ip address
* *
* @param string $ip Searched string * @param string $ip Searched string
*/ */
public static function searchByIp($ip) public static function searchByIp($ip)
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
@@ -415,10 +415,10 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Return several useful statistics about customer * Return several useful statistics about customer
* *
* @return array Stats * @return array Stats
*/ */
public function getStats() public function getStats()
{ {
$result = Db::getInstance()->getRow(' $result = Db::getInstance()->getRow('
@@ -445,15 +445,15 @@ class CustomerCore extends ObjectModel
public function getLastConnections() public function getLastConnections()
{ {
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS(' return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT c.date_add, COUNT(cp.id_page) AS pages, TIMEDIFF(MAX(cp.time_end), c.date_add) as time, http_referer,INET_NTOA(ip_address) as ipaddress SELECT c.date_add, COUNT(cp.id_page) AS pages, TIMEDIFF(MAX(cp.time_end), c.date_add) as time, http_referer,INET_NTOA(ip_address) as ipaddress
FROM `'._DB_PREFIX_.'guest` g FROM `'._DB_PREFIX_.'guest` g
LEFT JOIN `'._DB_PREFIX_.'connections` c ON c.id_guest = g.id_guest LEFT JOIN `'._DB_PREFIX_.'connections` c ON c.id_guest = g.id_guest
LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections LEFT JOIN `'._DB_PREFIX_.'connections_page` cp ON c.id_connections = cp.id_connections
WHERE g.`id_customer` = '.(int)$this->id.' WHERE g.`id_customer` = '.(int)$this->id.'
GROUP BY c.`id_connections` GROUP BY c.`id_connections`
ORDER BY c.date_add DESC ORDER BY c.date_add DESC
LIMIT 10'); LIMIT 10');
} }
/* /*
@@ -612,8 +612,8 @@ class CustomerCore extends ObjectModel
$vars = array( $vars = array(
'{firstname}' => $this->firstname, '{firstname}' => $this->firstname,
'{lastname}' => $this->lastname, '{lastname}' => $this->lastname,
'{email}' => $this->email, '{email}' => $this->email,
'{passwd}' => $password '{passwd}' => $password
); );
Mail::Send( Mail::Send(
@@ -642,28 +642,28 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Check customer informations and return customer validity * Check customer informations and return customer validity
* *
* @since 1.5.0 * @since 1.5.0
* @param boolean $with_guest * @param boolean $with_guest
* @return boolean customer validity * @return boolean customer validity
*/ */
public function isLogged($with_guest = false) public function isLogged($with_guest = false)
{ {
if (!$with_guest && $this->is_guest == 1) if (!$with_guest && $this->is_guest == 1)
return false; return false;
/* Customer is valid only if it can be load and if object password is the same as database one */ /* Customer is valid only if it can be load and if object password is the same as database one */
if ($this->logged == 1 && $this->id && Validate::isUnsignedId($this->id) && self::checkPassword($this->id, $this->passwd)) if ($this->logged == 1 && $this->id && Validate::isUnsignedId($this->id) && self::checkPassword($this->id, $this->passwd))
return true; return true;
return false; return false;
} }
/** /**
* Logout * Logout
* *
* @since 1.5.0 * @since 1.5.0
*/ */
public function logout() public function logout()
{ {
if (isset(Context::getContext()->cookie)) if (isset(Context::getContext()->cookie))
@@ -672,11 +672,11 @@ class CustomerCore extends ObjectModel
} }
/** /**
* Soft logout, delete everything links to the customer * Soft logout, delete everything links to the customer
* but leave there affiliate's informations * but leave there affiliate's informations
* *
* @since 1.5.0 * @since 1.5.0
*/ */
public function mylogout() public function mylogout()
{ {
if (isset(Context::getContext()->cookie)) if (isset(Context::getContext()->cookie))
+13 -8
View File
@@ -294,17 +294,22 @@ 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');