Commit 61bab73c by dhn

撤回购物车优化

parent e3707988
...@@ -7,23 +7,35 @@ ...@@ -7,23 +7,35 @@
?> ?>
<?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 */ ?>
<div id="block-shipping" class="block shipping"> <div id="block-shipping"
<div id="block-summary" style="display: none;"> class="block shipping"
<form method="post" id="shipping-zip-form"> data-mage-init='{"collapsible":{"openedState": "active", "saveState": true}}'
<fieldset class="fieldset estimate"> >
<div class="field" name="shippingAddress.country_id"> <div class="title" data-role="title">
<label class="label" for="shipping_country_id"> <strong id="block-shipping-heading" role="heading" aria-level="2">
<span><?= __('Country')?></span> <?= $block->getQuote()->isVirtual()
</label> ? $block->escapeHtml(__('Estimate Tax'))
<div class="control"> : $block->escapeHtml(__('Estimate Shipping and Tax'))
<?= $block->getCountryHtmlSelect(null, 'country_id', 'shipping_country_id')?> ?>
</div> </strong>
</div> </div>
</fieldset> <div id="block-summary"
</form> data-bind="scope:'block-summary'"
<?php $serializedCheckoutConfig = /* @noEscape */ $block->getSerializedCheckoutConfig(); class="content"
data-role="content"
aria-labelledby="block-shipping-heading"
>
<!-- ko template: getTemplate() --><!-- /ko -->
<script type="text/x-magento-init">
{
"#block-summary": {
"Magento_Ui/js/core/app": <?= /* @noEscape */ $block->getJsLayout() ?>
}
}
</script>
<?php $serializedCheckoutConfig = /* @noEscape */ $block->getSerializedCheckoutConfig();
$scriptString = <<<script $scriptString = <<<script
window.checkoutConfig = {$serializedCheckoutConfig}; window.checkoutConfig = {$serializedCheckoutConfig};
window.customerData = window.checkoutConfig.customerData; window.customerData = window.checkoutConfig.customerData;
...@@ -38,7 +50,7 @@ $scriptString = <<<script ...@@ -38,7 +50,7 @@ $scriptString = <<<script
return url.setBaseUrl('{$block->escapeJs($block->escapeUrl($block->getBaseUrl()))}'); return url.setBaseUrl('{$block->escapeJs($block->escapeUrl($block->getBaseUrl()))}');
}) })
script; script;
?> ?>
<?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?> <?= /* @noEscape */ $secureRenderer->renderTag('script', [], $scriptString, false) ?>
</div> </div>
</div> </div>
...@@ -29,7 +29,6 @@ define([ ...@@ -29,7 +29,6 @@ define([
billingAddress = ko.observable(null), billingAddress = ko.observable(null),
shippingAddress = ko.observable(null), shippingAddress = ko.observable(null),
shippingMethod = ko.observable(null), shippingMethod = ko.observable(null),
shippingSaveMethod = ko.observable(null),
paymentMethod = ko.observable(null), paymentMethod = ko.observable(null),
paymentMethodlist = ko.observable(null), paymentMethodlist = ko.observable(null),
quoteData = window.checkoutConfig.quoteData, quoteData = window.checkoutConfig.quoteData,
...@@ -44,7 +43,6 @@ define([ ...@@ -44,7 +43,6 @@ define([
totals: totals, totals: totals,
shippingAddress: shippingAddress, shippingAddress: shippingAddress,
shippingMethod: shippingMethod, shippingMethod: shippingMethod,
shippingSaveMethod:shippingSaveMethod,
billingAddress: billingAddress, billingAddress: billingAddress,
paymentMethod: paymentMethod, paymentMethod: paymentMethod,
paymentMethodlist:paymentMethodlist, paymentMethodlist:paymentMethodlist,
...@@ -115,20 +113,12 @@ define([ ...@@ -115,20 +113,12 @@ define([
getPaymentMethod: function () { getPaymentMethod: function () {
return paymentMethod; return paymentMethod;
}, },
setShippingSaveMethod: function (Method) {
shippingSaveMethod(Method);
},
getShippingSaveMethod: function () {
return shippingSaveMethod;
},
setPaymentMethodList: function (MethodList) { setPaymentMethodList: function (MethodList) {
paymentMethodlist(MethodList); paymentMethodlist(MethodList);
}, },
getPaymentMethodList: function () { getPaymentMethodList: function () {
return paymentMethodlist; return paymentMethodlist;
}, },
/** /**
* @return {*} * @return {*}
*/ */
......
...@@ -57,13 +57,8 @@ define([ ...@@ -57,13 +57,8 @@ define([
{ {
quote.setShippingSaveMethod(result[1]); quote.setShippingSaveMethod(result[1]);
} }
selectShippingAddress(addressConverter.formAddressDataToQuoteAddress(address)); //selectShippingAddress(addressConverter.formAddressDataToQuoteAddress(address));
//shippingService.setShippingRates(new_sh); //shippingService.setShippingRates(new_sh);
}).fail(function (response) {
shippingService.setShippingRates([]);
errorProcessor.process(response);
}).always(function () {
shippingService.isLoading(false);
}); });
} }
}; };
......
...@@ -2,12 +2,26 @@ define([ ...@@ -2,12 +2,26 @@ define([
'uiComponent', 'uiComponent',
'uiRegistry', 'uiRegistry',
'underscore', 'underscore',
'Magento_Checkout/js/model/shipping-rate-processor/get-address' 'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/action/select-billing-address',
'Magento_Checkout/js/model/payment-service',
'Magento_Checkout/js/model/totals',
'Magento_Checkout/js/action/set-shipping-information',
'Magento_Checkout/js/model/shipping-service',
'Magento_Customer/js/model/customer',
'Magento_Checkout/js/model/update-item-service'
], function ( ], function (
Component, Component,
registry, registry,
_, _,
getAddress quote,
selectBillingAddress,
paymentService,
totalsService,
setShippingInformationAction,
shippingService,
customer,
updateItemService
) { ) {
'use strict'; 'use strict';
...@@ -16,10 +30,48 @@ define([ ...@@ -16,10 +30,48 @@ define([
/** @inheritdoc */ /** @inheritdoc */
initialize: function () { initialize: function () {
this._super(); this._super();
var address={}; var self = this;
address.countryId = window.checkoutConfig.defaultCountryId; quote.shippingMethod.subscribe(function (method) {
getAddress.getRates(address); if (method && !updateItemService.hasUpdateResult()) {
var shippingRates = shippingService.getShippingRates();
var availableRate = _.find(shippingRates(), function (rate) {
if (rate['method_code'] === null && method['method_code'] === null) {
return false;
}
return rate['carrier_code'] + '_' + rate['method_code'] === method['carrier_code'] + '_' + method['method_code'];
});
if (availableRate) {
if (self._isAddressSameAsShipping()) {
selectBillingAddress(quote.shippingAddress());
}
paymentService.isLoading(true);
totalsService.isLoading(true);
setShippingInformationAction().done(
function () {
paymentService.isLoading(false);
totalsService.isLoading(false);
}
);
}
}
}, this);
if (!customer.isLoggedIn()) {
quote.shippingAddress.subscribe(function (address) {
if (_.isUndefined(address.street) || address.street.length == 0) {
address.street = ["", ""];
}
}, this);
}
},
/**
* @returns {*}
*/
_isAddressSameAsShipping: function () {
return true;
//return registry.get('checkout.steps.billing-step.payment.payments-list.billing-address-form-shared').isAddressSameAsShipping();
} }
}); });
}); });
...@@ -29,21 +29,6 @@ define([ ...@@ -29,21 +29,6 @@ define([
if (!this.isCalculated()) { if (!this.isCalculated()) {
return ''; return '';
} }
var price;
if (!this.isCalculated()) {
return this.notCalculatedMessage;
}
price = this.totals()['shipping_amount'];
if(price == 0)
{
if(quote.shippingSaveMethod())
{
return quote.shippingSaveMethod()['method_title'];
}
}
shippingMethod = quote.shippingMethod(); shippingMethod = quote.shippingMethod();
if (!_.isArray(shippingMethod) && !_.isObject(shippingMethod)) { if (!_.isArray(shippingMethod) && !_.isObject(shippingMethod)) {
...@@ -93,10 +78,7 @@ define([ ...@@ -93,10 +78,7 @@ define([
price = this.totals()['shipping_amount']; price = this.totals()['shipping_amount'];
if(price == 0) if(price == 0)
{ {
if(quote.shippingSaveMethod()) return this.getFormattedPrice(6.99);
{
return this.getFormattedPrice(quote.shippingSaveMethod()['amount']);
}
} }
return this.getFormattedPrice(price); return this.getFormattedPrice(price);
}, },
...@@ -109,11 +91,7 @@ define([ ...@@ -109,11 +91,7 @@ define([
price = this.totals()['shipping_amount']; price = this.totals()['shipping_amount'];
if(price == 0) if(price == 0)
{ {
if(quote.shippingSaveMethod()) return '-'+this.getFormattedPrice(6.99);
{
return '-'+this.getFormattedPrice(quote.shippingSaveMethod()['amount']);
}
return 0;
} }
}, },
......
...@@ -51,7 +51,7 @@ define([ ...@@ -51,7 +51,7 @@ define([
}, },
isSaveShowed: function () { isSaveShowed: function () {
var price = this.totals()['shipping_amount']; var price = this.totals()['shipping_amount'];
if(price != 0) if(price)
{ {
return false; return false;
} }
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<referenceContainer name="content"> <referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="checkout.cart.footer" template="Magento_Checkout::footer.phtml" /> <block class="Magento\Framework\View\Element\Template" name="checkout.cart.footer" template="Magento_Checkout::footer.phtml" />
</referenceContainer> </referenceContainer>
<!--
<referenceBlock name="checkout.cart.totals"> <referenceBlock name="checkout.cart.totals">
<arguments> <arguments>
<argument name="jsLayout" xsi:type="array"> <argument name="jsLayout" xsi:type="array">
...@@ -53,6 +53,6 @@ ...@@ -53,6 +53,6 @@
</argument> </argument>
</arguments> </arguments>
</referenceBlock> </referenceBlock>
-->
</body> </body>
</page> </page>
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