Commit 82e8a20e by dhn

购物车优化

parent 64dfa112
......@@ -119,4 +119,10 @@ class Shipping extends \Magento\Checkout\Block\Cart\AbstractCart
{
return $this->jsonHexTagSerializer->serialize($this->getCheckoutConfig());
}
public function getCountryHtmlSelect($defValue = null, $name = 'country_id', $id = 'country', $title = 'Country') {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Directory\Block\Data $block */
$block = $objectManager->get(\Magento\Directory\Block\Data::class);
return $block->getCountryHtmlSelect($defValue, $name, $id, $title);
}
}
......@@ -7,32 +7,20 @@
?>
<?php /** @var $block \Magento\Checkout\Block\Cart\Shipping */ ?>
<?php /** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */ ?>
<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>
<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();
$scriptString = <<<script
......
......@@ -29,6 +29,7 @@ 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,
......@@ -43,6 +44,7 @@ define([
totals: totals,
shippingAddress: shippingAddress,
shippingMethod: shippingMethod,
shippingSaveMethod:shippingSaveMethod,
billingAddress: billingAddress,
paymentMethod: paymentMethod,
paymentMethodlist:paymentMethodlist,
......@@ -113,12 +115,20 @@ define([
getPaymentMethod: function () {
return paymentMethod;
},
setShippingSaveMethod: function (Method) {
shippingSaveMethod(Method);
},
getShippingSaveMethod: function () {
return shippingSaveMethod;
},
setPaymentMethodList: function (MethodList) {
paymentMethodlist(MethodList);
},
getPaymentMethodList: function () {
return paymentMethodlist;
},
/**
* @return {*}
*/
......
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
define([
'Magento_Checkout/js/model/resource-url-manager',
'Magento_Checkout/js/model/quote',
'mage/storage',
'Magento_Checkout/js/model/shipping-service',
'Magento_Checkout/js/model/error-processor',
'Magento_Checkout/js/action/select-shipping-address',
'Magento_Checkout/js/model/address-converter',
'Magento_Checkout/js/view/cart/shipping-estimation'
], function (resourceUrlManager, quote, storage, shippingService, errorProcessor,selectShippingAddress,addressConverter) {
'use strict';
return {
/**
* Get shipping rates for specified address.
* @param {Object} address
*/
getRates: function (address) {
var cache, serviceUrl, payload;
shippingService.isLoading(true);
serviceUrl = resourceUrlManager.getUrlForEstimationShippingMethodsForNewAddress(quote);
payload = JSON.stringify({
address: {
'street': address.street,
'city': address.city,
'region_id': address.regionId,
'region': address.region,
'country_id': address.countryId,
'postcode': address.postcode,
'email': address.email,
'customer_id': address.customerId,
'firstname': address.firstname,
'lastname': address.lastname,
'middlename': address.middlename,
'prefix': address.prefix,
'suffix': address.suffix,
'vat_id': address.vatId,
'company': address.company,
'telephone': address.telephone,
'fax': address.fax,
'custom_attributes': address.customAttributes,
'save_in_address_book': address.saveInAddressBook
}
}
);
storage.post(
serviceUrl, payload, false
).done(function (result) {
var new_sh = [];
new_sh.push(result[0]);
if(result.length > 1)
{
quote.setShippingSaveMethod(result[1]);
}
selectShippingAddress(addressConverter.formAddressDataToQuoteAddress(address));
//shippingService.setShippingRates(new_sh);
}).fail(function (response) {
shippingService.setShippingRates([]);
errorProcessor.process(response);
}).always(function () {
shippingService.isLoading(false);
});
}
};
});
......@@ -2,26 +2,12 @@ define([
'uiComponent',
'uiRegistry',
'underscore',
'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'
'Magento_Checkout/js/model/shipping-rate-processor/get-address'
], function (
Component,
registry,
_,
quote,
selectBillingAddress,
paymentService,
totalsService,
setShippingInformationAction,
shippingService,
customer,
updateItemService
getAddress
) {
'use strict';
......@@ -30,48 +16,10 @@ define([
/** @inheritdoc */
initialize: function () {
this._super();
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);
}
var address={};
address.countryId = window.checkoutConfig.defaultCountryId;
getAddress.getRates(address);
},
/**
* @returns {*}
*/
_isAddressSameAsShipping: function () {
return true;
//return registry.get('checkout.steps.billing-step.payment.payments-list.billing-address-form-shared').isAddressSameAsShipping();
}
});
});
......@@ -29,6 +29,21 @@ 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)) {
......@@ -57,7 +72,7 @@ define([
/**
* @return {*}
getValue: function () {
getValue: function () {
var price;
if (!this.isCalculated()) {
......@@ -78,7 +93,10 @@ define([
price = this.totals()['shipping_amount'];
if(price == 0)
{
return this.getFormattedPrice(6.99);
if(quote.shippingSaveMethod())
{
return this.getFormattedPrice(quote.shippingSaveMethod()['amount']);
}
}
return this.getFormattedPrice(price);
},
......@@ -91,7 +109,11 @@ define([
price = this.totals()['shipping_amount'];
if(price == 0)
{
return '-'+this.getFormattedPrice(6.99);
if(quote.shippingSaveMethod())
{
return '-'+this.getFormattedPrice(quote.shippingSaveMethod()['amount']);
}
return 0;
}
},
......
......@@ -51,7 +51,7 @@ define([
},
isSaveShowed: function () {
var price = this.totals()['shipping_amount'];
if(price)
if(price != 0)
{
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