Index.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Controller\ShippingRates;
  7. use Magento\Framework\App\Action;
  8. use Magento\Framework\App\Action\Context;
  9. use Magento\Framework\App\RequestInterface;
  10. use Magento\Framework\App\ResponseInterface;
  11. class Index extends \Magento\Framework\App\Action\Action
  12. {
  13. /**
  14. * @var \Magento\Framework\Controller\ResultInterface
  15. */
  16. protected $result;
  17. /**
  18. * @var \Magento\Checkout\Model\Session
  19. */
  20. protected $checkoutSession;
  21. /**
  22. * @param Context $context
  23. * @param \Magento\Checkout\Model\Session $session
  24. * @codeCoverageIgnore
  25. */
  26. public function __construct(
  27. Context $context,
  28. \Magento\Checkout\Model\Session $session
  29. ) {
  30. $this->checkoutSession = $session;
  31. parent::__construct($context);
  32. }
  33. /**
  34. * Dispatch request
  35. *
  36. * @return \Magento\Framework\Controller\ResultInterface
  37. * @throws Action\NotFoundException
  38. */
  39. public function execute()
  40. {
  41. $quote = $this->checkoutSession->getQuote();
  42. $address = $quote->getShippingAddress();
  43. $address->collectShippingRates()->save();
  44. $rates = $address->getGroupedAllShippingRates();
  45. $result = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_JSON);
  46. $result->setData($rates);
  47. return $result;
  48. }
  49. }