public function isCouponRemovingPostage(Order $order)
    {
        $coupons = $this->facade->getCurrentCoupons();

        if (\count($coupons) == 0) {
            return false;
        }

        $couponsKept = $this->sortCoupons($coupons);

        /** @var CouponInterface $coupon */
        foreach ($couponsKept as $coupon) {
            if ($coupon->isRemovingPostage()) {
                // Check if delivery country is on the list of countries for which delivery is free
                // If the list is empty, the shipping is free for all countries.
                $couponCountries = $coupon->getFreeShippingForCountries();

                if (! $couponCountries->isEmpty()) {
                    if (null === $deliveryAddress = AddressQuery::create()->findPk($order->getChoosenDeliveryAddress())) {
                        continue;
                    }

                    $countryValid = false;

                    $deliveryCountryId = $deliveryAddress->getCountryId();

                    /** @var CouponCountry $couponCountry */
                    foreach ($couponCountries as $couponCountry) {
                        if ($deliveryCountryId == $couponCountry->getCountryId()) {
                            $countryValid = true;
                            break;
                        }
                    }

                    if (! $countryValid) {
                        continue;
                    }
                }

                // Check if shipping method is on the list of methods for which delivery is free
                // If the list is empty, the shipping is free for all methods.
                $couponModules = $coupon->getFreeShippingForModules();

                if (! $couponModules->isEmpty()) {
                    $moduleValid = false;

                    $shippingModuleId = $order->getDeliveryModuleId();

                    /** @var CouponModule $couponModule */
                    foreach ($couponModules as $couponModule) {
                        if ($shippingModuleId == $couponModule->getModuleId()) {
                            $moduleValid = true;
                            break;
                        }
                    }

                    if (! $moduleValid) {
                        continue;
                    }
                }

                // All conditions are met, the shipping is free !
                return true;
            }
        }

        return false;
    }
public function isCouponRemovingPostage(Order $order)
    {
        $coupons = $this->facade->getCurrentCoupons();

        if (\count($coupons) == 0) {
            return false;
        }

        $couponsKept = $this->sortCoupons($coupons);

        /** @var CouponInterface $coupon */
        foreach ($couponsKept as $coupon) {
            if ($coupon->isRemovingPostage()) {
                // Check if delivery country is on the list of countries for which delivery is free
                // If the list is empty, the shipping is free for all countries.
                $couponCountries = $coupon->getFreeShippingForCountries();

                if (! $couponCountries->isEmpty()) {
                    if (null === $deliveryAddress = AddressQuery::create()->findPk($order->getChoosenDeliveryAddress())) {
                        continue;
                    }

                    $countryValid = false;

                    $deliveryCountryId = $deliveryAddress->getCountryId();

                    /** @var CouponCountry $couponCountry */
                    foreach ($couponCountries as $couponCountry) {
                        if ($deliveryCountryId == $couponCountry->getCountryId()) {
                            $countryValid = true;
                            break;
                        }
                    }

                    if (! $countryValid) {
                        continue;
                    }
                }

                // Check if shipping method is on the list of methods for which delivery is free
                // If the list is empty, the shipping is free for all methods.
                $couponModules = $coupon->getFreeShippingForModules();

                if (! $couponModules->isEmpty()) {
                    $moduleValid = false;

                    $shippingModuleId = $order->getDeliveryModuleId();

                    /** @var CouponModule $couponModule */
                    foreach ($couponModules as $couponModule) {
                        if ($shippingModuleId == $couponModule->getModuleId()) {
                            $moduleValid = true;
                            break;
                        }
                    }

                    if (! $moduleValid) {
                        continue;
                    }
                }

                // All conditions are met, the shipping is free !
                return true;
            }
        }

        return false;
    }
public function isCouponRemovingPostage ( Order $ order ) { $ coupons = $ this -> facade -> getCurrentCoupons ( ) ; if ( \ count ( $ coupons ) == 0 ) { return false ; } $ couponsKept = $ this -> sortCoupons ( $ coupons ) ; /** @var CouponInterface $coupon */ foreach ( $ couponsKept as $ coupon ) { if ( $ coupon -> isRemovingPostage ( ) ) { // Check if delivery country is on the list of countries for which delivery is free // If the list is empty, the shipping is free for all countries. $ couponCountries = $ coupon -> getFreeShippingForCountries ( ) ; if ( ! $ couponCountries -> isEmpty ( ) ) { if ( null === $ deliveryAddress = AddressQuery :: create ( ) -> findPk ( $ order -> getChoosenDeliveryAddress ( ) ) ) { continue ; } $ countryValid = false ; $ deliveryCountryId = $ deliveryAddress -> getCountryId ( ) ; /** @var CouponCountry $couponCountry */ foreach ( $ couponCountries as $ couponCountry ) { if ( $ deliveryCountryId == $ couponCountry -> getCountryId ( ) ) { $ countryValid = true ; break ; } } if ( ! $ countryValid ) { continue ; } } // Check if shipping method is on the list of methods for which delivery is free // If the list is empty, the shipping is free for all methods. $ couponModules = $ coupon -> getFreeShippingForModules ( ) ; if ( ! $ couponModules -> isEmpty ( ) ) { $ moduleValid = false ; $ shippingModuleId = $ order -> getDeliveryModuleId ( ) ; /** @var CouponModule $couponModule */ foreach ( $ couponModules as $ couponModule ) { if ( $ shippingModuleId == $ couponModule -> getModuleId ( ) ) { $ moduleValid = true ; break ; } } if ( ! $ moduleValid ) { continue ; } } // All conditions are met, the shipping is free ! return true ; } } return false ; }
Check if there is a Coupon removing Postage

@param Order $order the order for which we have to check if postage is free

@return bool
Check if there is a Coupon removing Postage