- 資訊首頁(yè) > 互聯(lián)網(wǎng) > 經(jīng)驗分享 >
- Magento教程:在Magento 2創(chuàng )建支付方式的步驟
外貿電子商務(wù)中,選擇合適的支付方式很重要,而Magento作為一套專(zhuān)業(yè)熱門(mén)的開(kāi)源的電子商務(wù)系統,是可以直接設置創(chuàng )建支付方式的,安全即可靠。本文,主要為大家介紹如何在Magento 2中創(chuàng )建支付方式的教程步驟。
1、在app/code/Alwayly/CustomPayment/registration.php中創(chuàng )建registration.php文件,加入代碼:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
‘Alwayly_CustomPayment’,
__DIR__
);
2、在app/code/Alwayly/CustomPayment/etc/module.xml中創(chuàng )建module.xml文件,加入代碼:
<?xml version=”1.0″?>
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:Module/etc/module.xsd”>
<module name=”Alwayly_CustomPayment” setup_version=”1.0.0″>
</module>
</config>
3、在app/code/Alwayly/CustomPayment/etc/config.xml中創(chuàng )建config.xml文件,加入代碼:
<?xml version=”1.0″?>
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”../../Store/etc/config.xsd”>
<default>
<payment>
<custompayment>
<payment_action>authorize</payment_action> <!– You can use another method –>
<model>AlwaylyCustomPaymentModelPaymentMethod</model>
<active>1</active>
<title>Custom Payment</title>
<order_status>pending_payment</order_status><!– set default order status–>
</custompayment>
</payment>
</default>
</config>
4、在app/code/Alwayly/CustomPayment/etc/adminhtml/system.xml中創(chuàng )建system.xml文件,加入代碼:
<?xml version=”1.0″?>
<config xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:module:Magento_Config:etc/system_file.xsd”>
<system>
<section id=”payment”>
<group id=”custompayment” translate=”label” sortOrder=”100″ showInDefault=”1″ showInWebsite=”1″ showInStore=”1″>
<label>Custom Payment Method</label>
<field id=”active” translate=”label comment” sortOrder=”10″ type=”select” showInDefault=”1″ showInWebsite=”1″ showInStore=”0″>
<label>Enable</label>
<source_model>MagentoConfigModelConfigSourceYesno</source_model>
</field>
<field id=”title” translate=”label” type=”text” sortOrder=”20″ showInDefault=”1″ showInWebsite=”1″ showInStore=”1″>
<label>Custom Payment</label>
</field>
</group>
</section>
</system>
</config>
5、在app/code/Alwayly/CustomPayment/Model/PaymentMethod.php中創(chuàng )建PaymentMethod.php文件,加入代碼:
<?php
namespace AlwaylyCustomPaymentModel;
/**
* Pay In Store payment method model
*/
class PaymentMethod extends MagentoPaymentModelMethodAbstractMethod
{
/**
* Payment code
*
* @var string
*/
protected $_code = ‘custompayment’;
}
6、在app/code/Alwayly/CustomPayment/view/frontend/layout/checkout_index_index.xml中創(chuàng )建checkout_index_index.xml文件,加入代碼:
<?xml version=”1.0″?>
<page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”>
<body>
<referenceBlock name=”checkout.root”>
<arguments>
<argument name=”jsLayout” xsi:type=”array”>
<item name=”components” xsi:type=”array”>
<item name=”checkout” xsi:type=”array”>
<item name=”children” xsi:type=”array”>
<item name=”steps” xsi:type=”array”>
<item name=”children” xsi:type=”array”>
<item name=”billing-step” xsi:type=”array”>
<item name=”component” xsi:type=”string”>uiComponent</item>
<item name=”children” xsi:type=”array”>
<item name=”payment” xsi:type=”array”>
<item name=”children” xsi:type=”array”>
<item name=”renders” xsi:type=”array”>
<!– merge payment method renders here –>
<item name=”children” xsi:type=”array”>
<item name=”custompayment” xsi:type=”array”>
<item name=”component” xsi:type=”string”>Emipro_Custompayment/js/view/payment/method-renderer</item>
<item name=”methods” xsi:type=”array”>
<item name=”custompayment” xsi:type=”array”>
<item name=”isBillingAddressRequired” xsi:type=”boolean”>true</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</item>
</argument>
</arguments>
</referenceBlock>
</body>
</page>
7、在app/code/Alwayly/CustomPayment/view/frontend/web/js/view/payment/method-renderer.js上創(chuàng )建method-renderer.js文件,加入代碼:
define(
[
‘uiComponent’,
‘Magento_Checkout/js/model/payment/renderer-list’
],
function (
Component,
rendererList
) {
‘use strict’;
rendererList.push(
{
type: ‘custompayment’,
component: ‘Alwayly_CustomPayment/js/view/payment/method-renderer/custompayment’
}
);
return Component.extend({});
}
);
8、在app/code/Alwayly/CustomPayment/view/frontend/web/js/view/payment/method-renderer/custompayment.js上創(chuàng )建custompayment.js文件,加入代碼:
define(
[
‘Magento_Checkout/js/view/payment/default’
],
function (Component) {
‘use strict’;return Component.extend({
defaults: {
template: ‘Alwayly_CustomPayment/payment/customtemplate’
}
});
}
);
9、在app/code/Alwayly/CustomPayment/view/frontend/web/template/payment/customtemplate.html上創(chuàng )建customtemplate.html文件,加入代碼:
<div class=”payment-method” data-bind=”css: {‘_active’: (getCode() == isChecked())}”>
<div class=”payment-method-title field choice”>
<input type=”radio”
name=”payment[method]”
class=”radio”
data-bind=”attr: {‘id’: getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()”/>
<label data-bind=”attr: {‘for’: getCode()}” class=”label”><span data-bind=”text: getTitle()”></span></label>
</div>
<div class=”payment-method-content”>
<!– ko foreach: getRegion(‘messages’) –>
<!– ko template: getTemplate() –><!– /ko –>
<!–/ko–>
<div class=”payment-method-billing-address”>
<!– ko foreach: $parent.getRegion(getBillingAddressFormName()) –>
<!– ko template: getTemplate() –><!– /ko –>
<!–/ko–>
</div>
<div class=”checkout-agreements-block”>
<!– ko foreach: $parent.getRegion(‘before-place-order’) –>
<!– ko template: getTemplate() –><!– /ko –>
<!–/ko–>
</div>
<div class=”actions-toolbar”>
<div class=”primary”>
<button class=”action primary checkout”
type=”submit”
data-bind=”
click: placeOrder,
attr: {title: $t(‘Place Order’)},
css: {disabled: !isPlaceOrderActionAllowed()},
enable: (getCode() == isChecked())
”
disabled>
<span data-bind=”i18n: ‘Place Order'”></span>
</button>
</div>
</div>
</div>
</div>
到此,就完成了在Magento 2商店中創(chuàng )建自定義付款方式的步驟。接下來(lái)就可以啟用付款方式,步驟如下:
1、如圖所示,選擇“YES”
2、啟用付款方式后,可以在檢出產(chǎn)品時(shí)將其顯示在前端:
來(lái)源鏈接:https://www.idcspy.com/23947.html
本站聲明:網(wǎng)站內容來(lái)源于網(wǎng)絡(luò ),如有侵權,請聯(lián)系我們,我們將及時(shí)處理。
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站