结帐页面刷新问题


14

首先,我想提供一些屏幕截图以了解我的问题。

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

现在,我想在此处添加相关代码。

等/ frontend / di.xml

 <?xml version="1.0"?>
    <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
        <type name="Magento\Checkout\Model\CompositeConfigProvider">
            <arguments>
                <argument name="configProviders" xsi:type="array">
                    <item name="checkout_deliverysign_block" xsi:type="object">Kensium\DeliverySign\Model\DeliverySignConfigProvider</item>
                </argument>
            </arguments>
        </type>
    </config>

DeliverySignConfigProvider

<?php
namespace Kensium\DeliverySign\Model;

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Store\Model\ScopeInterface;

class DeliverySignConfigProvider implements ConfigProviderInterface
{
    /**
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $scopeConfiguration;

    protected $checkoutSession;

    protected $logger;

    /**
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration
     * @codeCoverageIgnore
     */
    public function __construct(
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfiguration,
        \Magento\Checkout\Model\Session $checkoutSession,
        \Psr\Log\LoggerInterface $logger

    )
    {
        $this->scopeConfiguration = $scopeConfiguration;
        $this->checkoutSession=$checkoutSession;
        $this->logger=$logger;
    }

    /**
     * {@inheritdoc}
     */
    public function getConfig()
    {
        $deliverySignConfig = [];
        $enabled = $this->scopeConfiguration->getValue('deliverysign/deliverysign/status', ScopeInterface::SCOPE_STORE);
        $minimumOrderAmount = $this->scopeConfiguration->getValue('deliverysign/deliverysign/minimum_order_amount', ScopeInterface::SCOPE_STORE);
        $quote=$this->checkoutSession->getQuote();
        $subtotal=$quote->getSubtotal();
        $this->logger->addDebug($subtotal);
        $deliverySignConfig['delivery_sign_amount'] = $this->scopeConfiguration->getValue('deliverysign/deliverysign/deliverysign_amount', ScopeInterface::SCOPE_STORE);
        $deliverySignConfig['show_hide_deliverysign_block'] = ($enabled && ($minimumOrderAmount<$subtotal) && $quote->getFee()) ? true : false;
        $deliverySignConfig['show_hide_deliverysign_shipblock'] = ($enabled && ($minimumOrderAmount<$subtotal)) ? true : false;
        return $deliverySignConfig;
    }
}

请在下面找到更多详细信息

https://github.com/sivajik34/Delivery-Signature-Magento2

我的观察是,DeliverySignConfigProvider当您单击下一步按钮时,对象未在调用,而是在重新加载页面时仅在调用它。有人可以帮我吗?


似乎您的Github源代码无法正常工作!您不声明Plugin Plugin/Checkout/Model/ShippingInformationManagement.php
Khoa TruongDinh '16

Answers:


4

我认为我们不需要重新加载总摘要。因为,当单击“ 下一步”按钮时,Magento将发出一个请求(API)V1/carts/mine/shipping-information以重新计算总计并将总计数据输出到我们的模板。

在此处输入图片说明

因此,如果我们要检查费用,则应检查响应 total_segments

当点击付款步骤旁边的时,系统会要求您设置运输信息 供应商/magento/module-checkout/view/frontend/web/js/view/shipping.js

             /**
             * Set shipping information handler
             */
            setShippingInformation: function () {
                if (this.validateShippingInformation()) {
                    setShippingInformationAction().done(
                        function () {
                            stepNavigator.next();
                        }
                    );
                }
            }

该请求将重新计算总数。

在您的情况下,在我们的html模板中,它应该具有以下isDisplayed()功能:

Kensium / DeliverySign / view / frontend / web / template / checkout / cart / totals / fee.html

<!-- ko if: isDisplayed() -->
<tr class="totals fee excl" data-bind="visible: canVisibleDeliverySignBlock">
    <th class="mark" colspan="1" scope="row" data-bind="text: title"></th>
    <td class="amount">
        <span class="price" data-bind="text: getValue()"></span>
    </td>
</tr>
<!-- /ko -->

检查isDisplayed()功能:

Kensium / DeliverySign / view / frontend / web / js / view / checkout / cart / totals / fee.js

define([
    'ko',
    'uiComponent',
    'Magento_Checkout/js/model/quote',
    'Magento_Catalog/js/price-utils',
    'Magento_Checkout/js/model/totals'

], function (ko, Component, quote, priceUtils, totals) {
    'use strict';
    var show_hide_deliverysign_blockConfig = window.checkoutConfig.show_hide_deliverysign_block;
    var delivery_sign_amount = window.checkoutConfig.delivery_sign_amount;

    return Component.extend({

        totals: quote.getTotals(),
        canVisibleDeliverySignBlock: show_hide_deliverysign_blockConfig,
        getFormattedPrice: ko.observable(priceUtils.formatPrice(delivery_sign_amount, quote.getPriceFormat())),

        isDisplayed: function () {
            return this.getValue() != 0;
        },
        getValue: function() {
            var price = 0;
            if (this.totals() && totals.getSegment('fee')) {
                price = totals.getSegment('fee').value;
            }
            return this.getFormattedPrice(price);
        }
    });
});

此功能将从fee响应中检查总计段。

在这里做个混帐。

注意:请确保您的费用计算正确。在付款步骤中,请检查回复中是否包含我们的费用。


它无法正常工作。您能否检查一次。
sivakumar

TypeError:totals.getSegment(...)为nullprice = totals.getSegment('fee')。value;
sivakumar

应该检查一下 if (this.totals() && totals.getSegment('fee'))。我忘了。
Khoa TruongDinh,2016年

0

您需要覆盖结帐“ payment-service.js”模型类。您可以通过以下方式执行此操作:

#Kensium / DeliverySign / view / frontend / requirejs-config.js
var config = {
    “地图”:{
        “ *”:{
            'Magento_Checkout / js / model / shipping-save-processor /默认':'Kensium_DeliverySign / js / model / shipping-save-processor /默认',
            'Magento_Checkout / js / model / pay-service':'Kensium_DeliverySign / js / model / pay-service'
        }
    }
};

因此创建Kensium / DeliverySign / view / frontend / web / js / model / payment-service.js,内容应为

/ **
 *版权所有©2016 Magento。版权所有。
 *有关许可证的详细信息,请参阅COPYING.txt。
 * /
限定(
    [
        “下划线”,
        'Magento_Checkout / js / model / quote',
        'Magento_Checkout / js / model / payment / method-list',
        'Magento_Checkout / js / action / select-payment-method',
        'Magento_Checkout / js / model / totals'
    ],
    函数(_,报价,methodList,selectPaymentMethod,总计){
        “使用严格”;
        var freeMethodCode ='免费';

        返回{
            isFreeAvailable:否,
            / **
             *填写付款方式清单
             * @param {Array}方法
             * /
            setPaymentMethods:函数(方法){
                var self = this,
                    freeMethod,
                    filterMethods,
                    methodIsAvailable;

                freeMethod = _.find(方法,函数(方法){
                    返回method.method === freeMethodCode;
                });
                this.isFreeAvailable = freeMethod吗?真假;

                如果(self.isFreeAvailable && freeMethod && quote.totals()。grand_total <= 0){
                    methods.splice(0,Methods.length,freeMethod);
                    selectPaymentMethod(freeMethod);
                }
                filteredMethods = _.without(方法,freeMethod);

                如果(filteredMethods.length === 1){
                    selectPaymentMethod(filteredMethods [0]);
                }否则,如果(quote.paymentMethod()){
                    methodIsAvailable = methods.some(function(item){
                        返回item.method === quote.paymentMethod()。method;
                    });
                    //未设置所选付款方式
                    如果(!methodIsAvailable){
                        selectPaymentMethod(null);
                    }
                }
                methodList(方法);
                totals.isLoading(true);
                window.checkoutConfig.show_hide_deliverysign_block = 1;
                totals.isLoading(false);
            },
            / **
             *获取可用的付款方式列表。
             * @returns {Array}
             * /
            getAvailablePaymentMethods:function(){
                var方法= [],
                    自我=这个
                _.each(methodList(),function(method){
                    如果(self.isFreeAvailable &&(
                            quote.totals()。grand_total 0 && method.method!== freeMethodCode
                        )|| !self.isFreeAvailable
                    ){
                        methods.push(method);
                    }
                });

                返回方法;
            }
        };
    }
);

如果已经存在,请删除pub / static / frontend / Magento / luma / en_US / Kensium_DeliverySign

运行以下deploy命令

php bin / magento设置:静态内容:部署


它无法正常工作。您能否检查一次。
sivakumar

0

您还应该在“交付标志”上创建一个会话名称。因此,这会将每个POST请求上的购物车更改重新加载到您的控制器。基本上,动作节点指示控制器路径,而节节点定义应更新哪些客户端内容。必须清除缓存才能应用此更改。检查Checkout/etc/frontend/sections.xml 例如一个sections.xmletc/frontend

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Customer:etc/sections.xsd">
    <action name="youraction/process/observer">
        <section name="cart"/>
    </action>
</config>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.