Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
EstimatePost.php
Go to the documentation of this file.
1 <?php
7 
10 
12 {
16  protected $quoteRepository;
17 
28  public function __construct(
29  Framework\App\Action\Context $context,
30  Framework\App\Config\ScopeConfigInterface $scopeConfig,
31  \Magento\Checkout\Model\Session $checkoutSession,
33  \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator,
36  ) {
37  $this->quoteRepository = $quoteRepository;
38  parent::__construct(
39  $context,
40  $scopeConfig,
41  $checkoutSession,
43  $formKeyValidator,
44  $cart
45  );
46  }
47 
53  public function execute()
54  {
55  $country = (string)$this->getRequest()->getParam('country_id');
56  $postcode = (string)$this->getRequest()->getParam('estimate_postcode');
57  $city = (string)$this->getRequest()->getParam('estimate_city');
58  $regionId = (string)$this->getRequest()->getParam('region_id');
59  $region = (string)$this->getRequest()->getParam('region');
60 
61  $this->cart->getQuote()->getShippingAddress()
62  ->setCountryId($country)
63  ->setCity($city)
64  ->setPostcode($postcode)
65  ->setRegionId($regionId)
66  ->setRegion($region)
67  ->setCollectShippingRates(true);
68  $this->quoteRepository->save($this->cart->getQuote());
69  $this->cart->save();
70  return $this->_goBack();
71  }
72 }
$quoteRepository
execute()
$storeManager
__construct(Framework\App\Action\Context $context, Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, CustomerCart $cart, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository)
_goBack($backUrl=null)
Definition: Cart.php:73