diff --git a/classes/AdminController.php b/classes/AdminController.php index 3026c7e0b..db7bd436c 100644 --- a/classes/AdminController.php +++ b/classes/AdminController.php @@ -231,6 +231,9 @@ class AdminControllerCore extends Controller /** @var instanciation of the class associated with the AdminController */ protected $object; + /** @var current object ID */ + protected $id_object; + public function __construct() { $controller = get_class($this); @@ -1696,6 +1699,8 @@ class AdminControllerCore extends Controller if (Tools::isSubmit('submitFilter'.$this->table) || $this->context->cookie->{'submitFilter'.$this->table} !== false) $this->filter = true; + $this->id_object = (int)Tools::getValue('id_'.$this->table); + /* Delete object image */ if (isset($_GET['deleteImage'])) { @@ -1733,7 +1738,7 @@ class AdminControllerCore extends Controller else if (Tools::getValue('submitAdd'.$this->table) || Tools::getValue('submitAdd'.$this->table.'AndStay')) { // case 1: updating existing entry - if ((int)(Tools::getValue('id_'.$this->table))) + if ($this->id_object) { if ($this->tabAccess['edit'] === '1') { @@ -1794,7 +1799,7 @@ class AdminControllerCore extends Controller else if (is_array($this->bulk_actions)) foreach ($this->bulk_actions as $bulk_action => $params) { - if (Tools::isSubmit('submitBulk'.$bulk_action.$this->table)) + if (Tools::isSubmit('submitBulk'.$bulk_action.$this->table) || Tools::isSubmit('submitBulk'.$bulk_action)) { $this->action = 'bulk'.$bulk_action; $this->boxes = Tools::getValue($this->table.'Box'); diff --git a/classes/Cart.php b/classes/Cart.php index d46a4c9a5..dd344de53 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1090,7 +1090,7 @@ class CartCore extends ObjectModel static $cache = false; if ($cache !== false && !$flush) return $cache; - + $product_list = $this->getProducts(); // Step 1 : Get product informations (warehouse_list and carrier_list), count warehouse // Determine the best warehouse to determine the packages @@ -1331,7 +1331,7 @@ class CartCore extends ObjectModel static $cache = false; if ($cache !== false && !$flush) return $cache; - + $delivery_option_list = array(); $carriers_price = array(); $carrier_collection = array(); @@ -1559,7 +1559,7 @@ class CartCore extends ObjectModel public function getDeliveryOption($default_country = null) { $delivery_option_list = $this->getDeliveryOptionList($default_country); - + // The delivery option was selected if (isset($this->delivery_option) && $this->delivery_option != '') { @@ -1574,7 +1574,7 @@ class CartCore extends ObjectModel if ($validated) return $delivery_option; } - + // No delivery option selected or delivery option selected is not valid, get the better for all options $delivery_option = array(); foreach ($delivery_option_list as $id_address => $options) @@ -2028,6 +2028,12 @@ class CartCore extends ObjectModel return self::$_isVirtualCart[$this->id]; } + /** + * Build cart object from provided id_order + * + * @param int $id_order + * @return Cart|bool + */ public static function getCartByOrderId($id_order) { if ($id_cart = self::getCartIdByOrderId($id_order)) diff --git a/classes/Category.php b/classes/Category.php index 1dbdf544f..837e2ce20 100644 --- a/classes/Category.php +++ b/classes/Category.php @@ -939,7 +939,6 @@ class CategoryCore extends ObjectModel return isset($row['id_category']); } - public function cleanGroups() { Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'category_group` WHERE `id_category` = '.(int)$this->id); @@ -1005,10 +1004,15 @@ class CategoryCore extends ObjectModel return false; } + /** + * Update customer groups associated to the object + * + * @param array $list groups + */ public function updateGroup($list) { $this->cleanGroups(); - if ($list && count($list)) + if ($list && !empty($list)) $this->addGroups($list); else $this->addGroups(array(1)); diff --git a/classes/Customer.php b/classes/Customer.php index 58fc0ffb9..5830e071e 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -108,6 +108,7 @@ class CustomerCore extends ObjectModel public $id_guest; protected $tables = array ('customer'); + public $groupBox; protected $fieldsRequired = array('lastname', 'passwd', 'firstname', 'email'); protected $fieldsSize = array('lastname' => 32, 'passwd' => 32, 'firstname' => 32, 'email' => 128, 'note' => 65000); @@ -125,7 +126,8 @@ class CustomerCore extends ObjectModel 'note' => 'isCleanHtml', 'is_guest' => 'isBool', 'id_shop' => 'isUnsignedId', - 'id_group_shop' => 'isUnsignedId' + 'id_group_shop' => 'isUnsignedId', + 'groupBox' => 'isArrayWithIds' ); protected $webserviceParameters = array( @@ -189,14 +191,13 @@ class CustomerCore extends ObjectModel $this->id_default_group = 2; else $this->id_default_group = 3; + /* Can't create a guest customer, if this feature is disabled */ if ($this->is_guest && !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) return false; - if (!parent::add($autodate, $null_values)) - return false; - - $row = array('id_customer' => (int)$this->id, 'id_group' => (int)$this->id_default_group); - return Db::getInstance()->AutoExecute(_DB_PREFIX_.'customer_group', $row, 'INSERT'); + $success = parent::add($autodate, $null_values); + $this->updateGroup($this->groupBox); + return $success; } public function update($nullValues = false) @@ -204,6 +205,7 @@ class CustomerCore extends ObjectModel $this->birthday = (empty($this->years) ? $this->birthday : (int)$this->years.'-'.(int)$this->months.'-'.(int)$this->days); if ($this->newsletter && !$this->newsletter_date_add) $this->newsletter_date_add = date('Y-m-d H:i:s'); + $this->updateGroup($this->groupBox); return parent::update(true); } @@ -419,7 +421,7 @@ class CustomerCore extends ObjectModel )'.$shop->addSqlRestriction(Shop::SHARE_CUSTOMER); return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } - + /** * Search for customers by ip address * @@ -499,6 +501,20 @@ class CustomerCore extends ObjectModel return isset($row['id_customer']); } + /** + * Update customer groups associated to the object + * + * @param array $list groups + */ + public function updateGroup($list) + { + $this->cleanGroups(); + if ($list && !empty($list)) + $this->addGroups($list); + else + $this->addGroups(array($this->id_default_group)); + } + public function cleanGroups() { Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customer_group` WHERE `id_customer` = '.(int)$this->id); @@ -508,19 +524,8 @@ class CustomerCore extends ObjectModel { foreach ($groups as $group) { - $groups_customers = $this->getGroups(); - if (count($groups_customers) == 0) - { - $row = array('id_customer' => (int)$this->id, 'id_group' => (int)$group); - Db::getInstance()->AutoExecute(_DB_PREFIX_.'customer_group', $row, 'INSERT'); - } - else - foreach ($groups_customers as $group_customers) - if ($group_customers != $group) - { - $row = array('id_customer' => (int)$this->id, 'id_group' => (int)$group); - Db::getInstance()->AutoExecute(_DB_PREFIX_.'customer_group', $row, 'INSERT'); - } + $row = array('id_customer' => (int)$this->id, 'id_group' => (int)$group); + Db::getInstance()->AutoExecute(_DB_PREFIX_.'customer_group', $row, 'INSERT'); } } @@ -547,8 +552,12 @@ class CustomerCore extends ObjectModel return self::getGroupsStatic((int)$this->id); } + /** + * @deprecated since 1.5 + */ public function isUsed() { + Tools::displayAsDeprecated(); return false; } diff --git a/classes/FrontController.php b/classes/FrontController.php index d2b2ed11f..5ae1897ed 100755 --- a/classes/FrontController.php +++ b/classes/FrontController.php @@ -86,6 +86,8 @@ class FrontControllerCore extends Controller return; self::$initialized = true; + parent::init(); + // For compatibility with globals, DEPRECATED as of version 1.5 $css_files = $this->css_files; $js_files = $this->js_files; @@ -242,11 +244,6 @@ class FrontControllerCore extends Controller $navigationPipe = (Configuration::get('PS_NAVIGATION_PIPE') ? Configuration::get('PS_NAVIGATION_PIPE') : '>'); $this->context->smarty->assign('navigationPipe', $navigationPipe); - if (!defined('_PS_BASE_URL_')) - define('_PS_BASE_URL_', Tools::getShopDomain(true)); - if (!defined('_PS_BASE_URL_SSL_')) - define('_PS_BASE_URL_SSL_', Tools::getShopDomainSsl(true)); - // Automatically redirect to the canonical URL if needed if (isset($this->php_self) && !empty($this->php_self) && !Tools::getValue('ajax')) $this->canonicalRedirection($this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id)); diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 532d66baf..c0496ac91 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -27,6 +27,8 @@ class AdminCustomersControllerCore extends AdminController { + protected $delete_mode; + public function __construct() { $this->table = 'customer'; @@ -34,6 +36,11 @@ class AdminCustomersControllerCore extends AdminController $this->lang = false; $this->deleted = true; + $this->addRowAction('edit'); + $this->addRowAction('view'); + $this->addRowAction('delete'); + $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); + $this->context = Context::getContext(); $this->default_form_language = $this->context->language->id; @@ -142,14 +149,41 @@ class AdminCustomersControllerCore extends AdminController parent::__construct(); } + public function initContent() + { + if ($this->action == 'select_delete') + $this->context->smarty->assign(array( + 'delete_form' => true, + 'url_delete' => htmlentities($_SERVER['REQUEST_URI']), + 'boxes' => $this->boxes, + )); + parent::initContent(); + } + + public function initProcess() + { + $this->id_object = Tools::getValue('id_'.$this->table); + if (Tools::isSubmit('submitGuestToCustomer') && $this->id_object) + if ($this->tabAccess['edit'] === '1') + $this->action = 'guest_to_customer'; + else + $this->_errors[] = Tools::displayError('You do not have permission to edit here.'); + elseif (Tools::isSubmit('changeNewsletterVal') && $this->id_object) + $this->action = 'change_newsletter_val'; + elseif (Tools::isSubmit('changeOptinVal') && $this->id_object) + $this->action = 'change_optin_val'; + + parent::initProcess(); + // When deleting, first display a form to select the type of deletion + if ($this->action == 'delete' || $this->action == 'bulkdelete') + if (Tools::getValue('deleteMode') == 'real' || Tools::getValue('deleteMode') == 'deleted') + $this->delete_mode = Tools::getValue('deleteMode'); + else + $this->action = 'select_delete'; + } + public function initList() { - $this->addRowAction('edit'); - $this->addRowAction('view'); - $this->addRowAction('delete'); - - $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); - $this->_select = '(YEAR(CURRENT_DATE)-YEAR(`birthday`)) - (RIGHT(CURRENT_DATE, 5) < RIGHT(birthday, 5)) AS `age`, ( SELECT c.date_add FROM '._DB_PREFIX_.'guest g LEFT JOIN '._DB_PREFIX_.'connections c ON c.id_guest = g.id_guest @@ -546,211 +580,132 @@ class AdminCustomersControllerCore extends AdminController return parent::initView(); } - public function postProcess() + public function processDelete($token) { - /** - * Todo : Where it's used? - */ - if (Tools::isSubmit('submitDel'.$this->table) || Tools::isSubmit('delete'.$this->table)) + if ($this->delete_mode == 'real') { - $delete_form = ' -
-