Siadou Posted March 18, 2014 Share Posted March 18, 2014 bonjour J'ai besoin d'effectuer une condition et de vérifier dans ma condition le numéro de la boutique sur laquelle le client se trouve. Or je n'arrive pas à récupérer l'id de la boutique pour le tester. le fichier que je veux modifier est Authcontroller.php et voici ce que j'ai mis protected function processSubmitLogin() { if ({$smarty.get.id_shop}=='7') { Hook::exec('actionBeforeAuthentication'); $passwd = trim(Tools::getValue('passwd')); $username = trim(Tools::getValue('username')); //$email = trim(Tools::getValue('email')); if (empty($username)) $this->errors[] = Tools::displayError('An username required.'); //elseif (!Validate::isusername($username)) //$this->errors[] = Tools::displayError('Invalid username address.'); elseif (empty($passwd)) $this->errors[] = Tools::displayError('Password is required.'); elseif (!Validate::isPasswd($passwd)) $this->errors[] = Tools::displayError('Invalid password.'); else { $customer = new Customer(); $authentication = $customer->getByUsername(trim($username), trim($passwd)); if (!$authentication || !$customer->id) $this->errors[] = Tools::displayError('Authentication failed.'); else { $this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($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; $customer->logged = 1; $this->context->cookie->is_guest = $customer->isGuest(); $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->email = $customer->email; // Add customer to the context $this->context->customer = $customer; if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0) && $id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id)) $this->context->cart = new Cart($id_cart); else { $this->context->cart->id_carrier = 0; $this->context->cart->setDeliveryOption(null); $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); } $this->context->cart->id_customer = (int)$customer->id; $this->context->cart->secure_key = $customer->secure_key; $this->context->cart->save(); $this->context->cookie->id_cart = (int)$this->context->cart->id; $this->context->cookie->write(); $this->context->cart->autosetProductAddress(); Hook::exec('actionAuthentication'); // Login information have changed, so we check if the cart rules still apply CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); if (!$this->ajax) { if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) Tools::redirect(html_entity_decode($back)); Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account')); } } } if ($this->ajax) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } else $this->context->smarty->assign('authentification_error', $this->errors); } else { Hook::exec('actionBeforeAuthentication'); $passwd = trim(Tools::getValue('passwd')); //$username = trim(Tools::getValue('username')); $email = trim(Tools::getValue('email')); if (empty($username)) $this->errors[] = Tools::displayError('An username required.'); elseif (!Validate::iseamil($email)) $this->errors[] = Tools::displayError('Invalid username address.'); elseif (empty($passwd)) $this->errors[] = Tools::displayError('Password is required.'); elseif (!Validate::isPasswd($passwd)) $this->errors[] = Tools::displayError('Invalid password.'); else { $customer = new Customer(); $authentication = $customer->getByEmail(trim($email), trim($passwd)); if (!$authentication || !$customer->id) $this->errors[] = Tools::displayError('Authentication failed.'); else { $this->context->cookie->id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: CompareProduct::getIdCompareByIdCustomer($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; $customer->logged = 1; $this->context->cookie->is_guest = $customer->isGuest(); $this->context->cookie->passwd = $customer->passwd; $this->context->cookie->email = $customer->email; // Add customer to the context $this->context->customer = $customer; if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->context->cookie->id_cart) || Cart::getNbProducts($this->context->cookie->id_cart) == 0) && $id_cart = (int)Cart::lastNoneOrderedCart($this->context->customer->id)) $this->context->cart = new Cart($id_cart); else { $this->context->cart->id_carrier = 0; $this->context->cart->setDeliveryOption(null); $this->context->cart->id_address_delivery = Address::getFirstCustomerAddressId((int)($customer->id)); $this->context->cart->id_address_invoice = Address::getFirstCustomerAddressId((int)($customer->id)); } $this->context->cart->id_customer = (int)$customer->id; $this->context->cart->secure_key = $customer->secure_key; $this->context->cart->save(); $this->context->cookie->id_cart = (int)$this->context->cart->id; $this->context->cookie->write(); $this->context->cart->autosetProductAddress(); Hook::exec('actionAuthentication'); // Login information have changed, so we check if the cart rules still apply CartRule::autoRemoveFromCart($this->context); CartRule::autoAddToCart($this->context); if (!$this->ajax) { if (($back = Tools::getValue('back')) && $back == Tools::secureReferrer($back)) Tools::redirect(html_entity_decode($back)); Tools::redirect('index.php?controller='.(($this->authRedirection !== false) ? urlencode($this->authRedirection) : 'my-account')); } } } if ($this->ajax) { $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } else $this->context->smarty->assign('authentification_error', $this->errors); } } Malheureusement, il ne récupère pas la variable. Merci pour votre aide. Cordialement Julien Link to comment Share on other sites More sharing options...
Vinum Posted March 18, 2014 Share Posted March 18, 2014 Bonsoir, Normalement pour récuperer l'id_shop dans un context, il faut faire : $this->context->shop->id; Link to comment Share on other sites More sharing options...
Siadou Posted March 18, 2014 Author Share Posted March 18, 2014 Bonsoir Vinum Merci pour ta réponse rapide, ça marche Link to comment Share on other sites More sharing options...
letonton Posted September 16, 2017 Share Posted September 16, 2017 Bonjour, Est-il possible de récupérer l'id de la boutique courante dans un header.tpl? J'ai tenté {$this->context->shop->id;} mais ça ne retourne rien. J'ai aussi essayé {if {$cart->id_shop} == 1} mais quand le panier est commun à plusieurs boutiques, l'id est "transporté" d'une boutique à l'autre. Une idée? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now