如何添加自定义付款方式在Magento

步骤一: 创建付款方式模块
Step 1: 创建 registration.php以注册您的付款方式。
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::MODULE,
    'PayFabric_Payment',
    __DIR__
);
Step 2: 创建 composer.json
{
  "name": "payfabric/module-payment",
  "description": "PayFabric Payment Gateway",
  "type": "magento2-module",
  "version": "1.0.0",
  "license": [
    "OSL-3.0",
    "AFL-3.0"
  ],
  "require": {
    "php": "~5.5.22|~5.6.0|~7.0.0|~7.1.0|~7.2.0|~7.3.0|~7.4.0",
    "magento/module-sales": "100.0.*",
    "magento/module-checkout": "100.0.*",
    "magento/module-payment": "100.0.*",
    "magento/framework": "100.0.*",
    "magento/magento-composer-installer": "100.0.*"
  },
  "autoload": {
    "files": [
      "registration.php"
    ],
    "psr-4" : {
      "PayFabric\\Payment\\" : ""
    }

  }
}
Step 3: 创建etc\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="PayFabric_Payment" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Payment" />
            <module name="Magento_Checkout"/>
            <module name="Magento_Sales"/>
            <module name="Magento_Quote"/>
            <module name="Magento_Config" />
            <module name="Magento_Directory" />
        </sequence>
    </module>
</config>
Step 4: 创建etc\config.xml定义付款方式的配置
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <payment>
            <payfabric_payment>
                <active>0</active>
                <model>PayFabric\Payment\Model\PaymentMethod</model>
                <title>PayFabric</title>
                <payment_action>sale</payment_action>
                <order_status>pending</order_status>
                <payment_cancelled>canceled</payment_cancelled>
                <merchant_id></merchant_id>
                <merchant_password></merchant_password>
                <display_mode>Redirect</display_mode>
                <debug_log>1</debug_log>
                <environment>production</environment>
                <is_gateway>1</is_gateway>
                <allowspecific>0</allowspecific>
                <specific_countries></specific_countries>
                <specific_currencies></specific_currencies>
            </payfabric_payment>
        </payment>
    </default>
</config>
Step 5: etc\adminh

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Magento 2中发送多个附件的电子邮件,您需要对`Magento\Framework\Mail\Template\TransportBuilder`类进行扩展。 下面是一个示例代码,它可以让您在Magento 2中发送多个附件的电子邮件: 1. 创建 `Vendor\Module\Model\Mail\Template\TransportBuilder.php` 文件并添加以下代码: ```php <?php namespace Vendor\Module\Model\Mail\Template; use Magento\Framework\App\Filesystem\DirectoryList; use Magento\Framework\Exception\MailException; use Magento\Framework\Mail\Template\TransportBuilder as MagentoTransportBuilder; use Magento\Framework\Mail\TransportInterfaceFactory; use Magento\Framework\Translate\Inline\StateInterface; use Magento\Store\Model\StoreManagerInterface; class TransportBuilder extends MagentoTransportBuilder { /** * @var array */ protected $attachments = []; /** * @param array $attachments * @return $this */ public function addMultipleAttachment($attachments = []) { foreach ($attachments as $attachment) { if (file_exists($attachment['path'])) { $this->attachments[] = [ 'type' => $attachment['type'], 'name' => $attachment['name'], 'path' => $attachment['path'] ]; } } return $this; } /** * @param null|string|array $to * @param array $templateVars * @param null|string $templateOptions * @param null|string $transportOptions * * @throws MailException * * @return TransportInterfaceFactory */ public function getTransport( $to = null, array $templateVars = [], $templateOptions = null, $transportOptions = null ) { if (!empty($this->attachments)) { foreach ($this->attachments as $attachment) { $this->message->createAttachment( file_get_contents($attachment['path']), $attachment['type'], \Zend_Mime::DISPOSITION_ATTACHMENT, \Zend_Mime::ENCODING_BASE64, $attachment['name'] ); } } return parent::getTransport($to, $templateVars, $templateOptions, $transportOptions); } } ``` 2. 创建 `Vendor_Module` 模块的 `di.xml` 文件并添加以下代码: ```xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <preference for="Magento\Framework\Mail\Template\TransportBuilder" type="Vendor\Module\Model\Mail\Template\TransportBuilder" /> </config> ``` 3. 在您的模块中使用以下代码发送多个附件的电子邮件: ```php <?php namespace Vendor\Module\Controller\Index; use Magento\Framework\App\Action\Action; use Magento\Framework\App\Action\Context; use Magento\Framework\Mail\Template\TransportBuilder; use Magento\Framework\Translate\Inline\StateInterface; use Magento\Store\Model\StoreManagerInterface; class SendEmail extends Action { /** * @var TransportBuilder */ protected $transportBuilder; /** * @var StateInterface */ protected $inlineTranslation; /** * @var StoreManagerInterface */ protected $storeManager; /** * @param Context $context * @param TransportBuilder $transportBuilder * @param StateInterface $inlineTranslation * @param StoreManagerInterface $storeManager */ public function __construct( Context $context, TransportBuilder $transportBuilder, StateInterface $inlineTranslation, StoreManagerInterface $storeManager ) { $this->transportBuilder = $transportBuilder; $this->inlineTranslation = $inlineTranslation; $this->storeManager = $storeManager; parent::__construct($context); } /** * @return void */ public function execute() { $attachmentOne = [ 'name' => 'Attachment One', 'path' => 'path/to/attachment/one.pdf', 'type' => 'application/pdf' ]; $attachmentTwo = [ 'name' => 'Attachment Two', 'path' => 'path/to/attachment/two.pdf', 'type' => 'application/pdf' ]; try { $this->inlineTranslation->suspend(); $this->transportBuilder->setTemplateIdentifier('your_email_template_id') ->setTemplateOptions([ 'area' => 'frontend', 'store' => $this->storeManager->getStore()->getId() ]) ->setTemplateVars([]) ->setFrom([ 'email' => '[email protected]', 'name' => 'Sender Name' ]) ->addTo('[email protected]', 'Recipient Name') ->addMultipleAttachment([$attachmentOne, $attachmentTwo]) ->getTransport() ->sendMessage(); $this->inlineTranslation->resume(); $this->messageManager->addSuccess(__('Your email was sent successfully.')); } catch (\Exception $e) { $this->inlineTranslation->resume(); $this->messageManager->addError(__('There was an error sending your email. Please try again later.')); } return $this->_redirect('*/*/index'); } } ``` 以上代码将会发送带有两个附件的电子邮件。您可以根据自己的需要更改附件的数量和详细信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值