vonwa Posted May 27, 2009 Share Posted May 27, 2009 Bonjour à tous !Je cherche à limiter l'utilisation des bon de réduction. Par exemple :pour une commande avec un total produit de 25euro (sans les frais de port)si l'utilisateur utilise un bon de réduction de 30euroalors j'aimerais que le total de ses produits passe à 0, mais que les frais de port reste inchangé (et que le bon, en cas de confirmation de payement, soit considéré comme utilisé)J'ai essayé de limiter l'utilisation de chaque bon à sa valeur, mais cette limite n'est pas "additionelle", (un bon de 30€ limité à 30€ d'achat mini + un bon de 20€ limité à 20€ d'achat mini = un bon de 50€ limité à 30€ d'achat mini)à priori, il faudrait rajouter un test dans le fichier order.php entre la ligne 45 et la ligne 72, du genre additionner tout les bon de réduction, les comparer à $cart->getOrderTotal() if ((Tools::isSubmit('submitDiscount') OR isset($_GET['submitDiscount'])) AND Tools::getValue('discount_name')) { $discountName = Tools::getValue('discount_name'); if (!Validate::isDiscountName($discountName)) $errors[] = Tools::displayError('voucher name not valid'); else { $discount = new Discount(intval(Discount::getIdByName($discountName))); if (is_object($discount) AND $discount->id) { if ($tmpError = $cart->checkDiscountValidity($discount, $cart->getDiscounts(), $cart->getOrderTotal(), $cart->getProducts(), true)) $errors[] = $tmpError; } else $errors[] = Tools::displayError('voucher name not valid'); if (!sizeof($errors)) { $cart->addDiscount(intval($discount->id)); Tools::redirect('order.php'); } else { $smarty->assign(array( 'errors' => $errors, 'discount_name' => Tools::safeOutput($discountName))); } } } Link to comment Share on other sites More sharing options...
vonwa Posted May 27, 2009 Author Share Posted May 27, 2009 Alors, un petit point :le mieux reste d'introduire le test directement dans la classe panier, methode checkDiscountValidity() ligne 761Je fais des test et vous tiens au courant... Link to comment Share on other sites More sharing options...
vonwa Posted May 27, 2009 Author Share Posted May 27, 2009 Ok bon bah j'ai déjà une prémière version qui ne controle que les bons de réduc en montant, (à voir pour le pourcentage)Donc, dans le fichier class/cart.php , modification de la méthode checkDiscountValidity().Voilà le kabouing non modifié : function checkDiscountValidity($discountObj, $discounts, $order_total, $products, $checkCartDiscount = false) { global $cookie; if (!$order_total) return Tools::displayError('cannot add voucher if order is free'); if (!$discountObj->active) return Tools::displayError('this voucher has already been used or is disabled'); if (!$discountObj->quantity) return Tools::displayError('this voucher has expired (usage limit attained)'); if ($checkCartDiscount AND ( $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user OR (Order::getDiscountsCustomer(intval($cookie->id_customer), $discountObj->id) + $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user) >= $discountObj->quantity_per_user ) ) return Tools::displayError('you cannot use this voucher anymore (usage limit attained)'); if (strtotime($discountObj->date_from) > time()) return Tools::displayError('this voucher is not yet valid'); if (strtotime($discountObj->date_to) < time()) return Tools::displayError('this voucher has expired'); if (sizeof($discounts) >= 1) { if (!$discountObj->cumulable) return Tools::displayError('this voucher isn\'t cumulative with other current discounts'); foreach ($discounts as $discount) if (!$discount['cumulable']) return Tools::displayError('previous voucher added isn\'t cumulative with other discounts'); } if (is_array($discounts) AND in_array($discountObj->id, $discounts)) return Tools::displayError('this voucher is already in your cart'); if ($discountObj->id_customer AND $this->id_customer != $discountObj->id_customer) { if (!$cookie->isLogged()) return Tools::displayError('you cannot use this voucher').' - '.Tools::displayError('try to log in if you own it'); return Tools::displayError('you cannot use this voucher'); } if ($discountObj->minimal > floatval($this->getOrderTotal(true, 1))) return Tools::displayError('the total amount of your order isn\'t high enough to use this voucher'); $currentDate = date('Y-m-d'); if (!$discountObj->cumulable_reduction) { foreach ($products as $product) if ((intval($product['reduction_price']) OR intval($product['reduction_percent'])) AND ($product['reduction_from'] == $product['reduction_to'] OR ($currentDate >= $product['reduction_from'] AND $currentDate <= $product['reduction_to'])) OR $product['on_sale']) return Tools::displayError('this voucher isn\'t cumulative on products with reduction or marked as on sale'); } if (!$this->hasProductInCategory($discountObj)) return Tools::displayError('this voucher cannot be used with those products'); return false; } Link to comment Share on other sites More sharing options...
vonwa Posted May 27, 2009 Author Share Posted May 27, 2009 Et voilà le kabouing modifié (si c'est l'arrache, vous aviez qu'a le faire :-p ) function checkDiscountValidity($discountObj, $discounts, $order_total, $products, $checkCartDiscount = false) { global $cookie; //permet de llimiter le total des bons de réduc au total des produits (on ne tiens pas compte des frais de livraison) //auteur vonwa //url vonwa.fr //mail hello-at-vonwa.fr if(2 == $discountObj->id_discount_type){//si il s'agit d'un bon fixe $vonwaTotalDiscount = 0; foreach ($discounts as $discount){//on additione les bon de réduc déjà présents if ($discount['id_discount_type'] == 2){ $vonwaTotalDiscount += $discount['value']; } } $vonwaTotalDiscount += $discountObj->value; //return Tools::displayError('Voucher is higher than the total of products'.$this->getOrderTotal(true,1)); if($vonwaTotalDiscount >= $this->getOrderTotal(true,1)){ return Tools::displayError('Voucher is higher than the total of products'); } } if (!$order_total) return Tools::displayError('cannot add voucher if order is free'); if (!$discountObj->active) return Tools::displayError('this voucher has already been used or is disabled'); if (!$discountObj->quantity) return Tools::displayError('this voucher has expired (usage limit attained)'); if ($checkCartDiscount AND ( $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user OR (Order::getDiscountsCustomer(intval($cookie->id_customer), $discountObj->id) + $this->getDiscountsCustomer($discountObj->id) >= $discountObj->quantity_per_user) >= $discountObj->quantity_per_user ) ) return Tools::displayError('you cannot use this voucher anymore (usage limit attained)'); if (strtotime($discountObj->date_from) > time()) return Tools::displayError('this voucher is not yet valid'); if (strtotime($discountObj->date_to) < time()) return Tools::displayError('this voucher has expired'); if (sizeof($discounts) >= 1) { if (!$discountObj->cumulable) return Tools::displayError('this voucher isn\'t cumulative with other current discounts'); foreach ($discounts as $discount) if (!$discount['cumulable']) return Tools::displayError('previous voucher added isn\'t cumulative with other discounts'); } if (is_array($discounts) AND in_array($discountObj->id, $discounts)) return Tools::displayError('this voucher is already in your cart'); if ($discountObj->id_customer AND $this->id_customer != $discountObj->id_customer) { if (!$cookie->isLogged()) return Tools::displayError('you cannot use this voucher').' - '.Tools::displayError('try to log in if you own it'); return Tools::displayError('you cannot use this voucher'); } if ($discountObj->minimal > floatval($this->getOrderTotal(true, 1))) return Tools::displayError('the total amount of your order isn\'t high enough to use this voucher'); $currentDate = date('Y-m-d'); if (!$discountObj->cumulable_reduction) { foreach ($products as $product) if ((intval($product['reduction_price']) OR intval($product['reduction_percent'])) AND ($product['reduction_from'] == $product['reduction_to'] OR ($currentDate >= $product['reduction_from'] AND $currentDate <= $product['reduction_to'])) OR $product['on_sale']) return Tools::displayError('this voucher isn\'t cumulative on products with reduction or marked as on sale'); } if (!$this->hasProductInCategory($discountObj)) return Tools::displayError('this voucher cannot be used with those products'); return false; } Link to comment Share on other sites More sharing options...
VIXUS Posted May 27, 2009 Share Posted May 27, 2009 what is this all about? Link to comment Share on other sites More sharing options...
vonwa Posted May 27, 2009 Author Share Posted May 27, 2009 Hi DJ Terror !All this stuff is about to block order process (display error message), if the total order amount (without shipping fee) is lower than the total discount amount.Be carefull, this amendment don't work if you're using discount by percentage. Link to comment Share on other sites More sharing options...
VIXUS Posted May 27, 2009 Share Posted May 27, 2009 Interesting, ill try it.tnx. 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