Search code examples
prestashopprestashop-1.7

Prestashop cart rule with free shipping not works


I have a site in prestashop (version 1.7.6.9), I created a cart rule that applies a 30% discount on the whole cart and also free shipping:

enter image description here

but when I enter the code it only applies percentage discount and not free shipping:

enter image description here

I've tried removing the percentage discount, leaving only the free shipping and in this case it takes away the shipping cost, but I need both discounts, how can I solve it?


Solution

  • I solved it by editing the file /src/Adapter/Presenter/Cart/CartPresenter.php and adding this function:

    private function getShippingDisplayValue($cart, $shippingCost)
        {
            $shippingDisplayValue = '';
            // if one of the applied cart rules have free shipping, then the shipping display value is 'Free'
            foreach ($cart->getCartRules() as $rule) {
                if ($rule['free_shipping'] && !$rule['carrier_restriction']) {
                    return $this->translator->trans('Free', [], 'Shop.Theme.Checkout');
                }
            }
            if ($shippingCost != 0) {
                $shippingDisplayValue = $this->priceFormatter->format($shippingCost);
            } else {
                $defaultCountry = null;
                if (isset(Context::getContext()->cookie->id_country)) {
                    $defaultCountry = new Country((int) Context::getContext()->cookie->id_country);
                }
                $deliveryOptionList = $cart->getDeliveryOptionList($defaultCountry);
                if (count($deliveryOptionList) > 0) {
                    foreach ($deliveryOptionList as $option) {
                        foreach ($option as $currentCarrier) {
                            if (isset($currentCarrier['is_free']) && $currentCarrier['is_free'] > 0) {
                                $shippingDisplayValue = $this->translator->trans('Free', [], 'Shop.Theme.Checkout');
                                break 2;
                            }
                        }
                    }
                }
            }
            return $shippingDisplayValue;
        }