Jump to content

[Résolu] Undefined class constant 'FREE_SHIPPING' in /home/www/classes/CartRule.php on line 381


Recommended Posts

Bonjour,
 
J'ai crée pour un client défini une règle panier ayant pour action d'offrir les frais de port automatiquement s'il mettait un article particulier au panier et je constate, une fois que le client a passé sa commande avec ces frais de port offerts sur sa commande, que lorsque je veux afficher la page "client" de ce client, j'obtiens désormais une page blanche avec le message :
Fatal error: Undefined class constant 'FREE_SHIPPING' in [/size]/home/www/classes/CartRule.php on line [/size]381
 

        // Retrocompatibility with 1.4 discounts
        foreach ($result as &$cart_rule) {
            $cart_rule['value'] = 0;
            $cart_rule['minimal'] = Tools::convertPriceFull($cart_rule['minimum_amount'], new Currency($cart_rule['minimum_amount_currency']), Context::getContext()->currency);
            $cart_rule['cumulable'] = !$cart_rule['cart_rule_restriction'];
            $cart_rule['id_discount_type'] = false;
            if ($cart_rule['free_shipping']) {
                $cart_rule['id_discount_type'] = Discount::FREE_SHIPPING; 
            } elseif ($cart_rule['reduction_percent'] > 0) {
                $cart_rule['id_discount_type'] = Discount::PERCENT;
                $cart_rule['value'] = $cart_rule['reduction_percent'];
            } elseif ($cart_rule['reduction_amount'] > 0) {
                $cart_rule['id_discount_type'] = Discount::AMOUNT;
                $cart_rule['value'] = $cart_rule['reduction_amount'];
            }
        }
        unset($cart_rule);

        return $result;
    } 

Je peux voir sa commande mais je ne peux pas afficher sa page client !
Un problème avec les règles panier "free shipping"?

 

Edit : je vois que le code susvisé concerne une soi disant "rétrocompatibilité 1.4" alors qu'il s'agit bien d'une règle panier créé sous PS 1.6.1.1
 
Help svp...

Edited by Hobbes (see edit history)
Link to comment
Share on other sites

Problème résolu en modifiant le fichier Classes/CartRule.php :

        // Retrocompatibility with 1.4 discounts
        foreach ($result as &$cart_rule) {
            $cart_rule['value'] = 0;
            $cart_rule['minimal'] = Tools::convertPriceFull($cart_rule['minimum_amount'], new Currency($cart_rule['minimum_amount_currency']), Context::getContext()->currency);
            $cart_rule['cumulable'] = !$cart_rule['cart_rule_restriction'];
            $cart_rule['id_discount_type'] = false;
            if ($cart_rule['free_shipping']) {
                $cart_rule['id_discount_type'] = Discount::FREE_SHIPPING;
            } elseif ($cart_rule['reduction_percent'] > 0) {
                $cart_rule['id_discount_type'] = Discount::PERCENT;
                $cart_rule['value'] = $cart_rule['reduction_percent'];
            } elseif ($cart_rule['reduction_amount'] > 0) {
                $cart_rule['id_discount_type'] = Discount::AMOUNT;
                $cart_rule['value'] = $cart_rule['reduction_amount'];
            }
        }
        unset($cart_rule);
 
        return $result;
    }

par :

        // Retrocompatibility with 1.4 discounts
        foreach ($result as &$cart_rule) {
            $cart_rule['value'] = 0;
            $cart_rule['minimal'] = Tools::convertPriceFull($cart_rule['minimum_amount'], new Currency($cart_rule['minimum_amount_currency']), Context::getContext()->currency);
            $cart_rule['cumulable'] = !$cart_rule['cart_rule_restriction'];
            $cart_rule['id_discount_type'] = false;
            if ($cart_rule['free_shipping']) {
                $cart_rule['id_discount_type'] = 3; // Discount::FREE_SHIPPING;
            } elseif ($cart_rule['reduction_percent'] > 0) {
                $cart_rule['id_discount_type'] = 1; // Discount::PERCENT;
                $cart_rule['value'] = $cart_rule['reduction_percent'];
            } elseif ($cart_rule['reduction_amount'] > 0) {
                $cart_rule['id_discount_type'] = 2; // Discount::AMOUNT;
                $cart_rule['value'] = $cart_rule['reduction_amount'];
            }
        }
        unset($cart_rule);
 
        return $result;
    }

Le problème a été résolu par Eolia, merci à lui :

 

En regardant le code, je me rend compte que Prestashop a fait nawak sur ce coup et suivant les versions php...

L'autoload de la classe en statique n'appelle pas les constantes, d'ou votre erreur.

 

Soit vous remplacez ces 3 valeurs dans cartrules.php par leurs valeurs respectives de discount.php

soit vous les ajoutez au debut de ce fichier

const PERCENT = 1;
const AMOUNT = 2;
const FREE_SHIPPING = 3;

et vous enlevez les 3 Discount::

 

 

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...