Commit 127897d1 by dhn

优化

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