From 2c4f27f1bef6a01a4a66ba952bb549b30f377e5e Mon Sep 17 00:00:00 2001 From: tDidierjean Date: Mon, 25 Jul 2011 15:19:39 +0000 Subject: [PATCH] // Context part 18 --- classes/Context.php | 2 +- classes/FrontController.php | 51 +++--- controllers/AddressController.php | 73 ++++---- controllers/AddressesController.php | 13 +- controllers/AttachmentController.php | 2 +- controllers/AuthController.php | 86 ++++----- controllers/BestSalesController.php | 6 +- controllers/CMSController.php | 32 ++-- controllers/CartController.php | 68 ++++---- controllers/CategoryController.php | 38 ++-- controllers/ChangeCurrencyController.php | 2 +- controllers/CompareController.php | 16 +- controllers/ContactController.php | 54 +++--- controllers/DiscountController.php | 6 +- controllers/GetFileController.php | 2 +- controllers/GuestTrackingController.php | 24 +-- controllers/HistoryController.php | 6 +- controllers/IdentityController.php | 18 +- controllers/IndexController.php | 4 +- controllers/ManufacturerController.php | 22 +-- controllers/MyAccountController.php | 6 +- controllers/NewProductsController.php | 8 +- controllers/OrderConfirmationController.php | 14 +- controllers/OrderController.php | 86 +++++---- controllers/OrderDetailController.php | 28 +-- controllers/OrderFollowController.php | 20 +-- controllers/OrderOpcController.php | 135 +++++++-------- controllers/OrderReturnController.php | 10 +- controllers/OrderSlipController.php | 4 +- controllers/PageNotFoundController.php | 2 +- controllers/ParentOrderController.php | 183 +++++++++----------- controllers/PasswordController.php | 12 +- controllers/PdfInvoiceController.php | 2 +- controllers/PricesDropController.php | 8 +- controllers/ProductController.php | 118 +++++++------ controllers/SearchController.php | 24 +-- controllers/SitemapController.php | 16 +- controllers/StoresController.php | 24 ++- controllers/SupplierController.php | 20 +-- controllers/pdfOrderReturnController.php | 2 +- controllers/pdfOrderSlipController.php | 2 +- 41 files changed, 611 insertions(+), 638 deletions(-) diff --git a/classes/Context.php b/classes/Context.php index f45186619..708f24b4f 100644 --- a/classes/Context.php +++ b/classes/Context.php @@ -108,7 +108,7 @@ class ContextCore } /** - * Clone current context ( + * Clone current context * * @return Context */ diff --git a/classes/FrontController.php b/classes/FrontController.php index cce7fecf7..04ccc41d6 100755 --- a/classes/FrontController.php +++ b/classes/FrontController.php @@ -28,6 +28,10 @@ class FrontControllerCore { public $errors = array(); + /** + * @var Context + */ + protected $context; protected static $smarty; protected static $cookie; protected static $link; @@ -76,18 +80,23 @@ class FrontControllerCore public function init() { + /* + * Globals are DEPRECATED as of version 1.5. + * Use the Context to access objects instead. + * Example: $this->context->cart + */ global $link, $cookie, $cart, $smarty, $iso, $defaultCountry; if (self::$initialized) return; self::$initialized = true; - $context = Context::getContext(); + $this->context = Context::getContext(); $protocol_link = (Configuration::get('PS_SSL_ENABLED') OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://'; $protocol_content = ((isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://'; $link = new Link($protocol_link, $protocol_content); - $context->link = $link; + $this->context->link = $link; $this->id_current_shop = Context::getContext()->shop->getID(); $this->id_current_group_shop = Context::getContext()->shop->getGroupID(); @@ -105,12 +114,12 @@ class FrontControllerCore ob_start(); $cookie = new Cookie('ps'); - $context->cookie = $cookie; + $this->context->cookie = $cookie; $protocol_link = (Configuration::get('PS_SSL_ENABLED') OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://'; $protocol_content = ((isset($useSSL) AND $useSSL AND Configuration::get('PS_SSL_ENABLED')) OR (!empty($_SERVER['HTTPS']) AND strtolower($_SERVER['HTTPS']) != 'off')) ? 'https://' : 'http://'; $link = new Link($protocol_link, $protocol_content); - $context->link = $link; + $this->context->link = $link; if ($this->auth AND !$cookie->isLogged($this->guestAllowed)) Tools::redirect('index.php?controller=authentication'.($this->authRedirection ? '&back='.$this->authRedirection : '')); @@ -219,7 +228,7 @@ class FrontControllerCore if (!Validate::isLoadedObject($language = new Language($cookie->id_lang))) $language = new Language(Configuration::get('PS_LANG_DEFAULT')); $smarty->ps_language = $language; - $context->language = $language; + $this->context->language = $language; /* get page name to display it in body id */ $pathinfo = pathinfo(__FILE__); @@ -310,7 +319,11 @@ class FrontControllerCore else $smarty->assign($assignKey, $assignValue); - // shortcuts to context objects + /* + * These shortcuts are DEPRECATED as of version 1.5. + * Use the Context to access objects instead. + * Example: $this->context->cart + */ self::$cookie = $cookie; self::$cart = $cart; self::$smarty = $smarty; @@ -345,11 +358,11 @@ class FrontControllerCore $customer->geoloc_postcode = (int)$cookie->postcode; - $context->customer = $customer; - $context->cart = $cart; - $context->currency = $currency; - $context->controller = $this; - $context->country = $defaultCountry; + $this->context->customer = $customer; + $this->context->cart = $cart; + $this->context->currency = $currency; + $this->context->controller = $this; + $this->context->country = $defaultCountry; } /* Display a maintenance page if shop is closed */ @@ -373,12 +386,11 @@ class FrontControllerCore protected function canonicalRedirection() { - $context = Context::getContext(); // Automatically redirect to the canonical URL if needed if (isset($this->php_self) AND !empty($this->php_self)) { // $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain - $canonicalURL = $context->link->getPageLink($this->php_self, $this->ssl, $context->language->id); + $canonicalURL = $this->context->link->getPageLink($this->php_self, $this->ssl, $this->context->language->id); if (!preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/i', (($this->ssl AND Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) { header('HTTP/1.0 301 Moved'); @@ -396,14 +408,12 @@ class FrontControllerCore protected function geolocationManagement($defaultCountry) { - $context = Context::getContext(); - if (!in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) { /* Check if Maxmind Database exists */ if (file_exists(_PS_GEOIP_DIR_.'GeoLiteCity.dat')) { - if (!isset($context->cookie->iso_code_country) OR (isset($context->cookie->iso_code_country) AND !in_array(strtoupper($context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))))) + if (!isset($this->context->cookie->iso_code_country) OR (isset($this->context->cookie->iso_code_country) AND !in_array(strtoupper($this->context->cookie->iso_code_country), explode(';', Configuration::get('PS_ALLOWED_COUNTRIES'))))) { include_once(_PS_GEOIP_DIR_.'geoipcity.inc'); include_once(_PS_GEOIP_DIR_.'geoipregionvars.php'); @@ -425,19 +435,19 @@ class FrontControllerCore } else { - $context->cookie->iso_code_country = strtoupper($record->country_code); + $this->context->cookie->iso_code_country = strtoupper($record->country_code); $hasBeenSet = true; } } } - if (isset($context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($context->cookie->iso_code_country)))) + if (isset($this->context->cookie->iso_code_country) && ($id_country = Country::getByIso(strtoupper($this->context->cookie->iso_code_country)))) { /* Update defaultCountry */ - if($defaultCountry->iso_code != $context->cookie->iso_code_country) + if($defaultCountry->iso_code != $this->context->cookie->iso_code_country) $defaultCountry = new Country($id_country); if (isset($hasBeenSet) AND $hasBeenSet) - $context->cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id); + $this->context->cookie->id_currency = (int)(Currency::getCurrencyInstance($defaultCountry->id_currency ? (int)$defaultCountry->id_currency : Configuration::get('PS_CURRENCY_DEFAULT'))->id); return $defaultCountry; } elseif (Configuration::get('PS_GEOLOCATION_NA_BEHAVIOR') == _PS_GEOLOCATION_NO_CATALOG_) @@ -488,7 +498,6 @@ class FrontControllerCore { if (!self::$initialized) $this->init(); - $context = Context::getContext(); // P3P Policies (http://www.w3.org/TR/2002/REC-P3P-20020416/#compact_policies) header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"'); diff --git a/controllers/AddressController.php b/controllers/AddressController.php index 2de7b0e27..78e89934e 100644 --- a/controllers/AddressController.php +++ b/controllers/AddressController.php @@ -45,18 +45,17 @@ class AddressControllerCore extends FrontController public function preProcess() { parent::preProcess(); - $context = Context::getContext(); if ($back = Tools::getValue('back')) - self::$smarty->assign('back', Tools::safeOutput($back)); + $this->context->smarty->assign('back', Tools::safeOutput($back)); if ($mod = Tools::getValue('mod')) - self::$smarty->assign('mod', Tools::safeOutput($mod)); + $this->context->smarty->assign('mod', Tools::safeOutput($mod)); if (Tools::isSubmit('ajax') AND Tools::isSubmit('type')) { if (Tools::getValue('type') == 'delivery') - $id_address = isset(self::$cart->id_address_delivery) ? (int)self::$cart->id_address_delivery : 0; + $id_address = isset($this->context->cart->id_address_delivery) ? (int)$this->context->cart->id_address_delivery : 0; elseif (Tools::getValue('type') == 'invoice') - $id_address = (isset(self::$cart->id_address_invoice) AND self::$cart->id_address_invoice != self::$cart->id_address_delivery) ? (int)self::$cart->id_address_invoice : 0; + $id_address = (isset($this->context->cart->id_address_invoice) AND $this->context->cart->id_address_invoice != $this->context->cart->id_address_delivery) ? (int)$this->context->cart->id_address_invoice : 0; else exit; } @@ -66,19 +65,19 @@ class AddressControllerCore extends FrontController if ($id_address) { $this->_address = new Address((int)$id_address); - if (Validate::isLoadedObject($this->_address) AND Customer::customerHasAddress((int)(self::$cookie->id_customer), (int)($id_address))) + if (Validate::isLoadedObject($this->_address) AND Customer::customerHasAddress($this->context->customer->id, (int)($id_address))) { if (Tools::isSubmit('delete')) { - if (self::$cart->id_address_invoice == $this->_address->id) - unset(self::$cart->id_address_invoice); - if (self::$cart->id_address_delivery == $this->_address->id) - unset(self::$cart->id_address_delivery); + if ($this->context->cart->id_address_invoice == $this->_address->id) + unset($this->context->cart->id_address_invoice); + if ($this->context->cart->id_address_delivery == $this->_address->id) + unset($this->context->cart->id_address_delivery); if ($this->_address->delete()) Tools::redirect('index.php?controller=addresses'); $this->errors[] = Tools::displayError('This address cannot be deleted.'); } - self::$smarty->assign(array('address' => $this->_address, 'id_address' => (int)$id_address)); + $this->context->smarty->assign(array('address' => $this->_address, 'id_address' => (int)$id_address)); } elseif (Tools::isSubmit('ajax')) exit; @@ -89,7 +88,7 @@ class AddressControllerCore extends FrontController { $address = new Address(); $this->errors = $address->validateControler(); - $address->id_customer = (int)(self::$cookie->id_customer); + $address->id_customer = (int)$this->context->customer->id; if (!Tools::getValue('phone') AND !Tools::getValue('phone_mobile')) $this->errors[] = Tools::displayError('You must register at least one phone number'); @@ -130,7 +129,7 @@ class AddressControllerCore extends FrontController $address->dni = NULL; if (Configuration::get('PS_TOKEN_ENABLE') == 1 AND strcmp(Tools::getToken(false), Tools::getValue('token')) AND - $context->customer->isLogged(true) === true) + $this->context->customer->isLogged(true) === true) $this->errors[] = Tools::displayError('Invalid token'); if ((int)($country->contains_states) AND !(int)($address->id_state)) @@ -144,7 +143,7 @@ class AddressControllerCore extends FrontController if (Validate::isLoadedObject($country) AND !$country->contains_states) $address->id_state = 0; $address_old = new Address((int)$id_address); - if (Validate::isLoadedObject($address_old) AND Customer::customerHasAddress((int)self::$cookie->id_customer, (int)$address_old->id)) + if (Validate::isLoadedObject($address_old) AND Customer::customerHasAddress($this->context->customer->id, (int)$address_old->id)) { if ($address_old->isUsed()) { @@ -152,18 +151,18 @@ class AddressControllerCore extends FrontController if (!Tools::isSubmit('ajax')) { $to_update = false; - if (self::$cart->id_address_invoice == $address_old->id) + if ($this->context->cart->id_address_invoice == $address_old->id) { $to_update = true; - self::$cart->id_address_invoice = 0; + $this->context->cart->id_address_invoice = 0; } - if (self::$cart->id_address_delivery == $address_old->id) + if ($this->context->cart->id_address_delivery == $address_old->id) { $to_update = true; - self::$cart->id_address_delivery = 0; + $this->context->cart->id_address_delivery = 0; } if ($to_update) - self::$cart->update(); + $this->context->cart->update(); } } else @@ -173,7 +172,7 @@ class AddressControllerCore extends FrontController } } } - elseif (self::$cookie->is_guest) + elseif ($this->context->customer->is_guest) Tools::redirect('index.php?controller=addresses'); if ($result = $address->save()) @@ -182,16 +181,16 @@ class AddressControllerCore extends FrontController if ((bool)(Tools::getValue('select_address', false)) == true OR (Tools::isSubmit('ajax') AND Tools::getValue('type') == 'invoice')) { /* This new adress is for invoice_adress, select it */ - self::$cart->id_address_invoice = (int)($address->id); - self::$cart->update(); + $this->context->cart->id_address_invoice = (int)($address->id); + $this->context->cart->update(); } if (Tools::isSubmit('ajax')) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, - 'id_address_delivery' => self::$cart->id_address_delivery, - 'id_address_invoice' => self::$cart->id_address_invoice + 'id_address_delivery' => $this->context->cart->id_address_delivery, + 'id_address_invoice' => $this->context->cart->id_address_invoice ); die(Tools::jsonEncode($return)); } @@ -202,10 +201,10 @@ class AddressControllerCore extends FrontController } elseif (!$id_address) { - if (Validate::isLoadedObject($context->customer)) + if (Validate::isLoadedObject($this->context->customer)) { - $_POST['firstname'] = $context->customer->firstname; - $_POST['lastname'] = $context->customer->lastname; + $_POST['firstname'] = $this->context->customer->firstname; + $_POST['lastname'] = $this->context->customer->lastname; } } if (Tools::isSubmit('ajax') AND sizeof($this->errors)) @@ -229,7 +228,7 @@ class AddressControllerCore extends FrontController parent::process(); /* Secure restriction for guest */ - if (self::$cookie->is_guest) + if ($this->context->customer->is_guest) Tools::redirect('index.php?controller=addresses'); if (Tools::isSubmit('id_country') AND Tools::getValue('id_country') != NULL AND is_numeric(Tools::getValue('id_country'))) @@ -245,23 +244,23 @@ class AddressControllerCore extends FrontController else $selectedCountry = (int)Configuration::get('PS_COUNTRY_DEFAULT'); - $countries = Country::getCountries((int)self::$cookie->id_lang, true); + $countries = Country::getCountries($this->context->language->id, true); $countriesList = ''; foreach ($countries AS $country) $countriesList .= ''; if ((Configuration::get('VATNUMBER_MANAGEMENT') AND file_exists(_PS_MODULE_DIR_.'vatnumber/vatnumber.php')) && VatNumber::isApplicable(Configuration::get('PS_COUNTRY_DEFAULT'))) - self::$smarty->assign('vat_display', 2); + $this->context->smarty->assign('vat_display', 2); else if(Configuration::get('VATNUMBER_MANAGEMENT')) - self::$smarty->assign('vat_display', 1); + $this->context->smarty->assign('vat_display', 1); else - self::$smarty->assign('vat_display', 0); + $this->context->smarty->assign('vat_display', 0); - self::$smarty->assign('ajaxurl', _MODULE_DIR_); + $this->context->smarty->assign('ajaxurl', _MODULE_DIR_); - self::$smarty->assign('vatnumber_ajax_call', (int)file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php')); + $this->context->smarty->assign('vatnumber_ajax_call', (int)file_exists(_PS_MODULE_DIR_.'vatnumber/ajax.php')); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'countries_list' => $countriesList, 'countries' => $countries, 'errors' => $this->errors, @@ -276,7 +275,7 @@ class AddressControllerCore extends FrontController $id_country = is_null($this->_address)? 0 : (int)$this->_address->id_country; $dlv_adr_fields = AddressFormat::getOrderedAddressFields($id_country, $split_all = true); - self::$smarty->assign('ordered_adr_fields', $dlv_adr_fields); + $this->context->smarty->assign('ordered_adr_fields', $dlv_adr_fields); } public function displayHeader() @@ -290,7 +289,7 @@ class AddressControllerCore extends FrontController parent::displayContent(); $this->_processAddressFormat(); - self::$smarty->display(_PS_THEME_DIR_.'address.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'address.tpl'); } public function displayFooter() diff --git a/controllers/AddressesController.php b/controllers/AddressesController.php index 817e003e6..aa0fc5605 100644 --- a/controllers/AddressesController.php +++ b/controllers/AddressesController.php @@ -47,18 +47,17 @@ class AddressesControllerCore extends FrontController public function process() { parent::process(); - $context = Context::getContext(); $multipleAddressesFormated = array(); $ordered_fields = array(); - $customer = $context->customer; + $customer = $this->context->customer; if (!Validate::isLoadedObject($customer)) die(Tools::displayError('Customer not found')); // Retro Compatibility Theme < 1.4.1 - self::$smarty->assign('addresses', $customer->getAddresses($context->language->id)); + $this->context->smarty->assign('addresses', $customer->getAddresses($this->context->language->id)); - $customerAddressesDetailed = $customer->getAddresses($context->language->id); + $customerAddressesDetailed = $customer->getAddresses($this->context->language->id); $total = 0; foreach($customerAddressesDetailed as $addressDetailed) @@ -81,7 +80,7 @@ class AddressesControllerCore extends FrontController if (($key = array_search('Country:name', $ordered_fields))) $ordered_fields[$key] = 'country'; - self::$smarty->assign('addresses_style', array( + $this->context->smarty->assign('addresses_style', array( 'company' => 'address_company' ,'vat_number' => 'address_company' ,'firstname' => 'address_name' @@ -95,7 +94,7 @@ class AddressesControllerCore extends FrontController ,'alias' => 'address_title' )); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'multipleAddresses' => $multipleAddressesFormated, 'ordered_fields' => $ordered_fields)); } @@ -103,7 +102,7 @@ class AddressesControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'addresses.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'addresses.tpl'); } } diff --git a/controllers/AttachmentController.php b/controllers/AttachmentController.php index 188e2320c..eec87be28 100644 --- a/controllers/AttachmentController.php +++ b/controllers/AttachmentController.php @@ -31,7 +31,7 @@ class AttachmentControllerCore extends FrontController { parent::process(); - $a = new Attachment((int)(Tools::getValue('id_attachment')), (int)(self::$cookie->id_lang)); + $a = new Attachment(Tools::getValue('id_attachment'), $this->context->language->id); if (!$a->id) Tools::redirect('index.php'); diff --git a/controllers/AuthController.php b/controllers/AuthController.php index 42f3a66ce..9c84a085d 100644 --- a/controllers/AuthController.php +++ b/controllers/AuthController.php @@ -39,13 +39,13 @@ class AuthControllerCore extends FrontController { parent::preProcess(); - if (self::$cookie->isLogged() AND !Tools::isSubmit('ajax')) + if ($this->context->customer->isLogged() AND !Tools::isSubmit('ajax')) Tools::redirect('index.php?controller=my-account'); if (Tools::getValue('create_account')) { $create_account = 1; - self::$smarty->assign('email_create', 1); + $this->context->smarty->assign('email_create', 1); } if (Tools::isSubmit('SubmitCreate')) @@ -61,7 +61,7 @@ class AuthControllerCore extends FrontController else { $create_account = 1; - self::$smarty->assign('email_create', Tools::safeOutput($email)); + $this->context->smarty->assign('email_create', Tools::safeOutput($email)); $_POST['email'] = $email; } @@ -71,7 +71,7 @@ class AuthControllerCore extends FrontController { $create_account = 1; if (Tools::isSubmit('submitAccount')) - self::$smarty->assign('email_create', 1); + $this->context->smarty->assign('email_create', 1); /* New Guest customer */ if (!Tools::getValue('is_new_customer', 1) AND !Configuration::get('PS_GUEST_CHECKOUT_ENABLED')) $this->errors[] = Tools::displayError('You cannot create a guest account.'); @@ -166,23 +166,23 @@ class AuthControllerCore extends FrontController { if (!$customer->is_guest) { - if (!Mail::Send((int)(self::$cookie->id_lang), 'account', Mail::l('Welcome!'), + if (!Mail::Send($this->context->language->id, 'account', Mail::l('Welcome!'), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => Tools::getValue('passwd')), $customer->email, $customer->firstname.' '.$customer->lastname)) $this->errors[] = Tools::displayError('Cannot send email'); } - self::$smarty->assign('confirmation', 1); - self::$cookie->id_customer = (int)($customer->id); - self::$cookie->customer_lastname = $customer->lastname; - self::$cookie->customer_firstname = $customer->firstname; - self::$cookie->passwd = $customer->passwd; - self::$cookie->logged = 1; - self::$cookie->email = $customer->email; - self::$cookie->is_guest = !Tools::getValue('is_new_customer', 1); + $this->context->smarty->assign('confirmation', 1); + $this->context->cookie->id_customer = (int)($customer->id); + $this->context->cookie->customer_lastname = $customer->lastname; + $this->context->cookie->customer_firstname = $customer->firstname; + $this->context->cookie->passwd = $customer->passwd; + $this->context->cookie->logged = 1; + $this->context->cookie->email = $customer->email; + $this->context->cookie->is_guest = !Tools::getValue('is_new_customer', 1); /* Update cart address */ - self::$cart->secure_key = $customer->secure_key; - self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); - self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); - self::$cart->update(); + $this->context->cart->secure_key = $customer->secure_key; + $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->update(); Module::hookExec('createAccount', array( '_POST' => $_POST, 'newCustomer' => $customer @@ -193,9 +193,9 @@ class AuthControllerCore extends FrontController 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'isSaved' => true, - 'id_customer' => (int)self::$cookie->id_customer, - 'id_address_delivery' => self::$cart->id_address_delivery, - 'id_address_invoice' => self::$cart->id_address_invoice, + 'id_customer' => (int)$this->context->cookie->id_customer, + 'id_address_delivery' => $this->context->cart->id_address_delivery, + 'id_address_invoice' => $this->context->cart->id_address_invoice, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); @@ -252,20 +252,20 @@ class AuthControllerCore extends FrontController } else { - self::$cookie->id_customer = (int)($customer->id); - self::$cookie->customer_lastname = $customer->lastname; - self::$cookie->customer_firstname = $customer->firstname; - self::$cookie->logged = 1; - self::$cookie->is_guest = $customer->isGuest(); - self::$cookie->passwd = $customer->passwd; - self::$cookie->email = $customer->email; - if (Configuration::get('PS_CART_FOLLOWING') AND (empty(self::$cookie->id_cart) OR Cart::getNbProducts(self::$cookie->id_cart) == 0)) - self::$cookie->id_cart = (int)Cart::lastNoneOrderedCart((int)$customer->id); + $this->context->cookie->id_customer = (int)($customer->id); + $this->context->cookie->customer_lastname = $customer->lastname; + $this->context->cookie->customer_firstname = $customer->firstname; + $this->context->cookie->logged = 1; + $this->context->cookie->is_guest = $customer->isGuest(); + $this->context->cookie->passwd = $customer->passwd; + $this->context->cookie->email = $customer->email; + if (Configuration::get('PS_CART_FOLLOWING') AND (empty($this->context->cookie->id_cart) OR Cart::getNbProducts($this->context->cookie->id_cart) == 0)) + $this->context->cookie->id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id); /* Update cart address */ - self::$cart->id_carrier = 0; - self::$cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); - self::$cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); - self::$cart->update(); + $this->context->cart->id_carrier = 0; + $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->update(); Module::hookExec('authentication'); if (!Tools::isSubmit('ajax')) { @@ -308,16 +308,16 @@ class AuthControllerCore extends FrontController }*/ if (!isset($selectedCountry)) $selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT')); - $countries = Country::getCountries((int)(self::$cookie->id_lang), true); + $countries = Country::getCountries($this->context->language->id, true); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'countries' => $countries, 'sl_country' => (isset($selectedCountry) ? $selectedCountry : 0), 'vat_management' => Configuration::get('VATNUMBER_MANAGEMENT') )); /* Call a hook to display more information on form */ - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'HOOK_CREATE_ACCOUNT_FORM' => Module::hookExec('createAccountForm'), 'HOOK_CREATE_ACCOUNT_TOP' => Module::hookExec('createAccountTop') )); @@ -335,7 +335,7 @@ class AuthControllerCore extends FrontController $selectedDays = (int)($_POST['days']); $days = Tools::dateDays(); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'years' => $years, 'sl_year' => (isset($selectedYears) ? $selectedYears : 0), 'months' => $months, @@ -343,7 +343,7 @@ class AuthControllerCore extends FrontController 'days' => $days, 'sl_day' => (isset($selectedDays) ? $selectedDays : 0) )); - self::$smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active); + $this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active); } public function setMedia() @@ -363,11 +363,11 @@ class AuthControllerCore extends FrontController $back .= (strpos($back, '?') !== false ? '&' : '?').'key='.$key; if (!empty($back)) { - self::$smarty->assign('back', Tools::safeOutput($back)); + $this->context->smarty->assign('back', Tools::safeOutput($back)); if (strpos($back, 'order.php') !== false) { - $countries = Country::getCountries((int)(self::$cookie->id_lang), true); - self::$smarty->assign(array( + $countries = Country::getCountries($this->context->language->id, true); + $this->context->smarty->assign(array( 'inOrderProcess' => true, 'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), 'sl_country' => (int)Tools::getValue('id_country', Configuration::get('PS_COUNTRY_DEFAULT')), @@ -382,7 +382,7 @@ class AuthControllerCore extends FrontController $this->processAddressFormat(); parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'authentication.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'authentication.tpl'); } protected function processAddressFormat() @@ -401,7 +401,7 @@ class AuthControllerCore extends FrontController $addressItems[] = trim($fieldName); foreach (array('inv', 'dlv') as $addressType) - self::$smarty->assign(array($addressType.'_adr_fields' => $addressFormat, $addressType.'_all_fields' => $addressItems)); + $this->context->smarty->assign(array($addressType.'_adr_fields' => $addressFormat, $addressType.'_all_fields' => $addressItems)); } } diff --git a/controllers/BestSalesController.php b/controllers/BestSalesController.php index 7b12d996e..7b50241f8 100644 --- a/controllers/BestSalesController.php +++ b/controllers/BestSalesController.php @@ -40,8 +40,8 @@ class BestSalesControllerCore extends FrontController $nbProducts = (int)ProductSale::getNbSales(); $this->pagination($nbProducts); - self::$smarty->assign(array( - 'products' => ProductSale::getBestSales((int)self::$cookie->id_lang, (int)$this->p - 1, (int)$this->n, $this->orderBy, $this->orderWay), + $this->context->smarty->assign(array( + 'products' => ProductSale::getBestSales($this->context->language->id, $this->p - 1, $this->n, $this->orderBy, $this->orderWay), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home') @@ -57,7 +57,7 @@ class BestSalesControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'best-sales.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'best-sales.tpl'); } } diff --git a/controllers/CMSController.php b/controllers/CMSController.php index aa793366b..a32f565f2 100644 --- a/controllers/CMSController.php +++ b/controllers/CMSController.php @@ -34,13 +34,13 @@ class CmsControllerCore extends FrontController public function preProcess() { if ($id_cms = (int)Tools::getValue('id_cms')) - $this->cms = new CMS($id_cms, self::$cookie->id_lang); + $this->cms = new CMS($id_cms, $this->context->language->id); elseif ($id_cms_category = (int)Tools::getValue('id_cms_category')) - $this->cms_category = new CMSCategory($id_cms_category, self::$cookie->id_lang); + $this->cms_category = new CMSCategory($id_cms_category, $this->context->language->id); // Automatically redirect to the canonical URL if the current in is the right one // $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain - if ($this->cms AND $canonicalURL = self::$link->getCMSLink($this->cms)) + if ($this->cms AND $canonicalURL = $this->context->link->getCMSLink($this->cms)) if (!preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/i', Tools::getProtocol().$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) { header('HTTP/1.0 301 Moved'); @@ -48,7 +48,7 @@ class CmsControllerCore extends FrontController die('[Debug] This page has moved
Please use the following URL instead: '.$canonicalURL.''); Tools::redirectLink($canonicalURL); } - if ($this->cms_category AND $canonicalURL = self::$link->getCMSCategoryLink($this->cms_category)) + if ($this->cms_category AND $canonicalURL = $this->context->link->getCMSCategoryLink($this->cms_category)) if (!preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/i', Tools::getProtocol().$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) { header('HTTP/1.0 301 Moved'); @@ -74,11 +74,11 @@ class CmsControllerCore extends FrontController foreach ($rewrite_infos AS $infos) { $arr_link = (isset($id_cms) AND !isset($id_cms_category)) ? - self::$link->getCMSLink($id_cms, $infos['link_rewrite'], $this->ssl, $infos['id_lang']) : - self::$link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']); + $this->context->link->getCMSLink($id_cms, $infos['link_rewrite'], $this->ssl, $infos['id_lang']) : + $this->context->link->getCMSCategoryLink($id_cms_category, $infos['link_rewrite'], $infos['id_lang']); $default_rewrite[$infos['id_lang']] = $arr_link; } - self::$smarty->assign('lang_rewrite_urls', $default_rewrite); + $this->context->smarty->assign('lang_rewrite_urls', $default_rewrite); } } @@ -95,13 +95,13 @@ class CmsControllerCore extends FrontController public function process() { parent::process(); - $parent_cat = new CMSCategory(1, (int)(self::$cookie->id_lang)); - self::$smarty->assign('id_current_lang', self::$cookie->id_lang); - self::$smarty->assign('home_title', $parent_cat->name); - self::$smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID')); + $parent_cat = new CMSCategory(1, $this->context->language->id); + $this->context->smarty->assign('id_current_lang', $this->context->language->id); + $this->context->smarty->assign('home_title', $parent_cat->name); + $this->context->smarty->assign('cgv_id', Configuration::get('PS_CONDITIONS_CMS_ID')); if ($this->assignCase == 1) { - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'cms' => $this->cms, 'content_only' => (int)(Tools::getValue('content_only')), 'path' => ((isset($this->cms->id_cms_category) AND $this->cms->id_cms_category) ? Tools::getFullPath((int)($this->cms->id_cms_category), $this->cms->meta_title, 'CMS') : Tools::getFullPath(1, $this->cms->meta_title, 'CMS')) @@ -109,10 +109,10 @@ class CmsControllerCore extends FrontController } elseif ($this->assignCase == 2) { - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'category' => $this->cms_category, - 'sub_category' => $this->cms_category->getSubCategories((int)(self::$cookie->id_lang)), - 'cms_pages' => CMS::getCMSPages((int)(self::$cookie->id_lang), (int)($this->cms_category->id) ), + 'sub_category' => $this->cms_category->getSubCategories($this->context->language->id), + 'cms_pages' => CMS::getCMSPages($this->context->language->id, (int)($this->cms_category->id) ), 'path' => ($this->cms_category->id !== 1) ? Tools::getPath((int)($this->cms_category->id), $this->cms_category->name, false, 'CMS') : '', )); } @@ -121,6 +121,6 @@ class CmsControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'cms.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'cms.tpl'); } } diff --git a/controllers/CartController.php b/controllers/CartController.php index 1470eb764..7eeaf52a5 100644 --- a/controllers/CartController.php +++ b/controllers/CartController.php @@ -31,7 +31,6 @@ class CartControllerCore extends FrontController { $this->init(); $this->preProcess(); - $context = Context::getContext(); if (Tools::getValue('ajax') == 'true') { @@ -39,16 +38,16 @@ class CartControllerCore extends FrontController { if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) { - if (Validate::isLoadedObject($context->customer)) - $groups = $context->customer->getGroups(); + if (Validate::isLoadedObject($this->context->customer)) + $groups = $this->context->customer->getGroups(); else $groups = array(1); - if ($context->cart->id_address_delivery) - $deliveryAddress = new Address($context->cart->id_address_delivery); + if ($this->context->cart->id_address_delivery) + $deliveryAddress = new Address($this->context->cart->id_address_delivery); $result = array('carriers' => Carrier::getCarriersForOrder(Country::getIdZone((isset($deliveryAddress) AND (int)$deliveryAddress->id) ? (int)$deliveryAddress->id_country : (int)Configuration::get('PS_COUNTRY_DEFAULT')), $groups)); } - $result['summary'] = $context->cart->getSummaryDetails(); - $result['customizedDatas'] = Product::getAllCustomizedDatas($context->cart->id, null, true); + $result['summary'] = $this->context->cart->getSummaryDetails(); + $result['customizedDatas'] = Product::getAllCustomizedDatas($this->context->cart->id, null, true); $result['HOOK_SHOPPING_CART'] = Module::hookExec('shoppingCart', $result['summary']); $result['HOOK_SHOPPING_CART_EXTRA'] = Module::hookExec('shoppingCartExtra', $result['summary']); die(Tools::jsonEncode($result)); @@ -74,23 +73,22 @@ class CartControllerCore extends FrontController public function preProcess() { parent::preProcess(); - $context = Context::getContext(); - $orderTotal = $context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); - $this->cartDiscounts = $context->cart->getDiscounts(); + $orderTotal = $this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS); + $this->cartDiscounts = $this->context->cart->getDiscounts(); foreach ($this->cartDiscounts AS $k => $this->cartDiscount) - if ($error = self::$cart->checkDiscountValidity(new Discount((int)($this->cartDiscount['id_discount'])), $this->cartDiscounts, $orderTotal, $context->cart->getProducts(), false)) - $context->cart->deleteDiscount((int)($this->cartDiscount['id_discount'])); + if ($error = $this->context->cart->checkDiscountValidity(new Discount((int)($this->cartDiscount['id_discount'])), $this->cartDiscounts, $orderTotal, $this->context->cart->getProducts(), false)) + $this->context->cart->deleteDiscount((int)($this->cartDiscount['id_discount'])); $add = Tools::getIsset('add') ? 1 : 0; $delete = Tools::getIsset('delete') ? 1 : 0; if (Configuration::get('PS_TOKEN_ENABLE') == 1 && strcasecmp(Tools::getToken(false), strval(Tools::getValue('token'))) && - $context->cookie->isLogged() === true) + $this->context->customer->isLogged() === true) $this->errors[] = Tools::displayError('Invalid token'); // Update the cart ONLY if $this->cookies are available, in order to avoid ghost carts created by bots - if (($add OR Tools::getIsset('update') OR $delete) AND isset($_COOKIE[$context->cookie->getName()])) + if (($add OR Tools::getIsset('update') OR $delete) AND isset($_COOKIE[$this->context->cookie->getName()])) { //get the values $idProduct = (int)(Tools::getValue('id_product', NULL)); @@ -103,7 +101,7 @@ class CartControllerCore extends FrontController $this->errors[] = Tools::displayError('Product not found'); else { - $producToAdd = new Product($idProduct, true, $context->language->id); + $producToAdd = new Product($idProduct, true, $this->context->language->id); if ((!$producToAdd->id OR !$producToAdd->active) AND !$delete) if (Tools::getValue('ajax') == 'true') die('{"hasError" : true, "errors" : ["'.Tools::displayError('Product is no longer available.', false).'"]}'); @@ -124,7 +122,7 @@ class CartControllerCore extends FrontController { $idProductAttribute = Product::getDefaultAttribute((int)$producToAdd->id, (int)$producToAdd->out_of_stock == 2 ? !(int)Configuration::get('PS_ORDER_OUT_OF_STOCK') : !(int)$producToAdd->out_of_stock); if (!$idProductAttribute) - Tools::redirectAdmin($context->link->getProductLink($producToAdd)); + Tools::redirectAdmin($this->context->link->getProductLink($producToAdd)); elseif (!$delete AND !Product::isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty((int)$idProductAttribute, (int)$qty)) if (Tools::getValue('ajax') == 'true') die('{"hasError" : true, "errors" : ["'.Tools::displayError('There is not enough product in stock.', false).'"]}'); @@ -139,14 +137,14 @@ class CartControllerCore extends FrontController /* Check vouchers compatibility */ if ($add AND (($producToAdd->specificPrice AND (float)($producToAdd->specificPrice['reduction'])) OR $producToAdd->on_sale)) { - $discounts = $context->cart->getDiscounts(); + $discounts = $this->context->cart->getDiscounts(); $hasUndiscountedProduct = null; foreach($discounts as $discount) { if(is_null($hasUndiscountedProduct)) { $hasUndiscountedProduct = false; - foreach($context->cart->getProducts() as $product) + foreach($this->context->cart->getProducts() as $product) if($product['reduction_applies'] === false) { $hasUndiscountedProduct = true; @@ -166,18 +164,18 @@ class CartControllerCore extends FrontController if ($add AND $qty >= 0) { /* Product addition to the cart */ - if (!$context->cart->id) + if (!$this->context->cart->id) { - $context->cart->add(); - if ($context->cart->id) - $context->cookie->id_cart = (int)$context->cart->id; + $this->context->cart->add(); + if ($this->context->cart->id) + $this->context->cookie->id_cart = (int)$this->context->cart->id; } if ($add AND !$producToAdd->hasAllRequiredCustomizableFields() AND !$customizationId) $this->errors[] = Tools::displayError('Please fill in all required fields, then save the customization.'); if (!sizeof($this->errors)) { - $updateQuantity = $context->cart->updateQty($qty, $idProduct, $idProductAttribute, $customizationId, Tools::getValue('op', 'up')); + $updateQuantity = $this->context->cart->updateQty($qty, $idProduct, $idProductAttribute, $customizationId, Tools::getValue('op', 'up')); if ($updateQuantity < 0) { @@ -206,25 +204,25 @@ class CartControllerCore extends FrontController } elseif ($delete) { - if ($context->cart->deleteProduct($idProduct, $idProductAttribute, $customizationId)) - if (!Cart::getNbProducts((int)(self::$cart->id))) + if ($this->context->cart->deleteProduct($idProduct, $idProductAttribute, $customizationId)) + if (!Cart::getNbProducts((int)($this->context->cart->id))) { - self::$cart->id_carrier = 0; - self::$cart->gift = 0; - self::$cart->gift_message = ''; - self::$cart->update(); + $this->context->cart->id_carrier = 0; + $this->context->cart->gift = 0; + $this->context->cart->gift_message = ''; + $this->context->cart->update(); } } } - $discounts = self::$cart->getDiscounts(); + $discounts = $this->context->cart->getDiscounts(); foreach($discounts AS $discount) { - $discountObj = new Discount((int)($discount['id_discount']), (int)(self::$cookie->id_lang)); + $discountObj = new Discount($discount['id_discount'], $this->context->language->id); - if ($error = self::$cart->checkDiscountValidity($discountObj, $discounts, self::$cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), self::$cart->getProducts(), false)) + if ($error = $this->context->cart->checkDiscountValidity($discountObj, $discounts, $this->context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS), $this->context->cart->getProducts(), false)) { - self::$cart->deleteDiscount((int)($discount['id_discount'])); - self::$cart->update(); + $this->context->cart->deleteDiscount((int)($discount['id_discount'])); + $this->context->cart->update(); $errors[] = $error; } } @@ -252,6 +250,6 @@ class CartControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'errors.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'errors.tpl'); } } diff --git a/controllers/CategoryController.php b/controllers/CategoryController.php index 09d4bb01f..e93e70420 100644 --- a/controllers/CategoryController.php +++ b/controllers/CategoryController.php @@ -51,7 +51,7 @@ class CategoryControllerCore extends FrontController public function preProcess() { if ($id_category = (int)Tools::getValue('id_category')) - $this->category = new Category($id_category, self::$cookie->id_lang); + $this->category = new Category($id_category, $this->context->language->id); if (!Validate::isLoadedObject($this->category)) { header('HTTP/1.1 404 Not Found'); @@ -61,7 +61,7 @@ class CategoryControllerCore extends FrontController { // Automatically redirect to the canonical URL if the current in is the right one // $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain - $currentURL = self::$link->getCategoryLink($this->category); + $currentURL = $this->context->link->getCategoryLink($this->category); $currentURL = preg_replace('/[?&].*$/', '', $currentURL); if (!preg_match('/^'.Tools::pRegexp($currentURL, '/').'([&?].*)?$/i', Tools::getProtocol().$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) { @@ -81,9 +81,9 @@ class CategoryControllerCore extends FrontController $default_rewrite = array(); foreach ($rewrite_infos AS $infos) - $default_rewrite[$infos['id_lang']] = self::$link->getCategoryLink((int)$id_category, $infos['link_rewrite'], $infos['id_lang']); + $default_rewrite[$infos['id_lang']] = $this->context->link->getCategoryLink((int)$id_category, $infos['link_rewrite'], $infos['id_lang']); - self::$smarty->assign('lang_rewrite_urls', $default_rewrite); + $this->context->smarty->assign('lang_rewrite_urls', $default_rewrite); } } @@ -96,16 +96,16 @@ class CategoryControllerCore extends FrontController { if (!Validate::isLoadedObject($this->category)) $this->errors[] = Tools::displayError('Category does not exist'); - elseif (!$this->category->checkAccess((int)(self::$cookie->id_customer))) + elseif (!$this->category->checkAccess($this->context->customer->id)) $this->errors[] = Tools::displayError('You do not have access to this category.'); elseif (!$this->category->active) - self::$smarty->assign('category', $this->category); + $this->context->smarty->assign('category', $this->category); else { - $rewrited_url = self::$link->getCategoryLink((int)$this->category->id, $this->category->link_rewrite); + $rewrited_url = $this->context->link->getCategoryLink((int)$this->category->id, $this->category->link_rewrite); /* Scenes (could be externalised to another controler if you need them */ - self::$smarty->assign('scenes', Scene::getScenes((int)($this->category->id), (int)(self::$cookie->id_lang), true, false)); + $this->context->smarty->assign('scenes', Scene::getScenes((int)($this->category->id), $this->context->language->id, true, false)); /* Scenes images formats */ if ($sceneImageTypes = ImageType::getImagesTypes('scenes')) @@ -117,18 +117,18 @@ class CategoryControllerCore extends FrontController elseif ($sceneImageType['name'] == 'large_scene') $largeSceneImageType = $sceneImageType; } - self::$smarty->assign('thumbSceneImageType', isset($thumbSceneImageType) ? $thumbSceneImageType : NULL); - self::$smarty->assign('largeSceneImageType', isset($largeSceneImageType) ? $largeSceneImageType : NULL); + $this->context->smarty->assign('thumbSceneImageType', isset($thumbSceneImageType) ? $thumbSceneImageType : NULL); + $this->context->smarty->assign('largeSceneImageType', isset($largeSceneImageType) ? $largeSceneImageType : NULL); } $this->category->description = Tools::nl2br($this->category->description); - $subCategories = $this->category->getSubCategories((int)(self::$cookie->id_lang)); - self::$smarty->assign('category', $this->category); + $subCategories = $this->category->getSubCategories($this->context->language->id); + $this->context->smarty->assign('category', $this->category); if (isset($subCategories) AND !empty($subCategories) AND $subCategories) { - self::$smarty->assign('subcategories', $subCategories); - self::$smarty->assign(array( + $this->context->smarty->assign('subcategories', $subCategories); + $this->context->smarty->assign(array( 'subcategories_nb_total' => sizeof($subCategories), 'subcategories_nb_half' => ceil(sizeof($subCategories) / 2))); } @@ -136,10 +136,10 @@ class CategoryControllerCore extends FrontController { $nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true); $this->pagination((int)$nbProducts); - self::$smarty->assign('nb_products', (int)$nbProducts); - $cat_products = $this->category->getProducts((int)(self::$cookie->id_lang), (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay); + $this->context->smarty->assign('nb_products', (int)$nbProducts); + $cat_products = $this->category->getProducts($this->context->language->id, (int)($this->p), (int)($this->n), $this->orderBy, $this->orderWay); } - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'products' => (isset($cat_products) AND $cat_products) ? $cat_products : NULL, 'id_category' => (int)($this->category->id), 'id_category_parent' => (int)($this->category->id_parent), @@ -154,7 +154,7 @@ class CategoryControllerCore extends FrontController } } - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'allow_oosp' => (int)(Configuration::get('PS_ORDER_OUT_OF_STOCK')), 'comparator_max_item' => (int)(Configuration::get('PS_COMPARATOR_MAX_ITEM')), 'suppliers' => Supplier::getSuppliers() @@ -164,7 +164,7 @@ class CategoryControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'category.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'category.tpl'); } } diff --git a/controllers/ChangeCurrencyController.php b/controllers/ChangeCurrencyController.php index 1c0a6ca85..bc7847cb6 100644 --- a/controllers/ChangeCurrencyController.php +++ b/controllers/ChangeCurrencyController.php @@ -34,7 +34,7 @@ class ChangeCurrencyControllerCore extends FrontController $currency = new Currency((int)Tools::getValue('id_currency')); if (Validate::isLoadedObject($currency) AND !$currency->deleted) { - self::$cookie->id_currency = (int)($currency->id); + $this->cookie->id_currency = (int)($currency->id); die('1'); } die('0'); diff --git a/controllers/CompareController.php b/controllers/CompareController.php index 1f40bf858..33643c86b 100644 --- a/controllers/CompareController.php +++ b/controllers/CompareController.php @@ -58,7 +58,7 @@ class CompareControllerCore extends FrontController foreach ($ids AS $k => &$id) { - $curProduct = new Product((int)$id, true, (int)self::$cookie->id_lang); + $curProduct = new Product((int)$id, true, $this->context->language->id); if (!$curProduct->active OR !$curProduct->isAssociatedToShop()) { unset($ids[$k]); @@ -80,12 +80,12 @@ class CompareControllerCore extends FrontController continue; } - foreach ($curProduct->getFrontFeatures(self::$cookie->id_lang) AS $feature) + foreach ($curProduct->getFrontFeatures($this->context->language->id) AS $feature) $listFeatures[$curProduct->id][$feature['id_feature']] = $feature['value']; $cover = Product::getCover((int)$id); - $curProduct->id_image = Tools::htmlentitiesUTF8(Product::defineProductImage(array('id_image' => $cover['id_image'], 'id_product' => $id), self::$cookie->id_lang)); + $curProduct->id_image = Tools::htmlentitiesUTF8(Product::defineProductImage(array('id_image' => $cover['id_image'], 'id_product' => $id), $this->context->language->id)); $curProduct->allow_oosp = Product::isAvailableWhenOutOfStock($curProduct->out_of_stock); $listProducts[] = $curProduct; } @@ -95,25 +95,25 @@ class CompareControllerCore extends FrontController $width = 80 / sizeof($listProducts); $hasProduct = true; - $ordered_features = Feature::getFeaturesForComparison($ids, self::$cookie->id_lang); - self::$smarty->assign(array( + $ordered_features = Feature::getFeaturesForComparison($ids, $this->context->language->id); + $this->context->smarty->assign(array( 'ordered_features' => $ordered_features, 'product_features' => $listFeatures, 'products' => $listProducts, 'width' => $width, 'homeSize' => Image::getSize('home') )); - self::$smarty->assign('HOOK_EXTRA_PRODUCT_COMPARISON', Module::hookExec('extraProductComparison', array('list_ids_product' => $ids))); + $this->context->smarty->assign('HOOK_EXTRA_PRODUCT_COMPARISON', Module::hookExec('extraProductComparison', array('list_ids_product' => $ids))); } } } - self::$smarty->assign('hasProduct', $hasProduct); + $this->context->smarty->assign('hasProduct', $hasProduct); } public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'products-comparison.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'products-comparison.tpl'); } } diff --git a/controllers/ContactController.php b/controllers/ContactController.php index 0f1bf4395..8476a1bec 100644 --- a/controllers/ContactController.php +++ b/controllers/ContactController.php @@ -39,23 +39,21 @@ class ContactControllerCore extends FrontController { parent::preProcess(); - if (self::$cookie->isLogged()) + if ($this->context->customer->isLogged()) { - self::$smarty->assign('isLogged', 1); - $customer = new Customer((int)(self::$cookie->id_customer)); - if (!Validate::isLoadedObject($customer)) - die(Tools::displayError('Customer not found')); + $this->context->smarty->assign('isLogged', 1); + $products = array(); $orders = array(); $getOrders = Db::getInstance()->ExecuteS(' SELECT id_order FROM '._DB_PREFIX_.'orders - WHERE id_customer = '.(int)$customer->id.' ORDER BY date_add'); + WHERE id_customer = '.(int)$this->context->customer->id.' ORDER BY date_add'); foreach ($getOrders as $row) { $order = new Order($row['id_order']); $date = explode(' ', $order->date_add); - $orders[$row['id_order']] = Tools::displayDate($date[0], self::$cookie->id_lang); + $orders[$row['id_order']] = Tools::displayDate($date[0], $this->context->language->id); $tmp = $order->getProducts(); foreach ($tmp as $key => $val) $products[$val['product_id']] = $val['product_name']; @@ -68,8 +66,8 @@ class ContactControllerCore extends FrontController foreach ($products as $key => $val) $orderedProductList .= ''; - self::$smarty->assign('orderList', $orderList); - self::$smarty->assign('orderedProductList', $orderedProductList); + $this->context->smarty->assign('orderList', $orderList); + $this->context->smarty->assign('orderedProductList', $orderedProductList); } if (Tools::isSubmit('submitMessage')) @@ -90,7 +88,7 @@ class ContactControllerCore extends FrontController $this->errors[] = Tools::displayError('Message cannot be blank'); elseif (!Validate::isCleanHtml($message)) $this->errors[] = Tools::displayError('Invalid message'); - elseif (!($id_contact = (int)(Tools::getValue('id_contact'))) OR !(Validate::isLoadedObject($contact = new Contact((int)($id_contact), (int)(self::$cookie->id_lang))))) + elseif (!($id_contact = (int)(Tools::getValue('id_contact'))) OR !(Validate::isLoadedObject($contact = new Contact($id_contact, $this->context->language->id)))) $this->errors[] = Tools::displayError('Please select a subject on the list.'); elseif (!empty($_FILES['fileUpload']['name']) AND $_FILES['fileUpload']['error'] != 0) $this->errors[] = Tools::displayError('An error occurred during the file upload'); @@ -98,15 +96,11 @@ class ContactControllerCore extends FrontController $this->errors[] = Tools::displayError('Bad file extension'); else { - if ((int)(self::$cookie->id_customer)) - $customer = new Customer((int)(self::$cookie->id_customer)); - else - { - $customer = new Customer(); + $customer = $this->context->customer; + if (!$customer->id) $customer->getByEmail($from); - } - $contact = new Contact($id_contact, self::$cookie->id_lang); + $contact = new Contact($id_contact, $this->context->language->id); if (!(( $id_customer_thread = (int)Tools::getValue('id_customer_thread') @@ -152,15 +146,15 @@ class ContactControllerCore extends FrontController ORDER BY date_add DESC'); if ($old_message == htmlentities($message, ENT_COMPAT, 'UTF-8')) { - self::$smarty->assign('alreadySent', 1); + $this->context->smarty->assign('alreadySent', 1); $contact->email = ''; $contact->customer_service = 0; } if (!empty($contact->email)) { - if (Mail::Send((int)(self::$cookie->id_lang), 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, ((int)(self::$cookie->id_customer) ? $customer->firstname.' '.$customer->lastname : ''), $fileAttachment) - AND Mail::Send((int)(self::$cookie->id_lang), 'contact_form', Mail::l('Your message has been correctly sent'), array('{message}' => stripslashes($message)), $from)) - self::$smarty->assign('confirmation', 1); + if (Mail::Send($this->context->language->id, 'contact', Mail::l('Message from contact form'), array('{email}' => $from, '{message}' => stripslashes($message)), $contact->email, $contact->name, $from, ($customer->id ? $customer->firstname.' '.$customer->lastname : ''), $fileAttachment) + AND Mail::Send($this->context->language->id, 'contact_form', Mail::l('Your message has been correctly sent'), array('{message}' => stripslashes($message)), $from)) + $this->context->smarty->assign('confirmation', 1); else $this->errors[] = Tools::displayError('An error occurred while sending message.'); } @@ -171,7 +165,7 @@ class ContactControllerCore extends FrontController { $ct = new CustomerThread($id_customer_thread); $ct->status = 'open'; - $ct->id_lang = (int)self::$cookie->id_lang; + $ct->id_lang = (int)$this->context->language->id; $ct->id_contact = (int)($id_contact); if ($id_order = (int)Tools::getValue('id_order')) $ct->id_order = $id_order; @@ -190,7 +184,7 @@ class ContactControllerCore extends FrontController if ($id_product = (int)Tools::getValue('id_product')) $ct->id_product = $id_product; $ct->id_contact = (int)($id_contact); - $ct->id_lang = (int)self::$cookie->id_lang; + $ct->id_lang = (int)$this->context->language->id; $ct->email = $from; $ct->status = 'open'; $ct->token = Tools::passwdGen(12); @@ -209,8 +203,8 @@ class ContactControllerCore extends FrontController if ($cm->add()) { if (empty($contact->email)) - Mail::Send((int)(self::$cookie->id_lang), 'contact_form', Mail::l('Your message has been correctly sent'), array('{message}' => stripslashes($message)), $from); - self::$smarty->assign('confirmation', 1); + Mail::Send($this->context->language->id, 'contact_form', Mail::l('Your message has been correctly sent'), array('{message}' => stripslashes($message)), $from); + $this->context->smarty->assign('confirmation', 1); } else $this->errors[] = Tools::displayError('An error occurred while sending message.'); @@ -234,8 +228,8 @@ class ContactControllerCore extends FrontController { parent::process(); - $email = Tools::safeOutput(Tools::getValue('from', ((isset(self::$cookie) AND isset(self::$cookie->email) AND Validate::isEmail(self::$cookie->email)) ? self::$cookie->email : ''))); - self::$smarty->assign(array( + $email = Tools::safeOutput(Tools::getValue('from', ((isset($this->context->cookie) AND isset($this->context->cookie->email) AND Validate::isEmail($this->context->cookie->email)) ? $this->context->cookie->email : ''))); + $this->context->smarty->assign(array( 'errors' => $this->errors, 'email' => $email, 'fileupload' => Configuration::get('PS_CUSTOMER_SERVICE_FILE_UPLOAD') @@ -247,9 +241,9 @@ class ContactControllerCore extends FrontController $customerThread = Db::getInstance()->getRow(' SELECT cm.* FROM '._DB_PREFIX_.'customer_thread cm WHERE cm.id_customer_thread = '.(int)$id_customer_thread.' AND cm.id_shop = '.(int)$this->id_current_shop.' AND token = \''.pSQL($token).'\''); - self::$smarty->assign('customerThread', $customerThread); + $this->context->smarty->assign('customerThread', $customerThread); } - self::$smarty->assign(array('contacts' => Contact::getContacts((int)self::$cookie->id_lang), + $this->context->smarty->assign(array('contacts' => Contact::getContacts($this->context->language->id), 'message' => html_entity_decode(Tools::getValue('message')) )); } @@ -258,7 +252,7 @@ class ContactControllerCore extends FrontController { $_POST = array_merge($_POST, $_GET); parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'contact-form.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'contact-form.tpl'); } } diff --git a/controllers/DiscountController.php b/controllers/DiscountController.php index 9192c7a4a..346e28db7 100644 --- a/controllers/DiscountController.php +++ b/controllers/DiscountController.php @@ -41,19 +41,19 @@ class DiscountControllerCore extends FrontController { parent::process(); - $discounts = Discount::getCustomerDiscounts((int)(self::$cookie->id_lang), (int)(self::$cookie->id_customer), true, false); + $discounts = Discount::getCustomerDiscounts($this->context->language->id, $this->context->customer->id, true, false); $nbDiscounts = 0; foreach ($discounts AS $discount) if ($discount['quantity_for_user']) $nbDiscounts++; - self::$smarty->assign(array('nbDiscounts' => (int)($nbDiscounts), 'discount' => $discounts)); + $this->context->smarty->assign(array('nbDiscounts' => (int)($nbDiscounts), 'discount' => $discounts)); } public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'discount.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'discount.tpl'); } } diff --git a/controllers/GetFileController.php b/controllers/GetFileController.php index 65e56683d..d72bd6348 100644 --- a/controllers/GetFileController.php +++ b/controllers/GetFileController.php @@ -29,7 +29,7 @@ class getFileControllerCore extends FrontController { public function process() { - $cookie = self::$cookie; + $cookie = $this->context->cookie; if ($cookie->isLoggedBack() AND Tools::getValue('file')) { /* Admin can directly access to file */ diff --git a/controllers/GuestTrackingController.php b/controllers/GuestTrackingController.php index 9f0891ffb..024719d8f 100644 --- a/controllers/GuestTrackingController.php +++ b/controllers/GuestTrackingController.php @@ -31,7 +31,7 @@ class GuestTrackingControllerCore extends FrontController { parent::preProcess(); - if (self::$cookie->isLogged()) + if ($this->context->customer->isLogged()) Tools::redirect('index.php?controller=history'); } @@ -60,13 +60,13 @@ class GuestTrackingControllerCore extends FrontController $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields); if ($order->total_discounts > 0) - self::$smarty->assign('total_old', (float)($order->total_paid - $order->total_discounts)); + $this->context->smarty->assign('total_old', (float)($order->total_paid - $order->total_discounts)); $products = $order->getProducts(); $customizedDatas = Product::getAllCustomizedDatas((int)($order->id_cart)); Product::addCustomizationPrice($products, $customizedDatas); $this->processAddressFormat($addressDelivery, $addressInvoice); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'shop_name' => Configuration::get('PS_SHOP_NAME'), 'order' => $order, 'return_allowed' => false, @@ -74,7 +74,7 @@ class GuestTrackingControllerCore extends FrontController 'order_state' => (int)($id_order_state), 'invoiceAllowed' => (int)(Configuration::get('PS_INVOICE')), 'invoice' => (OrderState::invoiceAvailable((int)($id_order_state)) AND $order->invoice_number), - 'order_history' => $order->getHistory((int)(self::$cookie->id_lang), false, true), + 'order_history' => $order->getHistory($this->context->language->id, false, true), 'products' => $products, 'discounts' => $order->getDiscounts(), 'carrier' => $carrier, @@ -91,8 +91,8 @@ class GuestTrackingControllerCore extends FrontController 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues)); if ($carrier->url AND $order->shipping_number) - self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); - self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order))); + $this->context->smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); + $this->context->smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order))); Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order)); if (Tools::isSubmit('submitTransformGuestToCustomer')) @@ -100,12 +100,12 @@ class GuestTrackingControllerCore extends FrontController $customer = new Customer((int)$order->id_customer); if (!Validate::isLoadedObject($customer)) $this->errors[] = Tools::displayError('Invalid customer'); - if (!$customer->transformToCustomer(self::$cookie->id_lang, Tools::getValue('password'))) + if (!$customer->transformToCustomer($this->context->language->id, Tools::getValue('password'))) $this->errors[] = Tools::displayError('An error occurred while transforming guest to customer.'); if (!Tools::getValue('password')) $this->errors[] = Tools::displayError('Invalid password'); else - self::$smarty->assign('transformSuccess', true); + $this->context->smarty->assign('transformSuccess', true); } } if (sizeof($this->errors)) @@ -113,7 +113,7 @@ class GuestTrackingControllerCore extends FrontController sleep(1); } - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'action' => 'guest-tracking.php', 'errors' => $this->errors )); @@ -131,7 +131,7 @@ class GuestTrackingControllerCore extends FrontController { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'guest-tracking.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'guest-tracking.tpl'); } private function processAddressFormat(Address $delivery, Address $invoice) @@ -140,8 +140,8 @@ class GuestTrackingControllerCore extends FrontController $inv_adr_fields = AddressFormat::getOrderedAddressFields($invoice->id_country); $dlv_adr_fields = AddressFormat::getOrderedAddressFields($delivery->id_country); - self::$smarty->assign('inv_adr_fields', $inv_adr_fields); - self::$smarty->assign('dlv_adr_fields', $dlv_adr_fields); + $this->context->smarty->assign('inv_adr_fields', $inv_adr_fields); + $this->context->smarty->assign('dlv_adr_fields', $dlv_adr_fields); } } diff --git a/controllers/HistoryController.php b/controllers/HistoryController.php index 470325552..0be66b852 100644 --- a/controllers/HistoryController.php +++ b/controllers/HistoryController.php @@ -52,14 +52,14 @@ class HistoryControllerCore extends FrontController { parent::process(); - if ($orders = Order::getCustomerOrders((int)(self::$cookie->id_customer))) + if ($orders = Order::getCustomerOrders($this->context->customer->id)) foreach ($orders AS &$order) { $myOrder = new Order((int)($order['id_order'])); if (Validate::isLoadedObject($myOrder)) $order['virtual'] = $myOrder->isVirtual(false); } - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'orders' => $orders, 'invoiceAllowed' => (int)(Configuration::get('PS_INVOICE')), 'slowValidation' => Tools::isSubmit('slowvalidation') @@ -69,7 +69,7 @@ class HistoryControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'history.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'history.tpl'); } } diff --git a/controllers/IdentityController.php b/controllers/IdentityController.php index 5473671e4..d3f7c9286 100644 --- a/controllers/IdentityController.php +++ b/controllers/IdentityController.php @@ -41,7 +41,7 @@ class IdentityControllerCore extends FrontController { parent::preProcess(); - $customer = new Customer((int)(self::$cookie->id_customer)); + $customer = $this->context->customer; if (sizeof($_POST)) { @@ -65,7 +65,7 @@ class IdentityControllerCore extends FrontController $customer->birthday = (empty($_POST['years']) ? '' : (int)($_POST['years']).'-'.(int)($_POST['months']).'-'.(int)($_POST['days'])); $_POST['old_passwd'] = trim($_POST['old_passwd']); - if (empty($_POST['old_passwd']) OR (Tools::encrypt($_POST['old_passwd']) != self::$cookie->passwd)) + if (empty($_POST['old_passwd']) OR (Tools::encrypt($_POST['old_passwd']) != $this->context->cookie->passwd)) $this->errors[] = Tools::displayError('Your password is incorrect.'); elseif ($_POST['passwd'] != $_POST['confirmation']) $this->errors[] = Tools::displayError('Password and confirmation do not match'); @@ -79,12 +79,12 @@ class IdentityControllerCore extends FrontController $customer->id_default_group = (int)($prev_id_default_group); $customer->firstname = Tools::ucfirst(Tools::strtolower($customer->firstname)); if (Tools::getValue('passwd')) - self::$cookie->passwd = $customer->passwd; + $this->context->cookie->passwd = $customer->passwd; if ($customer->update()) { - self::$cookie->customer_lastname = $customer->lastname; - self::$cookie->customer_firstname = $customer->firstname; - self::$smarty->assign('confirmation', 1); + $this->context->cookie->customer_lastname = $customer->lastname; + $this->context->cookie->customer_firstname = $customer->firstname; + $this->context->smarty->assign('confirmation', 1); } else $this->errors[] = Tools::displayError('Cannot update information'); @@ -100,7 +100,7 @@ class IdentityControllerCore extends FrontController $birthday = array('-', '-', '-'); /* Generate years, months and days */ - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'years' => Tools::dateYears(), 'sl_year' => $birthday[0], 'months' => Tools::dateMonths(), @@ -110,7 +110,7 @@ class IdentityControllerCore extends FrontController 'errors' => $this->errors )); - self::$smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active); + $this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active); } public function setMedia() @@ -122,7 +122,7 @@ class IdentityControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'identity.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'identity.tpl'); } } diff --git a/controllers/IndexController.php b/controllers/IndexController.php index d55c6c912..9300043d7 100644 --- a/controllers/IndexController.php +++ b/controllers/IndexController.php @@ -37,12 +37,12 @@ class IndexControllerCore extends FrontController public function process() { parent::process(); - self::$smarty->assign('HOOK_HOME', Module::hookExec('home')); + $this->context->smarty->assign('HOOK_HOME', Module::hookExec('home')); } public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'index.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'index.tpl'); } } diff --git a/controllers/ManufacturerController.php b/controllers/ManufacturerController.php index cc78afc44..4ca696b84 100644 --- a/controllers/ManufacturerController.php +++ b/controllers/ManufacturerController.php @@ -39,14 +39,14 @@ class ManufacturerControllerCore extends FrontController { if ($id_manufacturer = Tools::getValue('id_manufacturer')) { - $this->manufacturer = new Manufacturer((int)$id_manufacturer, self::$cookie->id_lang); + $this->manufacturer = new Manufacturer((int)$id_manufacturer, $this->context->language->id); if (Validate::isLoadedObject($this->manufacturer) AND $this->manufacturer->active AND $this->manufacturer->isAssociatedToGroupShop()) { $nbProducts = $this->manufacturer->getProducts($id_manufacturer, NULL, NULL, NULL, $this->orderBy, $this->orderWay, true); $this->pagination((int)$nbProducts); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'nb_products' => $nbProducts, - 'products' => $this->manufacturer->getProducts($id_manufacturer, (int)self::$cookie->id_lang, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay), + 'products' => $this->manufacturer->getProducts($id_manufacturer, $this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay), 'path' => ($this->manufacturer->active ? Tools::safeOutput($this->manufacturer->name) : ''), 'manufacturer' => $this->manufacturer)); } @@ -61,17 +61,17 @@ class ManufacturerControllerCore extends FrontController { if (Configuration::get('PS_DISPLAY_SUPPLIERS')) { - $id_current_group_shop = Context::getContext()->shop->getGroupID(); - $data = call_user_func(array('Manufacturer', 'getManufacturers'), true, (int)self::$cookie->id_lang, true, false, false, false, $id_current_group_shop); + $id_current_group_shop = $this->context->shop->getGroupID(); + $data = call_user_func(array('Manufacturer', 'getManufacturers'), true, $this->context->language->id, true, false, false, false, $id_current_group_shop); $nbProducts = count($data); $this->pagination($nbProducts); - $data = call_user_func(array('Manufacturer', 'getManufacturers'), true, (int)self::$cookie->id_lang, true, $this->p, $this->n, false, $id_current_group_shop); + $data = call_user_func(array('Manufacturer', 'getManufacturers'), true, $this->context->language->id, true, $this->p, $this->n, false, $id_current_group_shop); $imgDir = _PS_MANU_IMG_DIR_; foreach ($data AS &$item) $item['image'] = (!file_exists($imgDir.'/'.$item['id_manufacturer'].'-medium.jpg')) ? - Language::getIsoById((int)(self::$cookie->id_lang)).'-default' : $item['id_manufacturer']; - self::$smarty->assign(array( + $this->context->language->iso_code.'-default' : $item['id_manufacturer']; + $this->context->smarty->assign(array( 'pages_nb' => ceil($nbProducts / (int)($this->n)), 'nbManufacturers' => $nbProducts, 'mediumSize' => Image::getSize('medium'), @@ -80,7 +80,7 @@ class ManufacturerControllerCore extends FrontController )); } else - self::$smarty->assign('nbManufacturers', 0); + $this->context->smarty->assign('nbManufacturers', 0); } } @@ -94,9 +94,9 @@ class ManufacturerControllerCore extends FrontController { parent::displayContent(); if ($this->manufacturer) - self::$smarty->display(_PS_THEME_DIR_.'manufacturer.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'manufacturer.tpl'); else - self::$smarty->display(_PS_THEME_DIR_.'manufacturer-list.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'manufacturer-list.tpl'); } } diff --git a/controllers/MyAccountController.php b/controllers/MyAccountController.php index db4a1b30c..3ec5b03a6 100644 --- a/controllers/MyAccountController.php +++ b/controllers/MyAccountController.php @@ -47,17 +47,17 @@ class MyAccountControllerCore extends FrontController { parent::process(); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'voucherAllowed' => (int)(Configuration::get('PS_VOUCHERS')), 'returnAllowed' => (int)(Configuration::get('PS_ORDER_RETURN')) )); - self::$smarty->assign('HOOK_CUSTOMER_ACCOUNT', Module::hookExec('customerAccount')); + $this->context->smarty->assign('HOOK_CUSTOMER_ACCOUNT', Module::hookExec('customerAccount')); } public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'my-account.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'my-account.tpl'); } } diff --git a/controllers/NewProductsController.php b/controllers/NewProductsController.php index d0b74ca7d..1e1cfb3dc 100644 --- a/controllers/NewProductsController.php +++ b/controllers/NewProductsController.php @@ -46,11 +46,11 @@ class NewProductsControllerCore extends FrontController $this->productSort(); - $nbProducts = (int)Product::getNewProducts((int)self::$cookie->id_lang, (isset($this->p) ? (int)($this->p) - 1 : NULL), (isset($this->n) ? (int)($this->n) : NULL), true); + $nbProducts = (int)Product::getNewProducts($this->context->language->id, (isset($this->p) ? (int)($this->p) - 1 : NULL), (isset($this->n) ? (int)($this->n) : NULL), true); $this->pagination($nbProducts); - self::$smarty->assign(array( - 'products' => Product::getNewProducts((int)(self::$cookie->id_lang), (int)($this->p) - 1, (int)($this->n), false, $this->orderBy, $this->orderWay), + $this->context->smarty->assign(array( + 'products' => Product::getNewProducts($this->context->language->id, (int)($this->p) - 1, (int)($this->n), false, $this->orderBy, $this->orderWay), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => (int)($nbProducts), 'homeSize' => Image::getSize('home') @@ -60,7 +60,7 @@ class NewProductsControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'new-products.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'new-products.tpl'); } } diff --git a/controllers/OrderConfirmationController.php b/controllers/OrderConfirmationController.php index 41165322e..7351793ab 100644 --- a/controllers/OrderConfirmationController.php +++ b/controllers/OrderConfirmationController.php @@ -58,7 +58,7 @@ class OrderConfirmationControllerCore extends FrontController Tools::redirect($redirectLink.(Tools::isSubmit('slowvalidation') ? '&slowvalidation' : '')); $order = new Order((int)($this->id_order)); - if (!Validate::isLoadedObject($order) OR $order->id_customer != self::$cookie->id_customer OR $this->secure_key != $order->secure_key) + if (!Validate::isLoadedObject($order) OR $order->id_customer != $this->context->customer->id OR $this->secure_key != $order->secure_key) Tools::redirect($redirectLink); $module = Module::getInstanceById((int)($this->id_module)); if ($order->payment != $module->displayName) @@ -68,27 +68,27 @@ class OrderConfirmationControllerCore extends FrontController public function process() { parent::process(); - self::$smarty->assign(array( - 'is_guest' => self::$cookie->is_guest, + $this->context->smarty->assign(array( + 'is_guest' => $this->context->customer->is_guest, 'HOOK_ORDER_CONFIRMATION' => Hook::orderConfirmation((int)($this->id_order)), 'HOOK_PAYMENT_RETURN' => Hook::paymentReturn((int)($this->id_order), (int)($this->id_module)) )); - if (self::$cookie->is_guest) + if ($this->context->customer->is_guest) { - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'id_order' => $this->id_order, 'id_order_formatted' => sprintf('#%06d', $this->id_order) )); /* If guest we clear the cookie for security reason */ - self::$cookie->logout(); + $this->context->cookie->logout(); } } public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'order-confirmation.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'order-confirmation.tpl'); } } diff --git a/controllers/OrderController.php b/controllers/OrderController.php index 525e6209a..d5eda8923 100644 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -47,29 +47,29 @@ class OrderControllerCore extends ParentOrderController parent::preProcess(); /* If some products have disappear */ - if (!self::$cart->checkQuantities()) + if (!$this->context->cart->checkQuantities()) { $this->step = 0; $this->errors[] = Tools::displayError('An item in your cart is no longer available for this quantity, you cannot proceed with your order.'); } /* Check minimal amount */ - $currency = Currency::getCurrency((int)self::$cart->id_currency); + $currency = Currency::getCurrency((int)$this->context->cart->id_currency); - $orderTotal = self::$cart->getOrderTotal(); + $orderTotal = $this->context->cart->getOrderTotal(); $minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency); - if (self::$cart->getOrderTotal(false) < $minimalPurchase && $this->step != -1) + if ($this->context->cart->getOrderTotal(false) < $minimalPurchase && $this->step != -1) { $this->step = 0; $this->errors[] = Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency). ' '.Tools::displayError('is required in order to validate your order.'); } - if (!self::$cookie->isLogged(true) AND in_array($this->step, array(1, 2, 3))) + if (!$this->context->customer->isLogged(true) AND in_array($this->step, array(1, 2, 3))) Tools::redirect('index.php?controller=authentication&back='.urlencode('order.php&step='.$this->step)); if ($this->nbProducts) - self::$smarty->assign('virtual_cart', $isVirtualCart); + $this->context->smarty->assign('virtual_cart', $isVirtualCart); } public function displayHeader() @@ -86,7 +86,7 @@ class OrderControllerCore extends ParentOrderController switch ((int)$this->step) { case -1; - self::$smarty->assign('empty', 1); + $this->context->smarty->assign('empty', 1); break; case 1: $this->_assignAddress(); @@ -109,10 +109,10 @@ class OrderControllerCore extends ParentOrderController /* Bypass payment step if total is 0 */ if (($id_order = $this->_checkFreeOrder()) AND $id_order) { - if (self::$cookie->is_guest) + if ($this->context->customer->is_guest) { - $email = self::$cookie->email; - self::$cookie->logout(); // If guest we clear the cookie for security reason + $email = $this->context->customer->email; + $this->context->cookie->logout(); // If guest we clear the cookie for security reason Tools::redirect('index.php?controller=guest-tracking&id_order='.(int)$id_order.'&email='.urlencode($email)); } else @@ -128,47 +128,45 @@ class OrderControllerCore extends ParentOrderController private function processAddressFormat() { - $addressDelivery = new Address((int)(self::$cart->id_address_delivery)); - $addressInvoice = new Address((int)(self::$cart->id_address_invoice)); + $addressDelivery = new Address((int)($this->context->cart->id_address_delivery)); + $addressInvoice = new Address((int)($this->context->cart->id_address_invoice)); $invoiceAddressFields = AddressFormat::getOrderedAddressFields($addressInvoice->id_country); $deliveryAddressFields = AddressFormat::getOrderedAddressFields($addressDelivery->id_country); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'inv_adr_fields' => $invoiceAddressFields, 'dlv_adr_fields' => $deliveryAddressFields)); } public function displayContent() { - $context = Context::getContext(); - parent::displayContent(); - self::$smarty->assign(array( - 'currencySign' => $context->currency->sign, - 'currencyRate' => $context->currency->conversion_rate, - 'currencyFormat' => $context->currency->format, - 'currencyBlank' => $context->currency->blank, + $this->context->smarty->assign(array( + 'currencySign' => $this->context->currency->sign, + 'currencyRate' => $this->context->currency->conversion_rate, + 'currencyFormat' => $this->context->currency->format, + 'currencyBlank' => $this->context->currency->blank, )); switch ((int)$this->step) { case -1: - self::$smarty->display(_PS_THEME_DIR_.'shopping-cart.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'shopping-cart.tpl'); break; case 1: $this->processAddressFormat(); - self::$smarty->display(_PS_THEME_DIR_.'order-address.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'order-address.tpl'); break; case 2: - self::$smarty->display(_PS_THEME_DIR_.'order-carrier.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'order-carrier.tpl'); break; case 3: - self::$smarty->display(_PS_THEME_DIR_.'order-payment.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'order-payment.tpl'); break; default: - self::$smarty->display(_PS_THEME_DIR_.'shopping-cart.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'shopping-cart.tpl'); break; } } @@ -184,20 +182,20 @@ class OrderControllerCore extends ParentOrderController { global $isVirtualCart; - if ($this->step >= 2 AND (!self::$cart->id_address_delivery OR !self::$cart->id_address_invoice)) + if ($this->step >= 2 AND (!$this->context->cart->id_address_delivery OR !$this->context->cart->id_address_invoice)) Tools::redirect('index.php?controller=order&step=1'); - $delivery = new Address((int)(self::$cart->id_address_delivery)); - $invoice = new Address((int)(self::$cart->id_address_invoice)); + $delivery = new Address((int)($this->context->cart->id_address_delivery)); + $invoice = new Address((int)($this->context->cart->id_address_invoice)); if ($delivery->deleted OR $invoice->deleted) { if ($delivery->deleted) - unset(self::$cart->id_address_delivery); + unset($this->context->cart->id_address_delivery); if ($invoice->deleted) - unset(self::$cart->id_address_invoice); + unset($this->context->cart->id_address_invoice); Tools::redirect('index.php?controller=order&step=1'); } - elseif ($this->step >= 3 AND !self::$cart->id_carrier AND !$isVirtualCart) + elseif ($this->step >= 3 AND !$this->context->cart->id_carrier AND !$isVirtualCart) Tools::redirect('index.php?controller=order&step=2'); } @@ -210,9 +208,9 @@ class OrderControllerCore extends ParentOrderController $this->errors[] = Tools::displayError('This address is not in a valid area.'); else { - self::$cart->id_address_delivery = (int)(Tools::getValue('id_address_delivery')); - self::$cart->id_address_invoice = Tools::isSubmit('same') ? self::$cart->id_address_delivery : (int)(Tools::getValue('id_address_invoice')); - if (!self::$cart->update()) + $this->context->cart->id_address_delivery = (int)(Tools::getValue('id_address_delivery')); + $this->context->cart->id_address_invoice = Tools::isSubmit('same') ? $this->context->cart->id_address_delivery : (int)(Tools::getValue('id_address_invoice')); + if (!$this->context->cart->update()) $this->errors[] = Tools::displayError('An error occurred while updating your cart.'); if (Tools::isSubmit('message')) @@ -237,14 +235,14 @@ class OrderControllerCore extends ParentOrderController if (sizeof($this->errors)) { - self::$smarty->assign('errors', $this->errors); + $this->context->smarty->assign('errors', $this->errors); $this->_assignCarrier(); $this->step = 2; $this->displayContent(); include(dirname(__FILE__).'/../footer.php'); exit; } - $orderTotal = self::$cart->getOrderTotal(); + $orderTotal = $this->context->cart->getOrderTotal(); } /* Address step */ @@ -252,24 +250,22 @@ class OrderControllerCore extends ParentOrderController { parent::_assignAddress(); - self::$smarty->assign('cart', self::$cart); - if (self::$cookie->is_guest) + $this->context->smarty->assign('cart', $this->context->cart); + if ($this->context->customer->is_guest) Tools::redirect('index.php?controller=order&step=2'); } /* Carrier step */ protected function _assignCarrier() { - if (isset(self::$cookie->id_customer)) - $customer = new Customer((int)(self::$cookie->id_customer)); - else + if (!isset($this->context->customer->id)) die(Tools::displayError('Fatal error: No customer')); // Assign carrier parent::_assignCarrier(); // Assign wrapping and TOS $this->_assignWrappingAndTOS(); - self::$smarty->assign('is_guest' ,(isset(self::$cookie->is_guest) ? self::$cookie->is_guest : 0)); + $this->context->smarty->assign('is_guest' ,(isset($this->context->customer->is_guest) ? $this->context->customer->is_guest : 0)); } /* Payment step */ @@ -281,12 +277,12 @@ class OrderControllerCore extends ParentOrderController Hook::backBeforePayment('order.php?step=3'); /* We may need to display an order summary */ - self::$smarty->assign(self::$cart->getSummaryDetails()); - self::$smarty->assign(array( + $this->context->smarty->assign($this->context->cart->getSummaryDetails()); + $this->context->smarty->assign(array( 'total_price' => (float)($orderTotal), 'taxes_enabled' => (int)(Configuration::get('PS_TAX')) )); - self::$cookie->checkedTOS = '1'; + $this->context->cart->checkedTOS = '1'; parent::_assignPayment(); } diff --git a/controllers/OrderDetailController.php b/controllers/OrderDetailController.php index 1f866fea3..0f58fc116 100644 --- a/controllers/OrderDetailController.php +++ b/controllers/OrderDetailController.php @@ -58,10 +58,10 @@ class OrderDetailControllerCore extends FrontController if(!sizeof($this->errors)) { $order = new Order((int)($idOrder)); - if (Validate::isLoadedObject($order) AND $order->id_customer == self::$cookie->id_customer) + if (Validate::isLoadedObject($order) AND $order->id_customer == $this->context->customer->id) { $message = new Message(); - $message->id_customer = (int)(self::$cookie->id_customer); + $message->id_customer = (int)$this->context->customer->id; $message->message = $msgText; $message->id_order = (int)($idOrder); $message->private = false; @@ -74,9 +74,9 @@ class OrderDetailControllerCore extends FrontController $to = strval($to->email); } $toName = strval(Configuration::get('PS_SHOP_NAME')); - $customer = new Customer((int)(self::$cookie->id_customer)); + $customer = $context->customer->id; if (Validate::isLoadedObject($customer)) - Mail::Send((int)(self::$cookie->id_lang), 'order_customer_comment', Mail::l('Message from a customer'), + Mail::Send($this->context->language->id, 'order_customer_comment', Mail::l('Message from a customer'), array( '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, @@ -99,7 +99,7 @@ class OrderDetailControllerCore extends FrontController else { $order = new Order($id_order); - if (Validate::isLoadedObject($order) AND $order->id_customer == self::$cookie->id_customer) + if (Validate::isLoadedObject($order) AND $order->id_customer == $this->context->customer->id) { $id_order_state = (int)($order->getCurrentState()); $carrier = new Carrier((int)($order->id_carrier), (int)($order->id_lang)); @@ -114,7 +114,7 @@ class OrderDetailControllerCore extends FrontController $deliveryAddressFormatedValues = AddressFormat::getFormattedAddressFieldsValues($addressDelivery, $dlv_adr_fields); if ($order->total_discounts > 0) - self::$smarty->assign('total_old', (float)($order->total_paid - $order->total_discounts)); + $this->context->smarty->assign('total_old', (float)($order->total_paid - $order->total_discounts)); $products = $order->getProducts(); $customizedDatas = Product::getAllCustomizedDatas((int)($order->id_cart)); @@ -122,26 +122,26 @@ class OrderDetailControllerCore extends FrontController $customer = new Customer($order->id_customer); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'shop_name' => strval(Configuration::get('PS_SHOP_NAME')), 'order' => $order, 'return_allowed' => (int)($order->isReturnable()), 'currency' => new Currency($order->id_currency), 'order_state' => (int)($id_order_state), 'invoiceAllowed' => (int)(Configuration::get('PS_INVOICE')), - 'invoice' => (OrderState::invoiceAvailable((int)($id_order_state)) AND $order->invoice_number), - 'order_history' => $order->getHistory((int)(self::$cookie->id_lang), false, true), + 'invoice' => (OrderState::invoiceAvailable($id_order_state) AND $order->invoice_number), + 'order_history' => $order->getHistory($this->context->language->id, false, true), 'products' => $products, 'discounts' => $order->getDiscounts(), 'carrier' => $carrier, 'address_invoice' => $addressInvoice, - 'invoiceState' => (Validate::isLoadedObject($addressInvoice) AND $addressInvoice->id_state) ? new State((int)($addressInvoice->id_state)) : false, + 'invoiceState' => (Validate::isLoadedObject($addressInvoice) AND $addressInvoice->id_state) ? new State($addressInvoice->id_state) : false, 'address_delivery' => $addressDelivery, 'inv_adr_fields' => $inv_adr_fields, 'dlv_adr_fields' => $dlv_adr_fields, 'invoiceAddressFormatedValues' => $invoiceAddressFormatedValues, 'deliveryAddressFormatedValues' => $deliveryAddressFormatedValues, - 'deliveryState' => (Validate::isLoadedObject($addressDelivery) AND $addressDelivery->id_state) ? new State((int)($addressDelivery->id_state)) : false, + 'deliveryState' => (Validate::isLoadedObject($addressDelivery) AND $addressDelivery->id_state) ? new State($addressDelivery->id_state) : false, 'is_guest' => false, 'messages' => Message::getMessagesByOrderId((int)($order->id)), 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, @@ -150,8 +150,8 @@ class OrderDetailControllerCore extends FrontController 'group_use_tax' => (Group::getPriceDisplayMethod($customer->id_default_group) == PS_TAX_INC), 'customizedDatas' => $customizedDatas)); if ($carrier->url AND $order->shipping_number) - self::$smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); - self::$smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order))); + $this->context->smarty->assign('followup', str_replace('@', $order->shipping_number, $carrier->url)); + $this->context->smarty->assign('HOOK_ORDERDETAILDISPLAYED', Module::hookExec('orderDetailDisplayed', array('order' => $order))); Module::hookExec('OrderDetail', array('carrier' => $carrier, 'order' => $order)); unset($carrier); @@ -173,7 +173,7 @@ class OrderDetailControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'order-detail.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'order-detail.tpl'); } public function displayFooter() diff --git a/controllers/OrderFollowController.php b/controllers/OrderFollowController.php index 3c19be032..aa222743d 100644 --- a/controllers/OrderFollowController.php +++ b/controllers/OrderFollowController.php @@ -56,10 +56,10 @@ class OrderFollowControllerCore extends FrontController $order = new Order((int)($id_order)); if (!$order->isReturnable()) Tools::redirect('index.php?controller=order-follow&errorNotReturnable'); - if ($order->id_customer != self::$cookie->id_customer) + if ($order->id_customer != $this->context->customer->id) die(Tools::displayError()); $orderReturn = new OrderReturn(); - $orderReturn->id_customer = (int)(self::$cookie->id_customer); + $orderReturn->id_customer = (int)$this->context->customer->id; $orderReturn->id_order = $id_order; $orderReturn->question = strval(Tools::getValue('returnText')); if (empty($orderReturn->question)) @@ -74,19 +74,19 @@ class OrderFollowControllerCore extends FrontController Tools::redirect('index.php?controller=order-follow'); } - $ordersReturn = OrderReturn::getOrdersReturn((int)(self::$cookie->id_customer)); + $ordersReturn = OrderReturn::getOrdersReturn($this->context->customer->id); if (Tools::isSubmit('errorQuantity')) - self::$smarty->assign('errorQuantity', true); + $this->context->smarty->assign('errorQuantity', true); elseif (Tools::isSubmit('errorMsg')) - self::$smarty->assign('errorMsg', true); + $this->context->smarty->assign('errorMsg', true); elseif (Tools::isSubmit('errorDetail1')) - self::$smarty->assign('errorDetail1', true); + $this->context->smarty->assign('errorDetail1', true); elseif (Tools::isSubmit('errorDetail2')) - self::$smarty->assign('errorDetail2', true); + $this->context->smarty->assign('errorDetail2', true); elseif (Tools::isSubmit('errorNotReturnable')) - self::$smarty->assign('errorNotReturnable',true); + $this->context->smarty->assign('errorNotReturnable',true); - self::$smarty->assign('ordersReturn', $ordersReturn); + $this->context->smarty->assign('ordersReturn', $ordersReturn); } public function setMedia() @@ -100,7 +100,7 @@ class OrderFollowControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'order-follow.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'order-follow.tpl'); } } diff --git a/controllers/OrderOpcController.php b/controllers/OrderOpcController.php index 4762e97bc..19ed271e3 100644 --- a/controllers/OrderOpcController.php +++ b/controllers/OrderOpcController.php @@ -35,10 +35,10 @@ class OrderOpcControllerCore extends ParentOrderController { parent::preProcess(); if ($this->nbProducts) - self::$smarty->assign('virtual_cart', false); - $this->isLogged = (bool)((int)(self::$cookie->id_customer) AND Customer::customerIdExistsStatic((int)(self::$cookie->id_customer))); + $this->context->smarty->assign('virtual_cart', false); + $this->isLogged = (bool)($this->context->customer->id AND Customer::customerIdExistsStatic((int)($this->context->cookie->id_customer))); - if (self::$cart->nbProducts()) + if ($this->context->cart->nbProducts()) { if (Tools::isSubmit('ajax')) { @@ -62,7 +62,7 @@ class OrderOpcControllerCore extends ParentOrderController if ($this->_processCarrier()) { $return = array( - 'summary' => self::$cart->getSummaryDetails(), + 'summary' => $this->context->cart->getSummaryDetails(), 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods() ); @@ -78,7 +78,7 @@ class OrderOpcControllerCore extends ParentOrderController case 'updateTOSStatusAndGetPayments': if (Tools::isSubmit('checked')) { - self::$cookie->checkedTOS = (int)(Tools::getValue('checked')); + $this->context->cookie->checkedTOS = (int)(Tools::getValue('checked')); die(Tools::jsonEncode(array( 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods() @@ -91,18 +91,17 @@ class OrderOpcControllerCore extends ParentOrderController case 'editCustomer': if (!$this->isLogged) exit; - $customer = new Customer((int)self::$cookie->id_customer); if (Tools::getValue('years')) - $customer->birthday = (int)Tools::getValue('years').'-'.(int)Tools::getValue('months').'-'.(int)Tools::getValue('days'); + $this->context->customer->birthday = (int)Tools::getValue('years').'-'.(int)Tools::getValue('months').'-'.(int)Tools::getValue('days'); $_POST['lastname'] = $_POST['customer_lastname']; $_POST['firstname'] = $_POST['customer_firstname']; - $this->errors = $customer->validateControler(); - $customer->newsletter = (int)Tools::isSubmit('newsletter'); - $customer->optin = (int)Tools::isSubmit('optin'); + $this->errors = $this->context->customer->validateControler(); + $this->context->customer->newsletter = (int)Tools::isSubmit('newsletter'); + $this->context->customer->optin = (int)Tools::isSubmit('optin'); $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, - 'id_customer' => (int)self::$cookie->id_customer, + 'id_customer' => (int)$this->context->customer->id, 'token' => Tools::getToken(false) ); if (!sizeof($this->errors)) @@ -112,17 +111,17 @@ class OrderOpcControllerCore extends ParentOrderController die(Tools::jsonEncode($return)); break; case 'getAddressBlockAndCarriersAndPayments': - if (self::$cookie->isLogged()) + if ($this->context->customer->isLogged()) { // check if customer have addresses - if (!Customer::getAddressesTotalById((int)(self::$cookie->id_customer))) + if (!Customer::getAddressesTotalById($this->context->customer->id)) die(Tools::jsonEncode(array('no_address' => 1))); if (file_exists(_PS_MODULE_DIR_.'blockuserinfo/blockuserinfo.php')) { include_once(_PS_MODULE_DIR_.'blockuserinfo/blockuserinfo.php'); $blockUserInfo = new BlockUserInfo(); } - self::$smarty->assign('isVirtualCart', self::$cart->isVirtualCart()); + $this->context->smarty->assign('isVirtualCart', $this->context->cart->isVirtualCart()); $this->_processAddressFormat(); $this->_assignAddress(); // Wrapping fees @@ -130,14 +129,14 @@ class OrderOpcControllerCore extends ParentOrderController $wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX'))); $wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100))); $return = array( - 'summary' => self::$cart->getSummaryDetails(), - 'order_opc_adress' => self::$smarty->fetch(_PS_THEME_DIR_.'order-address.tpl'), + 'summary' => $this->context->cart->getSummaryDetails(), + 'order_opc_adress' => $this->context->smarty->fetch(_PS_THEME_DIR_.'order-address.tpl'), 'block_user_info' => (isset($blockUserInfo) ? $blockUserInfo->hookTop(array()) : ''), 'carrier_list' => $this->_getCarrierList(), 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), 'no_address' => 0, - 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)(self::$cookie->id_currency)))) + 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)($this->context->cookie->id_currency)))) ); die(Tools::jsonEncode($return)); } @@ -147,21 +146,21 @@ class OrderOpcControllerCore extends ParentOrderController /* Bypass payment step if total is 0 */ if (($id_order = $this->_checkFreeOrder()) AND $id_order) { - $email = self::$cookie->email; - if (self::$cookie->is_guest) - self::$cookie->logout(); // If guest we clear the cookie for security reason + $email = $this->context->customer->email; + if ($this->context->customer->is_guest) + $this->context->cookie->logout(); // If guest we clear the cookie for security reason die('freeorder:'.$id_order.':'.$email); } exit; break; case 'updateAddressesSelected': - if (self::$cookie->isLogged(true)) + if ($this->context->cookie->isLogged(true)) { $id_address_delivery = (int)(Tools::getValue('id_address_delivery')); $id_address_invoice = (int)(Tools::getValue('id_address_invoice')); $address_delivery = new Address((int)(Tools::getValue('id_address_delivery'))); $address_invoice = ((int)(Tools::getValue('id_address_delivery')) == (int)(Tools::getValue('id_address_invoice')) ? $address_delivery : new Address((int)(Tools::getValue('id_address_invoice')))); - if ($address_delivery->id_customer != self::$cookie->id_customer || $address_invoice->id_customer != self::$cookie->id_customer) + if ($address_delivery->id_customer != $this->context->customer->id || $address_invoice->id_customer != $this->context->customer->id) $this->errors[] = Tools::displayError('This address is not yours.'); elseif (!Address::isCountryActiveById((int)(Tools::getValue('id_address_delivery')))) $this->errors[] = Tools::displayError('This address is not in a valid area.'); @@ -169,18 +168,15 @@ class OrderOpcControllerCore extends ParentOrderController $this->errors[] = Tools::displayError('This address is invalid.'); else { - self::$cart->id_address_delivery = (int)(Tools::getValue('id_address_delivery')); - self::$cart->id_address_invoice = Tools::isSubmit('same') ? self::$cart->id_address_delivery : (int)(Tools::getValue('id_address_invoice')); - if (!self::$cart->update()) + $this->context->cart->id_address_delivery = (int)(Tools::getValue('id_address_delivery')); + $this->context->cart->id_address_invoice = Tools::isSubmit('same') ? $this->context->cart->id_address_delivery : (int)(Tools::getValue('id_address_invoice')); + if (!$this->context->cart->update()) $this->errors[] = Tools::displayError('An error occurred while updating your cart.'); if (!sizeof($this->errors)) { - if (self::$cookie->id_customer) - { - $customer = new Customer((int)(self::$cookie->id_customer)); - $groups = $customer->getGroups(); - } + if ($this->context->customer->id) + $groups = $this->context->customer->getGroups(); else $groups = array(1); $result = $this->_getCarrierList(); @@ -189,10 +185,10 @@ class OrderOpcControllerCore extends ParentOrderController $wrapping_fees_tax = new Tax((int)(Configuration::get('PS_GIFT_WRAPPING_TAX'))); $wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100))); $result = array_merge($result, array( - 'summary' => self::$cart->getSummaryDetails(), + 'summary' => $this->context->cart->getSummaryDetails(), 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => $this->_getPaymentMethods(), - 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)(self::$cookie->id_currency)))) + 'gift_price' => Tools::displayPrice(Tools::convertPrice(Product::getTaxCalculationMethod() == 1 ? $wrapping_fees : $wrapping_fees_tax_inc, new Currency((int)($this->context->cookie->id_currency)))) )); die(Tools::jsonEncode($result)); } @@ -233,10 +229,10 @@ class OrderOpcControllerCore extends ParentOrderController $this->_assignWrappingAndTOS(); $selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT')); - $countries = Country::getCountries((int)(self::$cookie->id_lang), true); - self::$smarty->assign(array( + $countries = Country::getCountries($this->context->language->id, true); + $this->context->smarty->assign(array( 'isLogged' => $this->isLogged, - 'isGuest' => isset(self::$cookie->is_guest) ? self::$cookie->is_guest : 0, + 'isGuest' => isset($this->context->cookie->is_guest) ? $this->context->cookie->is_guest : 0, 'countries' => $countries, 'sl_country' => isset($selectedCountry) ? $selectedCountry : 0, 'PS_GUEST_CHECKOUT_ENABLED' => Configuration::get('PS_GUEST_CHECKOUT_ENABLED'), @@ -247,15 +243,15 @@ class OrderOpcControllerCore extends ParentOrderController $years = Tools::dateYears(); $months = Tools::dateMonths(); $days = Tools::dateDays(); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'years' => $years, 'months' => $months, 'days' => $days, )); /* Load guest informations */ - if ($this->isLogged AND self::$cookie->is_guest) - self::$smarty->assign('guestInformations', $this->_getGuestInformations()); + if ($this->isLogged AND $this->context->cookie->is_guest) + $this->context->smarty->assign('guestInformations', $this->_getGuestInformations()); if ($this->isLogged) $this->_assignAddress(); // ADDRESS @@ -265,7 +261,7 @@ class OrderOpcControllerCore extends ParentOrderController $this->_assignPayment(); Tools::safePostVars(); - self::$smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active); + $this->context->smarty->assign('newsletter', (int)Module::getInstanceByName('blocknewsletter')->active); } public function displayHeader() @@ -279,7 +275,7 @@ class OrderOpcControllerCore extends ParentOrderController parent::displayContent(); $this->_processAddressFormat(); - self::$smarty->display(_PS_THEME_DIR_.'order-opc.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'order-opc.tpl'); } public function displayFooter() @@ -290,8 +286,8 @@ class OrderOpcControllerCore extends ParentOrderController protected function _getGuestInformations() { - $customer = new Customer((int)(self::$cookie->id_customer)); - $address_delivery = new Address((int)self::$cart->id_address_delivery); + $customer = $this->context->customer; + $address_delivery = new Address($this->context->cart->id_address_delivery); if ($customer->birthday) $birthday = explode('-', $customer->birthday); @@ -299,13 +295,13 @@ class OrderOpcControllerCore extends ParentOrderController $birthday = array('0', '0', '0'); return array( - 'id_customer' => (int)(self::$cookie->id_customer), + 'id_customer' => (int)$customer->id, 'email' => Tools::htmlentitiesUTF8($customer->email), 'customer_lastname' => Tools::htmlentitiesUTF8($customer->lastname), 'customer_firstname' => Tools::htmlentitiesUTF8($customer->firstname), 'newsletter' => (int)$customer->newsletter, 'optin' => (int)$customer->optin, - 'id_address_delivery' => (int)self::$cart->id_address_delivery, + 'id_address_delivery' => (int)$this->context->cart->id_address_delivery, 'company' => Tools::htmlentitiesUTF8($address_delivery->company), 'lastname' => Tools::htmlentitiesUTF8($address_delivery->lastname), 'firstname' => Tools::htmlentitiesUTF8($address_delivery->firstname), @@ -330,7 +326,7 @@ class OrderOpcControllerCore extends ParentOrderController if (!$this->isLogged) { $carriers = Carrier::getCarriersForOrder(Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT'))); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'checked' => $this->_setDefaultCarrierSelection($carriers), 'carriers' => $carriers, 'default_carrier' => (int)(Configuration::get('PS_CARRIER_DEFAULT')), @@ -344,7 +340,7 @@ class OrderOpcControllerCore extends ParentOrderController protected function _assignPayment() { - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'HOOK_TOP_PAYMENT' => ($this->isLogged ? Module::hookExec('paymentTop') : ''), 'HOOK_PAYMENT' => $this->_getPaymentMethods() )); @@ -354,41 +350,41 @@ class OrderOpcControllerCore extends ParentOrderController { if (!$this->isLogged) return '

'.Tools::displayError('Please sign in to see payment methods').'

'; - if (self::$cart->OrderExists()) + if ($this->context->cart->OrderExists()) return '

'.Tools::displayError('Error: this order is already validated').'

'; - if (!self::$cart->id_customer OR !Customer::customerIdExistsStatic(self::$cart->id_customer) OR Customer::isBanned(self::$cart->id_customer)) + if (!$this->context->cart->id_customer OR !Customer::customerIdExistsStatic($this->context->cart->id_customer) OR Customer::isBanned($this->context->cart->id_customer)) return '

'.Tools::displayError('Error: no customer').'

'; - $address_delivery = new Address(self::$cart->id_address_delivery); - $address_invoice = (self::$cart->id_address_delivery == self::$cart->id_address_invoice ? $address_delivery : new Address(self::$cart->id_address_invoice)); - if (!self::$cart->id_address_delivery OR !self::$cart->id_address_invoice OR !Validate::isLoadedObject($address_delivery) OR !Validate::isLoadedObject($address_invoice) OR $address_invoice->deleted OR $address_delivery->deleted) + $address_delivery = new Address($this->context->cart->id_address_delivery); + $address_invoice = ($this->context->cart->id_address_delivery == $this->context->cart->id_address_invoice ? $address_delivery : new Address($this->context->cart->id_address_invoice)); + if (!$this->context->cart->id_address_delivery OR !$this->context->cart->id_address_invoice OR !Validate::isLoadedObject($address_delivery) OR !Validate::isLoadedObject($address_invoice) OR $address_invoice->deleted OR $address_delivery->deleted) return '

'.Tools::displayError('Error: please choose an address').'

'; - if (!self::$cart->id_carrier AND !self::$cart->isVirtualCart()) + if (!$this->context->cart->id_carrier AND !$this->context->cart->isVirtualCart()) return '

'.Tools::displayError('Error: please choose a carrier').'

'; - elseif (self::$cart->id_carrier != 0) + elseif ($this->context->cart->id_carrier != 0) { - $carrier = new Carrier((int)(self::$cart->id_carrier)); + $carrier = new Carrier((int)($this->context->cart->id_carrier)); if (!Validate::isLoadedObject($carrier) OR $carrier->deleted OR !$carrier->active) return '

'.Tools::displayError('Error: the carrier is invalid').'

'; } - if (!self::$cart->id_currency) + if (!$this->context->cart->id_currency) return '

'.Tools::displayError('Error: no currency has been selected').'

'; - if (!self::$cookie->checkedTOS AND Configuration::get('PS_CONDITIONS')) + if (!$this->context->cookie->checkedTOS AND Configuration::get('PS_CONDITIONS')) return '

'.Tools::displayError('Please accept Terms of Service').'

'; /* If some products have disappear */ - if (!self::$cart->checkQuantities()) + if (!$this->context->cart->checkQuantities()) return '

'.Tools::displayError('An item in your cart is no longer available, you cannot proceed with your order.').'

'; /* Check minimal amount */ - $currency = Currency::getCurrency((int)self::$cart->id_currency); + $currency = Currency::getCurrency((int)$this->context->cart->id_currency); $minimalPurchase = Tools::convertPrice((float)Configuration::get('PS_PURCHASE_MINIMUM'), $currency); - if (self::$cart->getOrderTotal(false) < $minimalPurchase) + if ($this->context->cart->getOrderTotal(false) < $minimalPurchase) return '

'.Tools::displayError('A minimum purchase total of').' '.Tools::displayPrice($minimalPurchase, $currency). ' '.Tools::displayError('is required in order to validate your order.').'

'; /* Bypass payment step if total is 0 */ - if (self::$cart->getOrderTotal() <= 0) + if ($this->context->cart->getOrderTotal() <= 0) return '

'; $return = Module::hookExecPayment(); @@ -399,15 +395,12 @@ class OrderOpcControllerCore extends ParentOrderController protected function _getCarrierList() { - $address_delivery = new Address(self::$cart->id_address_delivery); - if (self::$cookie->id_customer) - { - $customer = new Customer((int)(self::$cookie->id_customer)); - $groups = $customer->getGroups(); - } + $address_delivery = new Address($this->context->cart->id_address_delivery); + if ($this->context->customer->id) + $groups = $this->context->customer->getGroups(); else $groups = array(1); - if (!Address::isCountryActiveById((int)(self::$cart->id_address_delivery))) + if (!Address::isCountryActiveById((int)($this->context->cart->id_address_delivery))) $this->errors[] = Tools::displayError('This address is not in a valid area.'); elseif (!Validate::isLoadedObject($address_delivery) OR $address_delivery->deleted) $this->errors[] = Tools::displayError('This address is invalid.'); @@ -433,8 +426,8 @@ class OrderOpcControllerCore extends ParentOrderController { $selectedCountry = (int)(Configuration::get('PS_COUNTRY_DEFAULT')); - $address_delivery = new Address((int)self::$cart->id_address_delivery); - $address_invoice = new Address((int)self::$cart->id_address_invoice); + $address_delivery = new Address((int)$this->context->cart->id_address_delivery); + $address_invoice = new Address((int)$this->context->cart->id_address_invoice); $inv_adr_fields = AddressFormat::getOrderedAddressFields((int)$address_delivery->id_country); $dlv_adr_fields = AddressFormat::getOrderedAddressFields((int)$address_invoice->id_country); @@ -448,8 +441,8 @@ class OrderOpcControllerCore extends ParentOrderController foreach(explode(' ',$fields_line) as $field_item) ${$adr_type.'_all_fields'}[] = trim($field_item); - self::$smarty->assign($adr_type.'_adr_fields', ${$adr_type.'_adr_fields'}); - self::$smarty->assign($adr_type.'_all_fields', ${$adr_type.'_all_fields'}); + $this->context->smarty->assign($adr_type.'_adr_fields', ${$adr_type.'_adr_fields'}); + $this->context->smarty->assign($adr_type.'_all_fields', ${$adr_type.'_all_fields'}); } } diff --git a/controllers/OrderReturnController.php b/controllers/OrderReturnController.php index 91ff15761..b2eff10cf 100644 --- a/controllers/OrderReturnController.php +++ b/controllers/OrderReturnController.php @@ -49,16 +49,16 @@ class OrderReturnControllerCore extends FrontController else { $orderRet = new OrderReturn((int)($_GET['id_order_return'])); - if (Validate::isLoadedObject($orderRet) AND $orderRet->id_customer == self::$cookie->id_customer) + if (Validate::isLoadedObject($orderRet) AND $orderRet->id_customer == $this->context->cookie->id_customer) { $order = new Order((int)($orderRet->id_order)); if (Validate::isLoadedObject($order)) { $state = new OrderReturnState((int)($orderRet->state)); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'orderRet' => $orderRet, 'order' => $order, - 'state_name' => $state->name[(int)(self::$cookie->id_lang)], + 'state_name' => $state->name[(int)$this->context->language->id], 'return_allowed' => false, 'products' => OrderReturn::getOrdersReturnProducts((int)($orderRet->id), $order), 'returnedCustomizations' => OrderReturn::getReturnedCustomizedProducts((int)($orderRet->id_order)), @@ -72,7 +72,7 @@ class OrderReturnControllerCore extends FrontController $this->errors[] = Tools::displayError('Cannot find this order return'); } - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'errors' => $this->errors, 'nbdaysreturn' => (int)(Configuration::get('PS_ORDER_RETURN_NB_DAYS')) )); @@ -87,7 +87,7 @@ class OrderReturnControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'order-return.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'order-return.tpl'); } public function displayFooter() diff --git a/controllers/OrderSlipController.php b/controllers/OrderSlipController.php index 76dc412ec..ce5417e5a 100644 --- a/controllers/OrderSlipController.php +++ b/controllers/OrderSlipController.php @@ -48,13 +48,13 @@ class OrderSlipControllerCore extends FrontController public function process() { parent::process(); - self::$smarty->assign('ordersSlip', OrderSlip::getOrdersSlip((int)(self::$cookie->id_customer))); + $this->context->smarty->assign('ordersSlip', OrderSlip::getOrdersSlip((int)($this->context->cookie->id_customer))); } public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'order-slip.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'order-slip.tpl'); } } diff --git a/controllers/PageNotFoundController.php b/controllers/PageNotFoundController.php index bbcd27c3b..6850573ca 100644 --- a/controllers/PageNotFoundController.php +++ b/controllers/PageNotFoundController.php @@ -29,7 +29,7 @@ class PageNotFoundControllerCore extends FrontController { public function displayContent() { - self::$smarty->display(_PS_THEME_DIR_.'404.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'404.tpl'); } } diff --git a/controllers/ParentOrderController.php b/controllers/ParentOrderController.php index 92ddd612a..7f1338e62 100644 --- a/controllers/ParentOrderController.php +++ b/controllers/ParentOrderController.php @@ -45,14 +45,12 @@ class ParentOrderControllerCore extends FrontController public function init() { parent::init(); - $context = Context::getContext(); - $this->nbProducts = $context->cart->nbProducts(); + $this->nbProducts = $this->context->cart->nbProducts(); } public function preProcess() { global $isVirtualCart; - $context = Context::getContext(); parent::preProcess(); // Redirect to the good order process @@ -70,7 +68,7 @@ class ParentOrderControllerCore extends FrontController if (Tools::isSubmit('submitReorder') AND $id_order = (int)Tools::getValue('id_order')) { - $oldCart = new Cart(Order::getCartIdStatic($id_order, $context->customer->id)); + $oldCart = new Cart(Order::getCartIdStatic($id_order, $this->context->customer->id)); $duplication = $oldCart->duplicate(); if (!$duplication OR !Validate::isLoadedObject($duplication['cart'])) $this->errors[] = Tools::displayError('Sorry, we cannot renew your order.'); @@ -78,8 +76,8 @@ class ParentOrderControllerCore extends FrontController $this->errors[] = Tools::displayError('Missing items - we are unable to renew your order'); else { - $context->cookie->id_cart = $duplication['cart']->id; - $context->cookie->write(); + $this->context->cookie->id_cart = $duplication['cart']->id; + $this->context->cookie->write(); if (Configuration::get('PS_ORDER_PROCESS_TYPE') == 1) Tools::redirect('index.php?controller=order-opc'); Tools::redirect('index.php?controller=order'); @@ -98,34 +96,34 @@ class ParentOrderControllerCore extends FrontController $discount = new Discount((int)(Discount::getIdByName($discountName))); if (Validate::isLoadedObject($discount)) { - if ($tmpError = $context->cart->checkDiscountValidity($discount, $context->cart->getDiscounts(), $context->cart->getOrderTotal(), $context->cart->getProducts(), true)) + if ($tmpError = $this->context->cart->checkDiscountValidity($discount, $this->context->cart->getDiscounts(), $this->context->cart->getOrderTotal(), $this->context->cart->getProducts(), true)) $this->errors[] = $tmpError; } else $this->errors[] = Tools::displayError('Voucher name invalid.'); if (!sizeof($this->errors)) { - $context->cart->addDiscount((int)($discount->id)); + $this->context->cart->addDiscount((int)($discount->id)); Tools::redirect('index.php?controller=order-opc'); } } - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'errors' => $this->errors, 'discount_name' => Tools::safeOutput($discountName) )); } elseif (isset($_GET['deleteDiscount']) AND Validate::isUnsignedId($_GET['deleteDiscount'])) { - $context->cart->deleteDiscount((int)($_GET['deleteDiscount'])); + $this->context->cart->deleteDiscount((int)($_GET['deleteDiscount'])); Tools::redirect('index.php?controller=order-opc'); } /* Is there only virtual product in cart */ - if ($isVirtualCart = $context->cart->isVirtualCart()) + if ($isVirtualCart = $this->context->cart->isVirtualCart()) $this->_setNoCarrier(); } - self::$smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); + $this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue('back'))); } public function setMedia() @@ -154,25 +152,23 @@ class ParentOrderControllerCore extends FrontController */ protected function _checkFreeOrder() { - $context = Context::getContext(); - if ($context->cart->getOrderTotal() <= 0) + if ($this->context->cart->getOrderTotal() <= 0) { $order = new FreeOrder(); $order->free_order_class = true; - $order->validateOrder($context->cart->id, _PS_OS_PAYMENT_, 0, Tools::displayError('Free order', false)); - return (int)Order::getOrderByCartId($context->cart->id); + $order->validateOrder($this->context->cart->id, _PS_OS_PAYMENT_, 0, Tools::displayError('Free order', false)); + return (int)Order::getOrderByCartId($this->context->cart->id); } return false; } protected function _updateMessage($messageContent) { - $context = Context::getContext(); if ($messageContent) { if (!Validate::isMessage($messageContent)) $this->errors[] = Tools::displayError('Invalid message'); - elseif ($oldMessage = Message::getMessageByCartId((int)($context->cart->id))) + elseif ($oldMessage = Message::getMessageByCartId((int)($this->context->cart->id))) { $message = new Message((int)($oldMessage['id_message'])); $message->message = htmlentities($messageContent, ENT_COMPAT, 'UTF-8'); @@ -182,14 +178,14 @@ class ParentOrderControllerCore extends FrontController { $message = new Message(); $message->message = htmlentities($messageContent, ENT_COMPAT, 'UTF-8'); - $message->id_cart = (int)($context->cart->id); - $message->id_customer = (int)($context->cart->id_customer); + $message->id_cart = (int)($this->context->cart->id); + $message->id_customer = (int)($this->context->cart->id_customer); $message->add(); } } else { - if ($oldMessage = Message::getMessageByCartId($context->cart->id)) + if ($oldMessage = Message::getMessageByCartId($this->context->cart->id)) { $message = new Message($oldMessage['id_message']); $message->delete(); @@ -200,20 +196,19 @@ class ParentOrderControllerCore extends FrontController protected function _processCarrier() { - $context = Context::getContext(); - $context->cart->recyclable = (int)(Tools::getValue('recyclable')); - $context->cart->gift = (int)(Tools::getValue('gift')); + $this->context->cart->recyclable = (int)(Tools::getValue('recyclable')); + $this->context->cart->gift = (int)(Tools::getValue('gift')); if ((int)(Tools::getValue('gift'))) { if (!Validate::isMessage($_POST['gift_message'])) $this->errors[] = Tools::displayError('Invalid gift message'); else - $context->cart->gift_message = strip_tags($_POST['gift_message']); + $this->context->cart->gift_message = strip_tags($_POST['gift_message']); } - if (isset($context->customer->id) AND $context->customer->id) + if (isset($this->context->customer->id) AND $this->context->customer->id) { - $address = new Address((int)($context->cart->id_address_delivery)); + $address = new Address((int)($this->context->cart->id_address_delivery)); if (!($id_zone = Address::getZoneById($address->id))) $this->errors[] = Tools::displayError('No zone match with your address'); } @@ -221,22 +216,21 @@ class ParentOrderControllerCore extends FrontController $id_zone = Country::getIdZone((int)Configuration::get('PS_COUNTRY_DEFAULT')); if (Validate::isInt(Tools::getValue('id_carrier')) AND sizeof(Carrier::checkCarrierZone((int)(Tools::getValue('id_carrier')), (int)($id_zone)))) - $context->cart->id_carrier = (int)(Tools::getValue('id_carrier')); - elseif (!$context->cart->isVirtualCart() AND (int)(Tools::getValue('id_carrier')) == 0) + $this->context->cart->id_carrier = (int)(Tools::getValue('id_carrier')); + elseif (!$this->context->cart->isVirtualCart() AND (int)(Tools::getValue('id_carrier')) == 0) $this->errors[] = Tools::displayError('Invalid carrier or no carrier selected'); - Module::hookExec('processCarrier', array('cart' => $context->cart)); + Module::hookExec('processCarrier', array('cart' => $this->context->cart)); - return $context->cart->update(); + return $this->context->cart->update(); } protected function _assignSummaryInformations() { - $context = Context::getContext(); - if (file_exists(_PS_SHIP_IMG_DIR_.$context->cart->id_carrier.'.jpg')) - self::$smarty->assign('carrierPicture', 1); - $summary = $context->cart->getSummaryDetails(); - $customizedDatas = Product::getAllCustomizedDatas($context->cart->id); + if (file_exists(_PS_SHIP_IMG_DIR_.$this->context->cart->id_carrier.'.jpg')) + $this->context->smarty->assign('carrierPicture', 1); + $summary = $this->context->cart->getSummaryDetails(); + $customizedDatas = Product::getAllCustomizedDatas($this->context->cart->id); // override customization tax rate with real tax (tax rules) foreach($summary['products'] AS &$productUpdate) @@ -245,14 +239,14 @@ class ParentOrderControllerCore extends FrontController $productAttributeId = (int)(isset($productUpdate['id_product_attribute']) ? $productUpdate['id_product_attribute'] : $productUpdate['product_attribute_id']); if (isset($customizedDatas[$productId][$productAttributeId])) - $productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $productUpdate['tax_rate'] = Tax::getProductTaxRate($productId, $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); } Product::addCustomizationPrice($summary['products'], $customizedDatas); - if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency($context->cart->id_currency))) + if ($free_ship = Tools::convertPrice((float)(Configuration::get('PS_SHIPPING_FREE_PRICE')), new Currency($this->context->cart->id_currency))) { - $discounts = $context->cart->getDiscounts(); + $discounts = $this->context->cart->getDiscounts(); $total_free_ship = $free_ship - ($summary['total_products_wt'] + $summary['total_discounts']); foreach ($discounts as $discount) if ($discount['id_discount_type'] == 3) @@ -260,30 +254,30 @@ class ParentOrderControllerCore extends FrontController $total_free_ship = 0; break; } - self::$smarty->assign('free_ship', $total_free_ship); + $this->context->smarty->assign('free_ship', $total_free_ship); } // for compatibility with 1.2 themes foreach($summary['products'] AS $key => $product) $summary['products'][$key]['quantity'] = $product['cart_quantity']; - self::$smarty->assign($summary); - self::$smarty->assign(array( + $this->context->smarty->assign($summary); + $this->context->smarty->assign(array( 'token_cart' => Tools::getToken(false), - 'isVirtualCart' => $context->cart->isVirtualCart(), - 'productNumber' => $context->cart->nbProducts(), + 'isVirtualCart' => $this->context->cart->isVirtualCart(), + 'productNumber' => $this->context->cart->nbProducts(), 'voucherAllowed' => Configuration::get('PS_VOUCHERS'), - 'shippingCost' => $context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING), - 'shippingCostTaxExc' => $context->cart->getOrderTotal(false, Cart::ONLY_SHIPPING), + 'shippingCost' => $this->context->cart->getOrderTotal(true, Cart::ONLY_SHIPPING), + 'shippingCostTaxExc' => $this->context->cart->getOrderTotal(false, Cart::ONLY_SHIPPING), 'customizedDatas' => $customizedDatas, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, - 'lastProductAdded' => $context->cart->getLastProduct(), - 'displayVouchers' => Discount::getVouchersToCartDisplay($context->language->id, (isset($context->customer->id) ? $context->customer->id : 0)), - 'currencySign' => $context->currency->sign, - 'currencyRate' => $context->currency->conversion_rate, - 'currencyFormat' => $context->currency->format, - 'currencyBlank' => $context->currency->blank)); - self::$smarty->assign(array( + 'lastProductAdded' => $this->context->cart->getLastProduct(), + 'displayVouchers' => Discount::getVouchersToCartDisplay($this->context->language->id, (isset($this->context->customer->id) ? $this->context->customer->id : 0)), + 'currencySign' => $this->context->currency->sign, + 'currencyRate' => $this->context->currency->conversion_rate, + 'currencyFormat' => $this->context->currency->format, + 'currencyBlank' => $this->context->currency->blank)); + $this->context->smarty->assign(array( 'HOOK_SHOPPING_CART' => Module::hookExec('shoppingCart', $summary), 'HOOK_SHOPPING_CART_EXTRA' => Module::hookExec('shoppingCartExtra', $summary) )); @@ -291,20 +285,19 @@ class ParentOrderControllerCore extends FrontController protected function _assignAddress() { - $context = Context::getContext(); //if guest checkout disabled and flag is_guest in cookies is actived - if(Configuration::get('PS_GUEST_CHECKOUT_ENABLED') == 0 AND ((int)$context->customer->is_guest != Configuration::get('PS_GUEST_CHECKOUT_ENABLED'))) + if(Configuration::get('PS_GUEST_CHECKOUT_ENABLED') == 0 AND ((int)$this->context->customer->is_guest != Configuration::get('PS_GUEST_CHECKOUT_ENABLED'))) { - $context->cookie->logout(); + $this->context->cookie->logout(); Tools::redirect(''); } - elseif (!Customer::getAddressesTotalById($context->customer->id)) + elseif (!Customer::getAddressesTotalById($this->context->customer->id)) Tools::redirect('index.php?controller=address&back=order.php&step=1'); - $customer = $context->customer; + $customer = $this->context->customer; if (Validate::isLoadedObject($customer)) { /* Getting customer addresses */ - $customerAddresses = $customer->getAddresses($context->language->id); + $customerAddresses = $customer->getAddresses($this->context->language->id); // Getting a list of formated address fields with associated values $formatedAddressFieldsValuesList = array(); @@ -319,53 +312,52 @@ class ParentOrderControllerCore extends FrontController unset($tmpAddress); } - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'addresses' => $customerAddresses, 'formatedAddressFieldsValuesList' => $formatedAddressFieldsValuesList)); /* Setting default addresses for cart */ - if ((!isset($context->cart->id_address_delivery) OR empty($context->cart->id_address_delivery)) AND sizeof($customerAddresses)) + if ((!isset($this->context->cart->id_address_delivery) OR empty($this->context->cart->id_address_delivery)) AND sizeof($customerAddresses)) { - $context->cart->id_address_delivery = (int)($customerAddresses[0]['id_address']); + $this->context->cart->id_address_delivery = (int)($customerAddresses[0]['id_address']); $update = 1; } - if ((!isset($context->cart->id_address_invoice) OR empty($context->cart->id_address_invoice)) AND sizeof($customerAddresses)) + if ((!isset($this->context->cart->id_address_invoice) OR empty($this->context->cart->id_address_invoice)) AND sizeof($customerAddresses)) { - $context->cart->id_address_invoice = (int)($customerAddresses[0]['id_address']); + $this->context->cart->id_address_invoice = (int)($customerAddresses[0]['id_address']); $update = 1; } /* Update cart addresses only if needed */ if (isset($update) AND $update) - $context->cart->update(); + $this->context->cart->update(); /* If delivery address is valid in cart, assign it to Smarty */ - if (isset($context->cart->id_address_delivery)) + if (isset($this->context->cart->id_address_delivery)) { - $deliveryAddress = new Address((int)($context->cart->id_address_delivery)); + $deliveryAddress = new Address((int)($this->context->cart->id_address_delivery)); if (Validate::isLoadedObject($deliveryAddress) AND ($deliveryAddress->id_customer == $customer->id)) - self::$smarty->assign('delivery', $deliveryAddress); + $this->context->smarty->assign('delivery', $deliveryAddress); } /* If invoice address is valid in cart, assign it to Smarty */ - if (isset($context->cart->id_address_invoice)) + if (isset($this->context->cart->id_address_invoice)) { - $invoiceAddress = new Address((int)($context->cart->id_address_invoice)); + $invoiceAddress = new Address((int)($this->context->cart->id_address_invoice)); if (Validate::isLoadedObject($invoiceAddress) AND ($invoiceAddress->id_customer == $customer->id)) - self::$smarty->assign('invoice', $invoiceAddress); + $this->context->smarty->assign('invoice', $invoiceAddress); } } - if ($oldMessage = Message::getMessageByCartId((int)($context->cart->id))) - self::$smarty->assign('oldMessage', $oldMessage['message']); + if ($oldMessage = Message::getMessageByCartId((int)($this->context->cart->id))) + $this->context->smarty->assign('oldMessage', $oldMessage['message']); } protected function _assignCarrier() { - $context = Context::getContext(); - $address = new Address($context->cart->id_address_delivery); + $address = new Address($this->context->cart->id_address_delivery); $id_zone = Address::getZoneById($address->id); - $carriers = Carrier::getCarriersForOrder($id_zone, $context->customer->getGroups()); + $carriers = Carrier::getCarriersForOrder($id_zone, $this->context->customer->getGroups()); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'checked' => $this->_setDefaultCarrierSelection($carriers), 'carriers' => $carriers, 'default_carrier' => (int)(Configuration::get('PS_CARRIER_DEFAULT')), @@ -376,36 +368,35 @@ class ParentOrderControllerCore extends FrontController protected function _assignWrappingAndTOS() { - $context = Context::getContext(); // Wrapping fees $wrapping_fees = (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')); $wrapping_fees_tax = new Tax(Configuration::get('PS_GIFT_WRAPPING_TAX')); $wrapping_fees_tax_inc = $wrapping_fees * (1 + (((float)($wrapping_fees_tax->rate) / 100))); // TOS - $cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $context->language->id); - $this->link_conditions = $context->link->getCMSLink($cms, $cms->link_rewrite, true); + $cms = new CMS(Configuration::get('PS_CONDITIONS_CMS_ID'), $this->context->language->id); + $this->link_conditions = $this->context->link->getCMSLink($cms, $cms->link_rewrite, true); if (!strpos($this->link_conditions, '?')) $this->link_conditions .= '?content_only=1'; else $this->link_conditions .= '&content_only=1'; - self::$smarty->assign(array( - 'checkedTOS' => (int)($context->cookie->checkedTOS), + $this->context->smarty->assign(array( + 'checkedTOS' => (int)($this->context->cookie->checkedTOS), 'recyclablePackAllowed' => (int)(Configuration::get('PS_RECYCLABLE_PACK')), 'giftAllowed' => (int)(Configuration::get('PS_GIFT_WRAPPING')), 'cms_id' => (int)(Configuration::get('PS_CONDITIONS_CMS_ID')), 'conditions' => (int)(Configuration::get('PS_CONDITIONS')), 'link_conditions' => $this->link_conditions, - 'recyclable' => (int)($context->cart->recyclable), + 'recyclable' => (int)($this->context->cart->recyclable), 'gift_wrapping_price' => (float)(Configuration::get('PS_GIFT_WRAPPING_PRICE')), - 'total_wrapping_cost' => Tools::convertPrice($wrapping_fees_tax_inc, $context->currency), - 'total_wrapping_tax_exc_cost' => Tools::convertPrice($wrapping_fees, $context->currency))); + 'total_wrapping_cost' => Tools::convertPrice($wrapping_fees_tax_inc, $this->context->currency), + 'total_wrapping_tax_exc_cost' => Tools::convertPrice($wrapping_fees, $this->context->currency))); } protected function _assignPayment() { - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'HOOK_TOP_PAYMENT' => Module::hookExec('paymentTop'), 'HOOK_PAYMENT' => Module::hookExecPayment() )); @@ -417,9 +408,8 @@ class ParentOrderControllerCore extends FrontController */ protected function _setNoCarrier() { - $context = Context::getContext(); - $context->cart->id_carrier = 0; - $context->cart->update(); + $this->context->cart->id_carrier = 0; + $this->context->cart->update(); } /** @@ -430,28 +420,27 @@ class ParentOrderControllerCore extends FrontController */ protected function _setDefaultCarrierSelection($carriers) { - $context = Context::getContext(); if (sizeof($carriers)) { $defaultCarrierIsPresent = false; - if ((int)$context->cart->id_carrier != 0) + if ((int)$this->context->cart->id_carrier != 0) foreach ($carriers AS $carrier) - if ($carrier['id_carrier'] == (int)$context->cart->id_carrier) + if ($carrier['id_carrier'] == (int)$this->context->cart->id_carrier) $defaultCarrierIsPresent = true; if (!$defaultCarrierIsPresent) foreach ($carriers AS $carrier) if ($carrier['id_carrier'] == (int)Configuration::get('PS_CARRIER_DEFAULT')) { $defaultCarrierIsPresent = true; - $context->cart->id_carrier = (int)$carrier['id_carrier']; + $this->context->cart->id_carrier = (int)$carrier['id_carrier']; } if (!$defaultCarrierIsPresent) - $context->cart->id_carrier = (int)$carriers[0]['id_carrier']; + $this->context->cart->id_carrier = (int)$carriers[0]['id_carrier']; } else - $context->cart->id_carrier = 0; - if ($context->cart->update()) - return $context->cart->id_carrier; + $this->context->cart->id_carrier = 0; + if ($this->context->cart->update()) + return $this->context->cart->id_carrier; return 0; } diff --git a/controllers/PasswordController.php b/controllers/PasswordController.php index f587f5b91..8ab8bc257 100644 --- a/controllers/PasswordController.php +++ b/controllers/PasswordController.php @@ -56,14 +56,14 @@ class PasswordControllerCore extends FrontController $this->errors[] = Tools::displayError('You can regenerate your password only every').' '.(int)($min_time).' '.Tools::displayError('minute(s)'); else { - if (Mail::Send((int)(self::$cookie->id_lang), 'password_query', Mail::l('Password query confirmation'), + if (Mail::Send($this->context->language->id, 'password_query', Mail::l('Password query confirmation'), array('{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, - '{url}' => self::$link->getPageLink('password', true, NULL, 'token='.$customer->secure_key.'&id_customer='.(int)$customer->id)), + '{url}' => $this->context->link->getPageLink('password', true, NULL, 'token='.$customer->secure_key.'&id_customer='.(int)$customer->id)), $customer->email, $customer->firstname.' '.$customer->lastname)) - self::$smarty->assign(array('confirmation' => 2, 'email' => $customer->email)); + $this->context->smarty->assign(array('confirmation' => 2, 'email' => $customer->email)); else $this->errors[] = Tools::displayError('Error occurred when sending the e-mail.'); } @@ -85,14 +85,14 @@ class PasswordControllerCore extends FrontController $customer->last_passwd_gen = date('Y-m-d H:i:s', time()); if ($customer->update()) { - if (Mail::Send((int)(self::$cookie->id_lang), 'password', Mail::l('Your password'), + if (Mail::Send($this->context->language->id, 'password', Mail::l('Your password'), array('{email}' => $customer->email, '{lastname}' => $customer->lastname, '{firstname}' => $customer->firstname, '{passwd}' => $password), $customer->email, $customer->firstname.' '.$customer->lastname)) - self::$smarty->assign(array('confirmation' => 1, 'email' => $customer->email)); + $this->context->smarty->assign(array('confirmation' => 1, 'email' => $customer->email)); else $this->errors[] = Tools::displayError('Error occurred when sending the e-mail.'); } @@ -110,7 +110,7 @@ class PasswordControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'password.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'password.tpl'); } } diff --git a/controllers/PdfInvoiceController.php b/controllers/PdfInvoiceController.php index 5e815fceb..39968dafb 100644 --- a/controllers/PdfInvoiceController.php +++ b/controllers/PdfInvoiceController.php @@ -31,7 +31,7 @@ class PdfInvoiceControllerCore extends FrontController { parent::process(); - $cookie = self::$cookie; + $cookie = $this->context->cookie; if (!$cookie->isLogged() AND !Tools::getValue('secure_key')) Tools::redirect('index.php?controller=authentication&back=pdf-invoice'); if (!(int)(Configuration::get('PS_INVOICE'))) diff --git a/controllers/PricesDropController.php b/controllers/PricesDropController.php index 1c27da2fc..e2153b3b4 100644 --- a/controllers/PricesDropController.php +++ b/controllers/PricesDropController.php @@ -45,11 +45,11 @@ class PricesDropControllerCore extends FrontController parent::process(); $this->productSort(); - $nbProducts = Product::getPricesDrop((int)self::$cookie->id_lang, NULL, NULL, true); + $nbProducts = Product::getPricesDrop($this->context->language->id, NULL, NULL, true); $this->pagination($nbProducts); - self::$smarty->assign(array( - 'products' => Product::getPricesDrop((int)self::$cookie->id_lang, (int)$this->p - 1, (int)$this->n, false, $this->orderBy, $this->orderWay), + $this->context->smarty->assign(array( + 'products' => Product::getPricesDrop($this->context->language->id, (int)$this->p - 1, (int)$this->n, false, $this->orderBy, $this->orderWay), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home') @@ -59,7 +59,7 @@ class PricesDropControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'prices-drop.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'prices-drop.tpl'); } } diff --git a/controllers/ProductController.php b/controllers/ProductController.php index 412cc4f56..0ebfa12c5 100644 --- a/controllers/ProductController.php +++ b/controllers/ProductController.php @@ -52,9 +52,8 @@ class ProductControllerCore extends FrontController public function preProcess() { - $context = Context::getContext(); if ($id_product = (int)Tools::getValue('id_product')) - $this->product = new Product($id_product, true, self::$cookie->id_lang, (int)$this->id_current_shop); + $this->product = new Product($id_product, true, $this->context->language->id, $this->id_current_shop); if (!Validate::isLoadedObject($this->product)) { @@ -67,7 +66,7 @@ class ProductControllerCore extends FrontController // $_SERVER['HTTP_HOST'] must be replaced by the real canonical domain if (Validate::isLoadedObject($this->product)) { - $canonicalURL = $context->link->getProductLink($this->product); + $canonicalURL = $this->context->link->getProductLink($this->product); if (!preg_match('/^'.Tools::pRegexp($canonicalURL, '/').'([&?].*)?$/i', Tools::getProtocol().$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])) { header('HTTP/1.0 301 Moved'); @@ -87,16 +86,15 @@ class ProductControllerCore extends FrontController $default_rewrite = array(); foreach ($rewrite_infos AS $infos) - $default_rewrite[$infos['id_lang']] = $context->link->getProductLink((int)$id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int)$infos['id_lang']); + $default_rewrite[$infos['id_lang']] = $this->context->link->getProductLink((int)$id_product, $infos['link_rewrite'], $infos['category_rewrite'], $infos['ean13'], (int)$infos['id_lang']); - self::$smarty->assign('lang_rewrite_urls', $default_rewrite); + $this->context->smarty->assign('lang_rewrite_urls', $default_rewrite); } } public function process() { parent::process(); - $context = Context::getContext(); if (!$id_product = (int)(Tools::getValue('id_product')) OR !Validate::isUnsignedId($id_product)) $this->errors[] = Tools::displayError('Product not found'); @@ -109,48 +107,48 @@ class ProductControllerCore extends FrontController header('HTTP/1.1 404 page not found'); $this->errors[] = Tools::displayError('Pproduct is no longer available.'); } - elseif (!$this->product->checkAccess(isset($context->customer) ? $context->customer->id : 0)) + elseif (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) $this->errors[] = Tools::displayError('You do not have access to this product.'); else { - self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int)($this->product->id))); + $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int)($this->product->id))); if (!$this->product->active) - self::$smarty->assign('adminActionDisplay', true); + $this->context->smarty->assign('adminActionDisplay', true); /* rewrited url set */ - $rewrited_url = $context->link->getProductLink($this->product->id, $this->product->link_rewrite); + $rewrited_url = $this->context->link->getProductLink($this->product->id, $this->product->link_rewrite); /* Product pictures management */ require_once('images.inc.php'); - self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); + $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI']))); if (Tools::isSubmit('submitCustomizedDatas')) { // If cart has not been saved, we need to do it so that customization fields can have an id_cart // We check that the cookie exists first to avoid ghost carts - if (!$context->cart->id && isset($_COOKIE[$context->cookie->getName()])) + if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) { - $context->cart->add(); - $context->cookie->id_cart = (int)$context->cart->id; + $this->context->cart->add(); + $this->context->cookie->id_cart = (int)$this->context->cart->id; } - $this->pictureUpload($this->product, $context->cart); - $this->textRecord($this->product, $context->cart); + $this->pictureUpload($this->product, $this->context->cart); + $this->textRecord($this->product, $this->context->cart); $this->formTargetFormat(); } - elseif (isset($_GET['deletePicture']) AND !$context->cart->deletePictureToProduct($this->product->id, Tools::getValue('deletePicture'))) + elseif (isset($_GET['deletePicture']) AND !$this->context->cart->deletePictureToProduct($this->product->id, Tools::getValue('deletePicture'))) $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture'); - $files = self::$cart->getProductCustomization($this->product->id, _CUSTOMIZE_FILE_, true); + $files = $this->context->cart->getProductCustomization($this->product->id, _CUSTOMIZE_FILE_, true); $pictures = array(); foreach($files as $file) $pictures['pictures_'.$this->product->id.'_'.$file['index']] = $file['value']; - $texts = self::$cart->getProductCustomization($this->product->id, _CUSTOMIZE_TEXTFIELD_, true); + $texts = $this->context->cart->getProductCustomization($this->product->id, _CUSTOMIZE_TEXTFIELD_, true); $textFields = array(); foreach ($texts as $textField) $textFields['textFields_'.$this->product->id.'_'.$textField['index']] = str_replace('
', "\n", $textField['value']); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'pictures' => $pictures, 'textFields' => $textFields)); @@ -162,8 +160,8 @@ class ProductControllerCore extends FrontController $configs = Configuration::getMultiple(array('PS_ORDER_OUT_OF_STOCK', 'PS_LAST_QTIES')); /* Features / Values */ - $features = $this->product->getFrontFeatures((int)(self::$cookie->id_lang)); - $attachments = $this->product->getAttachments((int)(self::$cookie->id_lang)); + $features = $this->product->getFrontFeatures($this->context->language->id); + $attachments = $this->product->getAttachments($this->context->language->id); /* Category */ $category = false; @@ -172,52 +170,52 @@ class ProductControllerCore extends FrontController if (isset($regs[2]) AND is_numeric($regs[2])) { if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[2]))))) - $category = new Category((int)($regs[2]), (int)self::$cookie->id_lang); + $category = new Category((int)($regs[2]), (int)$this->context->cookie->id_lang); } elseif (isset($regs[5]) AND is_numeric($regs[5])) { if (Product::idIsOnCategoryId((int)($this->product->id), array('0' => array('id_category' => (int)($regs[5]))))) - $category = new Category((int)($regs[5]), (int)self::$cookie->id_lang); + $category = new Category((int)($regs[5]), (int)$this->context->cookie->id_lang); } } if (!$category) - $category = new Category($this->product->id_category_default, (int)self::$cookie->id_lang); + $category = new Category($this->product->id_category_default, (int)$this->context->cookie->id_lang); if (isset($category) AND Validate::isLoadedObject($category)) { - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'path' => Tools::getPath((int)$category->id, $this->product->name, true), 'category' => $category, - 'subCategories' => $category->getSubCategories((int)(self::$cookie->id_lang), true), + 'subCategories' => $category->getSubCategories($this->context->language->id, true), 'id_category_current' => (int)($category->id), 'id_category_parent' => (int)($category->id_parent), 'return_category_name' => Tools::safeOutput($category->name))); } else - self::$smarty->assign('path', Tools::getPath((int)$this->product->id_category_default, $this->product->name)); + $this->context->smarty->assign('path', Tools::getPath((int)$this->product->id_category_default, $this->product->name)); - self::$smarty->assign('return_link', (isset($category->id) AND $category->id) ? Tools::safeOutput($context->link->getCategoryLink($category)) : 'javascript: history.back();'); + $this->context->smarty->assign('return_link', (isset($category->id) AND $category->id) ? Tools::safeOutput($this->context->link->getCategoryLink($category)) : 'javascript: history.back();'); $lang = Configuration::get('PS_LANG_DEFAULT'); if (Pack::isPack((int)($this->product->id), (int)($lang)) AND !Pack::isInStock((int)($this->product->id), (int)($lang))) $this->product->quantity = 0; - $id_customer = (isset($context->customer) ? (int)($context->customer->id) : 0); + $id_customer = (isset($this->context->customer) ? (int)($this->context->customer->id) : 0); $group_reduction = (100 - Group::getReduction($id_customer)) / 100; - $id_group = (isset($context->customer) ? $context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_); + $id_group = (isset($this->context->customer) ? $this->context->customer->id_default_group : _PS_DEFAULT_CUSTOMER_GROUP_); $id_country = (int)($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT')); // Tax - $tax = (float)(Tax::getProductTaxRate((int)($this->product->id), $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); - self::$smarty->assign('tax_rate', $tax); + $tax = (float)(Tax::getProductTaxRate((int)($this->product->id), $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); + $this->context->smarty->assign('tax_rate', $tax); - $ecotax_rate = (float) Tax::getProductEcotaxRate($context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); + $ecotax_rate = (float) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}); $ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2); if (Product::$_taxCalculationMethod == PS_TAX_INC && (int)Configuration::get('PS_TAX')) $ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2); - self::$smarty->assign(array( - 'quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int)($this->product->id), $this->id_current_shop, (int)(self::$cookie->id_currency), $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (float)($tax)), + $this->context->smarty->assign(array( + 'quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int)($this->product->id), $this->id_current_shop, (int)($this->context->cookie->id_currency), $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (float)($tax)), 'product' => $this->product, 'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), @@ -233,7 +231,7 @@ class ProductControllerCore extends FrontController 'group_reduction' => $group_reduction, 'col_img_dir' => _PS_COL_IMG_DIR_, )); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($this->product), @@ -243,13 +241,13 @@ class ProductControllerCore extends FrontController 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent') )); - $images = $this->product->getImages((int)self::$cookie->id_lang); + $images = $this->product->getImages((int)$this->context->cookie->id_lang); $productImages = array(); foreach ($images AS $k => $image) { if ($image['cover']) { - self::$smarty->assign('mainImage', $images[0]); + $this->context->smarty->assign('mainImage', $images[0]); $cover = $image; $cover['id_image'] = (Configuration::get('PS_LEGACY_IMAGES') ? ($this->product->id.'-'.$image['id_image']) : $image['id_image']); $cover['id_image_only'] = (int)($image['id_image']); @@ -257,24 +255,24 @@ class ProductControllerCore extends FrontController $productImages[(int)($image['id_image'])] = $image; } if (!isset($cover)) - $cover = array('id_image' => $context->language->iso_code.'-default', 'legend' => 'No picture', 'title' => 'No picture'); + $cover = array('id_image' => $this->context->language->iso_code.'-default', 'legend' => 'No picture', 'title' => 'No picture'); $size = Image::getSize('large'); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'cover' => $cover, 'imgWidth' => (int)($size['width']), 'mediumSize' => Image::getSize('medium'), 'largeSize' => Image::getSize('large'), - 'accessories' => $this->product->getAccessories((int)(self::$cookie->id_lang)))); + 'accessories' => $this->product->getAccessories($this->context->language->id))); if (sizeof($productImages)) - self::$smarty->assign('images', $productImages); + $this->context->smarty->assign('images', $productImages); /* Attributes / Groups & colors */ $colors = array(); - $attributesGroups = $this->product->getAttributesGroups((int)(self::$cookie->id_lang)); // @todo (RM) should only get groups and not all declination ? + $attributesGroups = $this->product->getAttributesGroups($this->context->language->id); // @todo (RM) should only get groups and not all declination ? if (is_array($attributesGroups) AND $attributesGroups) { $groups = array(); - $combinationImages = $this->product->getCombinationImages((int)(self::$cookie->id_lang)); + $combinationImages = $this->product->getCombinationImages($this->context->language->id); foreach ($attributesGroups AS $k => $row) { /* Color management */ @@ -340,7 +338,7 @@ class ProductControllerCore extends FrontController $combinations[$id_product_attribute]['list'] = $attributeList; } - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'groups' => $groups, 'combinaisons' => $combinations, /* Kept for compatibility purpose only */ 'combinations' => $combinations, @@ -348,31 +346,31 @@ class ProductControllerCore extends FrontController 'combinationImages' => $combinationImages)); } - self::$smarty->assign(array( - 'no_tax' => Tax::excludeTaxeOption() OR !Tax::getProductTaxRate((int)$this->product->id, $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), - 'customizationFields' => $this->product->getCustomizationFields((int)(self::$cookie->id_lang)) + $this->context->smarty->assign(array( + 'no_tax' => Tax::excludeTaxeOption() OR !Tax::getProductTaxRate((int)$this->product->id, $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), + 'customizationFields' => $this->product->getCustomizationFields($this->context->language->id) )); // Pack management - self::$smarty->assign('packItems', $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, (int)(self::$cookie->id_lang), true) : array()); - self::$smarty->assign('packs', Pack::getPacksTable($this->product->id, (int)(self::$cookie->id_lang), true, 1)); + $this->context->smarty->assign('packItems', $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array()); + $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1)); } } - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int)(Configuration::get('PS_ORDER_OUT_OF_STOCK')), 'errors' => $this->errors, - 'categories' => Category::getHomeCategories((int)(self::$cookie->id_lang)), + 'categories' => Category::getHomeCategories($this->context->language->id), 'have_image' => Product::getCover((int)(Tools::getValue('id_product'))), 'tax_enabled' => Configuration::get('PS_TAX'), 'display_qties' => (int)(Configuration::get('PS_DISPLAY_QTIES')), 'display_ht' => !Tax::excludeTaxeOption(), 'ecotax' => (!sizeof($this->errors) AND $this->product->ecotax > 0 ? Tools::convertPrice((float)($this->product->ecotax)) : 0), - 'currencySign' => $context->currency->sign, - 'currencyRate' => $context->currency->conversion_rate, - 'currencyFormat' => $context->currency->format, - 'currencyBlank' => $context->currency->blank, + 'currencySign' => $this->context->currency->sign, + 'currencyRate' => $this->context->currency->conversion_rate, + 'currencyFormat' => $this->context->currency->format, + 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM') )); } @@ -380,7 +378,7 @@ class ProductControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'product.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'product.tpl'); } public function pictureUpload(Product $product, Cart $cart) @@ -447,8 +445,8 @@ class ProductControllerCore extends FrontController if (strncmp($field, 'group_', 6) == 0) $customizationFormTarget = preg_replace('/&group_([[:digit:]]+)=([[:digit:]]+)/', '', $customizationFormTarget); if (isset($_POST['quantityBackup'])) - self::$smarty->assign('quantityBackup', (int)($_POST['quantityBackup'])); - self::$smarty->assign('customizationFormTarget', $customizationFormTarget); + $this->context->smarty->assign('quantityBackup', (int)($_POST['quantityBackup'])); + $this->context->smarty->assign('customizationFormTarget', $customizationFormTarget); } public function formatQuantityDiscounts($specificPrices, $price, $taxRate) diff --git a/controllers/SearchController.php b/controllers/SearchController.php index d8c9e530f..83ff1c3d6 100644 --- a/controllers/SearchController.php +++ b/controllers/SearchController.php @@ -49,7 +49,7 @@ class SearchControllerCore extends FrontController { $searchResults = Search::find((int)(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); foreach ($searchResults AS &$product) - $product['product_link'] = self::$link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); + $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); die(Tools::jsonEncode($searchResults)); } @@ -58,11 +58,11 @@ class SearchControllerCore extends FrontController $this->productSort(); $this->n = abs((int)(Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')))); $this->p = abs((int)(Tools::getValue('p', 1))); - $search = Search::find((int)(self::$cookie->id_lang), $query, $this->p, $this->n, $this->orderBy, $this->orderWay); + $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay); Module::hookExec('search', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'search_products' => $search['result'], 'nbProducts' => $search['total'], @@ -75,11 +75,11 @@ class SearchControllerCore extends FrontController $this->productSort(); $this->n = abs((int)(Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')))); $this->p = abs((int)(Tools::getValue('p', 1))); - $search = Search::find((int)(self::$cookie->id_lang), $query, false, $this->p, $this->n, $this->orderBy, $this->orderWay); + $search = Search::find($this->context->language->id, $query, false, $this->p, $this->n, $this->orderBy, $this->orderWay); Module::hookExec('search', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'products' => $search['result'], // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'search_products' => $search['result'], 'nbProducts' => $search['total'], @@ -88,11 +88,11 @@ class SearchControllerCore extends FrontController } elseif ($tag = urldecode(Tools::getValue('tag')) AND !is_array($tag)) { - $nbProducts = (int)(Search::searchTag((int)(self::$cookie->id_lang), $tag, true)); + $nbProducts = (int)(Search::searchTag($this->context->language->id, $tag, true)); $this->pagination($nbProducts); - $result = Search::searchTag((int)(self::$cookie->id_lang), $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay); + $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay); Module::hookExec('search', array('expr' => $tag, 'total' => sizeof($result))); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'search_tag' => $tag, 'products' => $result, // DEPRECATED (since to 1.4), not use this: conflict with block_cart module 'search_products' => $result, @@ -101,13 +101,13 @@ class SearchControllerCore extends FrontController } else { - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0)); } - self::$smarty->assign('add_prod_display', Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY')); + $this->context->smarty->assign('add_prod_display', Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY')); } public function displayHeader() @@ -115,13 +115,13 @@ class SearchControllerCore extends FrontController if (!$this->instantSearch AND !$this->ajaxSearch) parent::displayHeader(); else - self::$smarty->assign('static_token', Tools::getToken(false)); + $this->context->smarty->assign('static_token', Tools::getToken(false)); } public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'search.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'search.tpl'); } public function displayFooter() diff --git a/controllers/SitemapController.php b/controllers/SitemapController.php index 5e236db52..442419850 100644 --- a/controllers/SitemapController.php +++ b/controllers/SitemapController.php @@ -45,21 +45,21 @@ class SitemapControllerCore extends FrontController { parent::process(); - self::$smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0)); - self::$smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory(Context::getContext()->language->id, 1, 1, 1)); - self::$smarty->assign('voucherAllowed', (int)Configuration::get('PS_VOUCHERS')); + $this->context->smarty->assign('categoriesTree', Category::getRootCategory()->recurseLiteCategTree(0)); + $this->context->smarty->assign('categoriescmsTree', CMSCategory::getRecurseCategory($this->context->language->id, 1, 1, 1)); + $this->context->smarty->assign('voucherAllowed', (int)Configuration::get('PS_VOUCHERS')); $blockmanufacturer = Module::getInstanceByName('blockmanufacturer'); $blocksupplier = Module::getInstanceByName('blocksupplier'); - self::$smarty->assign('display_manufacturer_link', (((int)$blockmanufacturer->id) ? true : false)); - self::$smarty->assign('display_supplier_link', (((int)$blocksupplier->id) ? true : false)); - self::$smarty->assign('PS_DISPLAY_SUPPLIERS', Configuration::get('PS_DISPLAY_SUPPLIERS')); - self::$smarty->assign('display_store', Configuration::get('PS_STORES_DISPLAY_SITEMAP')); + $this->context->smarty->assign('display_manufacturer_link', (((int)$blockmanufacturer->id) ? true : false)); + $this->context->smarty->assign('display_supplier_link', (((int)$blocksupplier->id) ? true : false)); + $this->context->smarty->assign('PS_DISPLAY_SUPPLIERS', Configuration::get('PS_DISPLAY_SUPPLIERS')); + $this->context->smarty->assign('display_store', Configuration::get('PS_STORES_DISPLAY_SITEMAP')); } public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'sitemap.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'sitemap.tpl'); } } diff --git a/controllers/StoresController.php b/controllers/StoresController.php index adac36d33..49174f2eb 100644 --- a/controllers/StoresController.php +++ b/controllers/StoresController.php @@ -36,8 +36,6 @@ class StoresControllerCore extends FrontController public function preProcess() { - $context = Context::getContext(); - $simplifiedStoreLocator = Configuration::get('PS_STORES_SIMPLIFIED'); $distanceUnit = Configuration::get('PS_DISTANCE_UNIT'); if (!in_array($distanceUnit, array('km', 'mi'))) @@ -51,7 +49,7 @@ class StoresControllerCore extends FrontController LEFT JOIN '._DB_PREFIX_.'store s ON (ss.id_store = s.id_store) LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country) LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state) - WHERE s.active = 1 AND cl.id_lang = '.(int)$context->language->id.' AND ss.id_shop = '.(int)$this->id_current_shop); + WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id.' AND ss.id_shop = '.(int)$this->id_current_shop); foreach ($stores AS &$store) $store['has_picture'] = file_exists(_PS_STORE_IMG_DIR_.(int)($store['id_store']).'.jpg'); @@ -66,7 +64,7 @@ class StoresControllerCore extends FrontController LEFT JOIN '._DB_PREFIX_.'store s ON (ss.id_store = s.id_store) LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country) LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state) - WHERE s.active = 1 AND cl.id_lang = '.(int)$context->language->id.' AND ss.id_shop = '.(int)$this->id_current_shop); + WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id.' AND ss.id_shop = '.(int)$this->id_current_shop); } else { @@ -80,7 +78,7 @@ class StoresControllerCore extends FrontController LEFT JOIN '._DB_PREFIX_.'store s ON (ss.id_store = s.id_store) LEFT JOIN '._DB_PREFIX_.'country_lang cl ON (cl.id_country = s.id_country) LEFT JOIN '._DB_PREFIX_.'state st ON (st.id_state = s.id_state) - WHERE s.active = 1 AND cl.id_lang = '.(int)$context->language->id.' AND ss.id_shop = '.(int)$this->id_current_shop.' + WHERE s.active = 1 AND cl.id_lang = '.(int)$this->context->language->id.' AND ss.id_shop = '.(int)$this->id_current_shop.' HAVING distance < '.(int)($distance).' ORDER BY distance ASC LIMIT 0,20'); @@ -120,10 +118,10 @@ class StoresControllerCore extends FrontController $hours_datas['hours'] = $hours[(int)($i) - 1]; $days_datas[] = $hours_datas; } - self::$smarty->assign('days_datas', $days_datas); - self::$smarty->assign('id_country', $store['id_country']); + $this->context->smarty->assign('days_datas', $days_datas); + $this->context->smarty->assign('id_country', $store['id_country']); - $other .= self::$smarty->fetch(_PS_THEME_DIR_.'store_infos.tpl'); + $other .= $this->context->smarty->fetch(_PS_THEME_DIR_.'store_infos.tpl'); } $newnode->setAttribute('addressNoHtml', strip_tags(str_replace('
', ' ', $address))); @@ -143,10 +141,10 @@ class StoresControllerCore extends FrontController die($dom->saveXML()); } else - self::$smarty->assign('hasStoreIcon', file_exists(dirname(__FILE__).'/../img/logo_stores.gif')); + $this->context->smarty->assign('hasStoreIcon', file_exists(dirname(__FILE__).'/../img/logo_stores.gif')); } - self::$smarty->assign(array('distance_unit' => $distanceUnit, 'simplifiedStoresDiplay' => $simplifiedStoreLocator, 'stores' => $stores, 'mediumSize' => Image::getSize('medium'))); + $this->context->smarty->assign(array('distance_unit' => $distanceUnit, 'simplifiedStoresDiplay' => $simplifiedStoreLocator, 'stores' => $stores, 'mediumSize' => Image::getSize('medium'))); } private function _processStoreAddress($store) @@ -191,10 +189,10 @@ class StoresControllerCore extends FrontController { parent::process(); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'defaultLat' => (float)Configuration::get('PS_STORES_CENTER_LAT'), 'defaultLong' => (float)Configuration::get('PS_STORES_CENTER_LONG'), - 'searchUrl' => Context::getContext()->link->getPageLink('stores') + 'searchUrl' => $this->context->link->getPageLink('stores') )); } @@ -210,6 +208,6 @@ class StoresControllerCore extends FrontController public function displayContent() { parent::displayContent(); - self::$smarty->display(_PS_THEME_DIR_.'stores.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'stores.tpl'); } } diff --git a/controllers/SupplierController.php b/controllers/SupplierController.php index 89a4deb22..4468c0f72 100644 --- a/controllers/SupplierController.php +++ b/controllers/SupplierController.php @@ -39,14 +39,14 @@ class SupplierControllerCore extends FrontController { if ($id_supplier = Tools::getValue('id_supplier')) { - $this->supplier = new Supplier((int)$id_supplier, self::$cookie->id_lang); + $this->supplier = new Supplier((int)$id_supplier, $this->context->cookie->id_lang); if (Validate::isLoadedObject($this->supplier) AND $this->supplier->active AND $this->supplier->isAssociatedToGroupShop()) { $nbProducts = $this->supplier->getProducts($id_supplier, NULL, NULL, NULL, $this->orderBy, $this->orderWay, true); $this->pagination((int)$nbProducts); - self::$smarty->assign(array( + $this->context->smarty->assign(array( 'nb_products' => $nbProducts, - 'products' => $this->supplier->getProducts($id_supplier, (int)self::$cookie->id_lang, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay), + 'products' => $this->supplier->getProducts($id_supplier, (int)$this->context->cookie->id_lang, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay), 'path' => ($this->supplier->active ? Tools::safeOutput($this->supplier->name) : ''), 'supplier' => $this->supplier)); } @@ -61,16 +61,16 @@ class SupplierControllerCore extends FrontController { if (Configuration::get('PS_DISPLAY_SUPPLIERS')) { - $data = call_user_func(array('Supplier', 'getSuppliers'), true, (int)(self::$cookie->id_lang), true); + $data = call_user_func(array('Supplier', 'getSuppliers'), true, $this->context->language->id, true); $nbProducts = count($data); $this->pagination($nbProducts); - $data = call_user_func(array('Supplier', 'getSuppliers'), true, (int)(self::$cookie->id_lang), true, $this->p, $this->n); + $data = call_user_func(array('Supplier', 'getSuppliers'), true, $this->context->language->id, true, $this->p, $this->n); $imgDir = _PS_SUPP_IMG_DIR_; foreach ($data AS &$item) $item['image'] = (!file_exists($imgDir.'/'.$item['id_supplier'].'-medium.jpg')) ? - Language::getIsoById((int)(self::$cookie->id_lang)).'-default' : $item['id_supplier']; - self::$smarty->assign(array( + $this->context->language->iso_code.'-default' : $item['id_supplier']; + $this->context->smarty->assign(array( 'pages_nb' => ceil($nbProducts / (int)($this->n)), 'nbSuppliers' => $nbProducts, 'mediumSize' => Image::getSize('medium'), @@ -79,7 +79,7 @@ class SupplierControllerCore extends FrontController )); } else - self::$smarty->assign('nbSuppliers', 0); + $this->context->smarty->assign('nbSuppliers', 0); } } @@ -93,9 +93,9 @@ class SupplierControllerCore extends FrontController { parent::displayContent(); if ($this->supplier) - self::$smarty->display(_PS_THEME_DIR_.'supplier.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'supplier.tpl'); else - self::$smarty->display(_PS_THEME_DIR_.'supplier-list.tpl'); + $this->context->smarty->display(_PS_THEME_DIR_.'supplier-list.tpl'); } } diff --git a/controllers/pdfOrderReturnController.php b/controllers/pdfOrderReturnController.php index 9f0df13d2..5bfdbc6cf 100644 --- a/controllers/pdfOrderReturnController.php +++ b/controllers/pdfOrderReturnController.php @@ -31,7 +31,7 @@ class PdfOrderReturnControllerCore extends FrontController { parent::process(); - $cookie = self::$cookie; + $cookie = $this->context->cookie; if (!$cookie->isLogged()) Tools::redirect('index.php?controller=authentication&back=order-follow'); diff --git a/controllers/pdfOrderSlipController.php b/controllers/pdfOrderSlipController.php index 7dcdc781d..7b22590c8 100644 --- a/controllers/pdfOrderSlipController.php +++ b/controllers/pdfOrderSlipController.php @@ -31,7 +31,7 @@ class PdfOrderSlipControllerCore extends FrontController { parent::process(); - $cookie = self::$cookie; + $cookie = $this->context->cookie; if (!$cookie->isLogged()) Tools::redirect('index.php?controller=authentication&back=order-follow');