우선 내 문제를 이해하기 위해 스크린 샷을주고 싶습니다.
이제 여기에 관련 코드를 추가하고 싶습니다.
etc / 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 을 클릭 할 때 객체가 호출되지 않고 페이지를 다시로드 할 때만 호출됩니다 . 누구든지 나를 도울 수 있습니까?
답변
전체 요약을 다시로드 할 필요는 없다고 생각합니다. 다음 버튼을 클릭하면 Magento는 V1/carts/mine/shipping-information총계를 다시 계산하고 총계 데이터를 템플릿으로 출력하도록 요청 (API) 합니다.
따라서 수수료를 확인하려면 응답을 확인해야합니다 total_segments
결제 단계 옆 에있는을 클릭하면 배송 정보 공급 업체 / 마 젠토 / 모듈-체크 아웃 /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응답에서 총 세그먼트를 확인합니다 .
나는 여기에 자식을 당긴다 .
참고 : 요금이 올바르게 계산되었는지 확인하십시오. 결제 단계에서 응답에 수수료가 있는지 확인하십시오.
답변
결제 ‘payment-service.js’ 모델 클래스 를 덮어 써야합니다 . 다음과 같은 방법으로이 작업을 수행 할 수 있습니다.
# Kensium / DeliverySign / view / frontend / requirejs-config.js
var config = {
"지도": {
"*": {
'Magento_Checkout / js / model / shipping-save-processor / default': 'Kensium_DeliverySign / js / model / shipping-save-processor / default',
'Magento_Checkout / js / model / payment-service': 'Kensium_DeliverySign / js / model / payment-service'
}
}
};
그래서 만들 Kensium / DeliverySign /보기 / 프론트 엔드 / 웹 / JS / 모델 / 납부 – service.js을 하고 내용이 있어야한다
/ **
* 저작권 © 2016 마 젠토. 판권 소유.
* 라이센스 세부 사항은 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'
],
함수 (_, quote, methodList, selectPaymentMethod, totals) {
'엄격한 사용';
var freeMethodCode = '무료';
{
isFreeAvailable : false,
/ **
* 결제 수단 목록을 채 웁니다.
* @param {Array} 메소드
* /
setPaymentMethods : 함수 (방법) {
var self = this,
freeMethod,
filtersMethods,
methodIsAvailable;
freeMethod = _.find (방법, 함수 (방법) {
return method.method === freeMethodCode;
});
this.isFreeAvailable = freeMethod? 허위 사실;
if (self.isFreeAvailable && freeMethod && quote.totals (). grand_total <= 0) {
methods.splice (0, methods.length, freeMethod);
selectPaymentMethod (freeMethod);
}
filteringMethods = _.with ((방법, freeMethod);
if (filteredMethods.length === 1) {
selectPaymentMethod (filteredMethods [0]);
} else if (quote.paymentMethod ()) {
methodIsAvailable = methods.some (함수 (항목) {
return item.method === quote.paymentMethod (). method;
});
// 사용할 수없는 경우 선택한 결제 수단을 설정 해제
if (! methodIsAvailable) {
selectPaymentMethod (null);
}
}
methodList (방법);
totals.isLoading (true);
window.checkoutConfig.show_hide_deliverysign_block = 1;
totals.isLoading (false);
},
/ **
* 사용 가능한 결제 수단 목록을 확인하십시오.
* @ 반환 {배열}
* /
getAvailablePaymentMethods : 함수 () {
var methods = [],
자기 = 이것;
_.each (methodList (), 함수 (방법) {
if (self.isFreeAvailable && (
quote.totals (). grand_total 0 && method.method! == freeMethodCode
) || ! self.isFreeAvailable
) {
methods.push (method);
}
});
반환 방법;
}
};
}
);
pub / static / frontend / Magento / luma / en_US / Kensium_DeliverySign 이 이미있는 경우 삭제
다음 배포 명령 실행
PHP bin / magento 설정 : 정적 내용 : 배포
답변
Delivery Sign에 세션 이름도 만들어야합니다. 따라서 이것은 각 POST 요청에서 카트 변경 사항을 컨트롤러에 다시로드합니다. 기본적으로 작업 노드는 컨트롤러 경로를 나타내며 섹션 노드는 업데이트 할 클라이언트 쪽 콘텐츠를 정의합니다. 이 변경 사항을 적용하려면 캐시를 비워야합니다. 확인 Checkout/etc/frontend/sections.xml
예를 들어 A에 대한 sections.xml에etc/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>



