drasl Posted June 15, 2016 Share Posted June 15, 2016 Hi guys, i'm coding a module that control inconsistent prices when a client add a product in the cart. The problem is that my module affects on backoffice too, and I don't want this. There is someway tell my module only affect on frontoffice? Here is my code: public function hookactionCartSave($req) { //Reglas de avisos/prohibiciones en el evento de "añadir a carrito" global $cookie; $id_lang=$cookie->id_lang; $productError = false; $products = $this->context->cart->getProducts(); foreach ($products as $product) { // Si el precio de producto es igual o menor a 0, al añadir el producto al carrito, el mismo se borra. if ($product['price'] <= 0){ $this->context->cart->deleteProduct($product['id_product']); $productError = true; } } if ($productError){ //Si detecta error, envía aviso al usuario y manda correo electrónico reportando el problema. Mail::Send($id_lang, 'price_incoherence', $this->l('Incoherencia con Precio'), array('{firstname}' => $cookie->firstname, '{customer_id}' => $cookie->id_customer, '{lastname}' => $cookie->lastname, '{product_id}' => $product['id_product'], '{product_price}' => $product['price']), '[email protected]', NULL, NULL, NULL, NULL, NULL, 'modules/xxxx/mails/'); $this->context->controller->errors[] = $this->l('ERROR....'); } return true; } } Link to comment Share on other sites More sharing options...
roja45 Posted June 15, 2016 Share Posted June 15, 2016 you mean that this function is also called from when you're logged in to the Back Office? You could check whether the employee is assigned in the context object, and if it is just exit out the of the hook, pretty sure it's only assigned when in the BO. You can't prevent the hook from being called. Link to comment Share on other sites More sharing options...
drasl Posted June 15, 2016 Author Share Posted June 15, 2016 (edited) you mean that this function is also called from when you're logged in to the Back Office? You could check whether the employee is assigned in the context object, and if it is just exit out the of the hook, pretty sure it's only assigned when in the BO. You can't prevent the hook from being called. Thanks, done. I'm controlling it with this: $current_context = Context::getContext(); if ($current_context->controller->controller_type == 'front'){ //code } Edited June 15, 2016 by lsard (see edit history) 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