Commit 61bab73c by dhn

撤回购物车优化

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