LittleNem Posted March 2, 2020 Share Posted March 2, 2020 (edited) Bonjour tout le monde , Je viens à vous pour un petit soucis que je rencontre, mais pas des moindre et avant de me lancer sur un override, je préfère venir voir des experts: J'ai créé une règle catalogue sur une certaine catégorie de produit et pour un certain groupe de client. La réduction ne s'affiche que si le client a pour groupe par défaut le groupe concerné. Sauf que je ne veux pas le mettre par défaut mais il fait bien parti de ce groupe. Est ce que j'ai loupé quelque chose ? Et si je dois override, dans quelle fonction je peux trouver ça ? Je suis pas encore à l'aise dans la recherche de fonction sur PS. Merci beaaaucoup d'avance ! Edited March 3, 2020 by LittleNem Problème résolu (see edit history) Link to comment Share on other sites More sharing options...
doekia Posted March 2, 2020 Share Posted March 2, 2020 Il doit avoir ce groupe comme groupe par défaut, sinon PrestaShop ne sais pas lui afficher sa remise, même si elle existe 1 Link to comment Share on other sites More sharing options...
LittleNem Posted March 3, 2020 Author Share Posted March 3, 2020 Merci pour ta réponse @doekia, du coup j'ai pu adapter en overridant sereinement ! Link to comment Share on other sites More sharing options...
znabdjo Posted May 14, 2020 Share Posted May 14, 2020 Bonjour, @LittleNem du coup vous avez résolu le problème comment ? J'ai le même soucis et j'aimerais comme vous que les règles ne s'appliquent pas uniquement au groupe par défaut Link to comment Share on other sites More sharing options...
LittleNem Posted May 14, 2020 Author Share Posted May 14, 2020 (edited) Bonjour ! J'ai override Group.php et Product.php, j'ai peut-être fait d'autres modifications qui suivent celle-ci, Je ne suis pas encore une pro de prestashop, c'est peut-être pas optimal... Au moins, c'est le coeur d'une solution. J'ai simplement rendu possible le passage en paramètre d'un tableau d'id pour récupérer toutes les remises possibles. public static function getReductionByIdGroup($id_group) { $real_id_group = $id_group; if(is_array($id_group)){ $id_group = implode(',',$id_group); } if (!isset(self::$cache_reduction['group'][$id_group])) { if(!is_array($real_id_group)){ self::$cache_reduction['group'][$id_group] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `reduction` FROM `' . _DB_PREFIX_ . 'group` WHERE `id_group` = ' . (int) $id_group); }else{ self::$cache_reduction['group'][$id_group] = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' SELECT `reduction` FROM `' . _DB_PREFIX_ . 'group` WHERE `id_group` IN ('.$id_group.')' ); } } return self::$cache_reduction['group'][$id_group]; } et dans Product.php j'ai ajouté ces 2 lignes dans la fonction getPriceStatic pour récupérer tous id des groupes auxquels appartient l'utilisateur global $cookie; $id_group=Customer::getGroupsStatic($cookie->id_customer); Product.php public static function getPriceStatic( $id_product, $usetax = true, $id_product_attribute = null, $decimals = 6, $divisor = null, $only_reduc = false, $usereduc = true, $quantity = 1, $force_associated_tax = false, $id_customer = null, $id_cart = null, $id_address = null, &$specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, Context $context = null, $use_customer_price = true, $id_customization = null ) { if (!$context) { $context = Context::getContext(); } $cur_cart = $context->cart; if ($divisor !== null) { Tools::displayParameterAsDeprecated('divisor'); } if (!Validate::isBool($usetax) || !Validate::isUnsignedId($id_product)) { die(Tools::displayError()); } // Initializations $id_group = null; // Code prestashop original replaced if ($id_customer) { $id_group = Customer::getDefaultGroupId((int) $id_customer); } if (!$id_group) { $id_group = (int) Group::getCurrent()->id; } global $cookie; $id_group=Customer::getGroupsStatic($cookie->id_customer); // If there is cart in context or if the specified id_cart is different from the context cart id if (!is_object($cur_cart) || (Validate::isUnsignedInt($id_cart) && $id_cart && $cur_cart->id != $id_cart)) { /* * When a user (e.g., guest, customer, Google...) is on PrestaShop, he has already its cart as the global (see /init.php) * When a non-user calls directly this method (e.g., payment module...) is on PrestaShop, he does not have already it BUT knows the cart ID * When called from the back office, cart ID can be inexistant */ if (!$id_cart && !isset($context->employee)) { die(Tools::displayError()); } $cur_cart = new Cart($id_cart); // Store cart in context to avoid multiple instantiations in BO if (!Validate::isLoadedObject($context->cart)) { $context->cart = $cur_cart; } } $cart_quantity = 0; if ((int) $id_cart) { $cache_id = 'Product::getPriceStatic_' . (int) $id_product . '-' . (int) $id_cart; if (!Cache::isStored($cache_id) || ($cart_quantity = Cache::retrieve($cache_id) != (int) $quantity)) { $sql = 'SELECT SUM(`quantity`) FROM `' . _DB_PREFIX_ . 'cart_product` WHERE `id_product` = ' . (int) $id_product . ' AND `id_cart` = ' . (int) $id_cart; $cart_quantity = (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql); Cache::store($cache_id, $cart_quantity); } else { $cart_quantity = Cache::retrieve($cache_id); } } $id_currency = Validate::isLoadedObject($context->currency) ? (int) $context->currency->id : (int) Configuration::get('PS_CURRENCY_DEFAULT'); if (!$id_address && Validate::isLoadedObject($cur_cart)) { $id_address = $cur_cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; } // retrieve address informations $address = Address::initialize($id_address, true); $id_country = (int) $address->id_country; $id_state = (int) $address->id_state; $zipcode = $address->postcode; if (Tax::excludeTaxeOption()) { $usetax = false; } if ($usetax != false && !empty($address->vat_number) && $address->id_country != Configuration::get('VATNUMBER_COUNTRY') && Configuration::get('VATNUMBER_MANAGEMENT')) { $usetax = false; } if (null === $id_customer && Validate::isLoadedObject($context->customer)) { $id_customer = $context->customer->id; } $return = Product::priceCalculation( $context->shop->id, $id_product, $id_product_attribute, $id_country, $id_state, $zipcode, $id_currency, $id_group, $quantity, $usetax, $decimals, $only_reduc, $usereduc, $with_ecotax, $specific_price_output, $use_group_reduction, $id_customer, $use_customer_price, $id_cart, $cart_quantity, $id_customization ); return $return; } J'espère que ça aidera suffisamment Edited May 14, 2020 by LittleNem (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