FreeShipping.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
  4. */
  5. namespace Temando\Shipping\Model\Shipping\RateResult;
  6. use Magento\Quote\Model\Quote\Address\RateRequest;
  7. use Magento\Shipping\Model\Rate\Result;
  8. /**
  9. * Temando Rate Result Free Shipping Handler.
  10. *
  11. * @package Temando\Shipping\Model
  12. * @author Christoph Aßmann <christoph.assmann@netresearch.de>
  13. * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  14. * @link https://www.temando.com/
  15. */
  16. class FreeShipping
  17. {
  18. /**
  19. * Apply free shipping as configured via cart price rules.
  20. *
  21. * For now we only consider the `free_shipping` flag on the rate request itself.
  22. * Under certain conditions, the quote items also have a `free_shipping`
  23. * property (boolean flag or number). As the free shipping information on
  24. * item level is not handled consistently in core carriers and there is no
  25. * documentation available how it should be handled by 3rd party carriers,
  26. * we cannot reliably process it.
  27. *
  28. * @param RateRequest $rateRequest
  29. * @param Result $rateResult
  30. */
  31. public function apply(RateRequest $rateRequest, Result $rateResult)
  32. {
  33. if (!$rateRequest->getFreeShipping()) {
  34. return;
  35. }
  36. foreach ($rateResult->getAllRates() as $method) {
  37. $method->setPrice(0);
  38. }
  39. }
  40. }