EstimatePost.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Controller\Cart;
  7. use Magento\Framework;
  8. use Magento\Checkout\Model\Cart as CustomerCart;
  9. class EstimatePost extends \Magento\Checkout\Controller\Cart
  10. {
  11. /**
  12. * @var \Magento\Quote\Api\CartRepositoryInterface
  13. */
  14. protected $quoteRepository;
  15. /**
  16. * @param \Magento\Framework\App\Action\Context $context
  17. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  18. * @param \Magento\Checkout\Model\Session $checkoutSession
  19. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  20. * @param \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator
  21. * @param CustomerCart $cart
  22. * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
  23. * @codeCoverageIgnore
  24. */
  25. public function __construct(
  26. Framework\App\Action\Context $context,
  27. Framework\App\Config\ScopeConfigInterface $scopeConfig,
  28. \Magento\Checkout\Model\Session $checkoutSession,
  29. \Magento\Store\Model\StoreManagerInterface $storeManager,
  30. \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
  31. CustomerCart $cart,
  32. \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
  33. ) {
  34. $this->quoteRepository = $quoteRepository;
  35. parent::__construct(
  36. $context,
  37. $scopeConfig,
  38. $checkoutSession,
  39. $storeManager,
  40. $formKeyValidator,
  41. $cart
  42. );
  43. }
  44. /**
  45. * Initialize shipping information
  46. *
  47. * @return \Magento\Framework\Controller\Result\Redirect
  48. */
  49. public function execute()
  50. {
  51. $country = (string)$this->getRequest()->getParam('country_id');
  52. $postcode = (string)$this->getRequest()->getParam('estimate_postcode');
  53. $city = (string)$this->getRequest()->getParam('estimate_city');
  54. $regionId = (string)$this->getRequest()->getParam('region_id');
  55. $region = (string)$this->getRequest()->getParam('region');
  56. $this->cart->getQuote()->getShippingAddress()
  57. ->setCountryId($country)
  58. ->setCity($city)
  59. ->setPostcode($postcode)
  60. ->setRegionId($regionId)
  61. ->setRegion($region)
  62. ->setCollectShippingRates(true);
  63. $this->quoteRepository->save($this->cart->getQuote());
  64. $this->cart->save();
  65. return $this->_goBack();
  66. }
  67. }