Commit 127897d1 by dhn

优化

parent 27d9a21c
......@@ -44,6 +44,7 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
*/
private $jsonHexTagSerializer;
protected $_quote;
/**
* @param Context $context
* @param CustomerSession $customerSession
......@@ -55,6 +56,7 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
* @param JsonHexTag|null $jsonHexTagSerializer
* @throws \RuntimeException
*/
public function __construct(
Context $context,
CustomerSession $customerSession,
......@@ -67,6 +69,7 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
) {
$this->configProvider = $configProvider;
$this->layoutProcessors = $layoutProcessors;
$this->_quote = $checkoutSession->getQuote();
parent::__construct($context, $customerSession, $checkoutSession, $data);
$this->_isScopePrivate = true;
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
......@@ -83,7 +86,10 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
{
return $this->configProvider->getConfig();
}
public function getCountryId() {
$shippingAddress = $this->_quote->getShippingAddress();
return $shippingAddress->getCountryId();
}
/**
* Retrieve serialized JS layout configuration ready to use in template
*
......
......@@ -7,7 +7,9 @@
?>
<?php /** @var $block \Magento\Checkout\Block\Cart\Shipping */ ?>
<?php /** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */ ?>
<?php
$selectedCountryId = $block->getCountryId();
?>
<div id="block-shipping" class="block shipping">
<div id="block-summary" style="display: none;">
<form method="post" id="shipping-zip-form">
......@@ -41,5 +43,10 @@
script;
?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
<script>
require(['jquery'], function($) {
$('#shipping_country_id').val('<?= $selectedCountryId?>');
});
</script>
</div>
</div>
......@@ -18,6 +18,7 @@ define([
this._super();
var address={};
address.countryId = window.checkoutConfig.defaultCountryId;
address.postcode = window.checkoutConfig.postcode;
getAddress.getRates(address);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment