diff --git a/classes/Cart.php b/classes/Cart.php index 1a6455501..d582de72c 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -84,8 +84,20 @@ class CartCore extends ObjectModel protected static $_nbProducts = array(); protected static $_isVirtualCart = array(); - - + protected $fieldsRequired = array('id_currency', 'id_lang'); + protected $fieldsValidate = array( + 'id_address_delivery' => 'isUnsignedId', + 'id_carrier' => 'isUnsignedId', + 'id_address_invoice' => 'isUnsignedId', + 'id_currency' => 'isUnsignedId', + 'id_customer' => 'isUnsignedId', + 'id_guest' => 'isUnsignedId', + 'id_lang' => 'isUnsignedId', + 'recyclable' => 'isBool', + 'gift' => 'isBool', + 'gift_message' => 'isMessage', + 'allow_seperated_package' => 'isBool' + ); protected $_products = null; protected static $_totalWeight = array(); @@ -94,31 +106,9 @@ class CartCore extends ObjectModel protected static $_taxes_rate = null; protected static $_attributesLists = array(); - /** - * @see ObjectModel::$definition - */ public static $definition = array( 'table' => 'cart', 'primary' => 'id_cart', - 'fields' => array( - 'id_group_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_address_delivery' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_address_invoice' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_carrier' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_currency' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), - 'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_guest' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId'), - 'id_lang' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), - 'recyclable' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), - 'gift' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), - 'gift_message' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage'), - 'delivery_option' => array('type' => self::TYPE_STRING), - 'secure_key' => array('type' => self::TYPE_STRING, 'size' => 32), - 'allow_seperated_package' =>array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), - 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'), - 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDateFormat'), - ), ); protected $webserviceParameters = array( @@ -148,6 +138,32 @@ class CartCore extends ObjectModel const ONLY_WRAPPING = 6; const ONLY_PRODUCTS_WITHOUT_SHIPPING = 7; + public function getFields() + { + $this->validateFields(); + + $fields['id_group_shop'] = (int)$this->id_group_shop; + $fields['id_shop'] = (int)$this->id_shop; + + $fields['id_address_delivery'] = (int)$this->id_address_delivery; + $fields['id_address_invoice'] = (int)$this->id_address_invoice; + $fields['id_currency'] = (int)$this->id_currency; + $fields['id_customer'] = (int)$this->id_customer; + $fields['id_carrier'] = (int)$this->id_carrier; + $fields['id_guest'] = (int)$this->id_guest; + $fields['id_lang'] = (int)$this->id_lang; + $fields['recyclable'] = (int)$this->recyclable; + $fields['gift'] = (int)$this->gift; + $fields['secure_key'] = pSQL($this->secure_key); + $fields['gift_message'] = pSQL($this->gift_message); + $fields['date_add'] = pSQL($this->date_add); + $fields['date_upd'] = pSQL($this->date_upd); + $fields['allow_seperated_package'] = (int)$this->allow_seperated_package; + $fields['delivery_option'] = $this->delivery_option; + + return $fields; + } + public function __construct($id = null, $id_lang = null) { parent::__construct($id, $id_lang); @@ -171,8 +187,7 @@ class CartCore extends ObjectModel { if (!$this->id_lang) $this->id_lang = Configuration::get('PS_LANG_DEFAULT'); - if (Context::getContext()->shop->getGroup()->share_order == true) - $this->id_shop = null; + $return = parent::add($autodate); Hook::exec('cart'); @@ -186,8 +201,7 @@ class CartCore extends ObjectModel if (isset(self::$_totalWeight[$this->id])) unset(self::$_totalWeight[$this->id]); - if (Context::getContext()->shop->getGroup()->share_order == true) - $this->id_shop = null; + $this->_products = null; $return = parent::update(); Hook::exec('cart'); diff --git a/classes/Customer.php b/classes/Customer.php index 09550fd60..620408b63 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -187,10 +187,7 @@ class CustomerCore extends ObjectModel public function add($autodate = true, $null_values = true) { - if (Context::getContext()->shop->getGroup()->share_customer == true) - $this->id_shop = null; - else - $this->id_shop = ($this->id_shop) ? $this->id_shop : Context::getContext()->shop->getID(); + $this->id_shop = ($this->id_shop) ? $this->id_shop : Context::getContext()->shop->getID(); $this->id_group_shop = ($this->id_group_shop) ? $this->id_group_shop : Context::getContext()->shop->getGroupID(); $this->birthday = (empty($this->years) ? $this->birthday : (int)$this->years.'-'.(int)$this->months.'-'.(int)$this->days); $this->secure_key = md5(uniqid(rand(), true)); diff --git a/classes/order/Order.php b/classes/order/Order.php index f1b4bd368..01c2625ba 100644 --- a/classes/order/Order.php +++ b/classes/order/Order.php @@ -298,21 +298,6 @@ class OrderCore extends ObjectModel $this->_taxCalculationMethod = Group::getDefaultPriceDisplayMethod(); } - public function add($autodate = true, $null_values = false) - { - if (Context::getContext()->shop->getGroup()->share_order == true) - $this->id_shop = null; - return parent::add($autodate); - } - - public function update($null_values = false) - { - if (Context::getContext()->shop->getGroup()->share_order == true) - $this->id_shop = null; - $return = parent::update(); - return $return; - } - public function getTaxCalculationMethod() { return (int)($this->_taxCalculationMethod); diff --git a/classes/shop/Shop.php b/classes/shop/Shop.php index cdcf0484e..b73c06ec2 100644 --- a/classes/shop/Shop.php +++ b/classes/shop/Shop.php @@ -758,13 +758,12 @@ class ShopCore extends ObjectModel } else { - if ($shop_group_id && ($share == Shop::SHARE_CUSTOMER || $share == Shop::SHARE_ORDER)) - $restriction = ' AND '.$alias.'id_group_shop = '.$shop_group_id.' AND '.$alias.'id_shop = 0'; - else if ($shop_id || $shop_group_id) + if ($shop_id || $shop_group_id) $restriction = ' AND '.$alias.'id_shop IN ('.implode(', ', $this->getListOfID($share)).') '; //else if ($share == Shop::SHARE_STOCK) // $restriction = ' AND '.$alias.'id_shop = '.$this->getID(true); } + return $restriction; }