【发布时间】:2020-07-02 10:51:43
【问题描述】:
您好,我的 magento2 商店有 2 种付款方式。一种是货到付款,另一种是自定义支付网关。我安装了自定义支付网关扩展,它工作正常。
现在我有一些条件,如果条件没问题,那么我只需要激活那个自定义支付网关扩展。
我的产品有一个名为“otherthancod”的产品属性。如果 'otherthancod' 处于活动状态,然后只显示自定义 结帐页面中的支付网关。为此,我编写了以下代码。
$items = $cart->getItems();
$flag = 0;
$count=0;
foreach($items as $item){
$attribute1 = $item->getProduct()->getData('otherthancod');
if($attribute1){
$flag++;
$count++;
}else{
$flag--;
}
}
if($flag == $count){
$checkResult = $observer->getEvent()->getResult();
$checkResult->setData('is_available', true);
}else{
$checkResult = $observer->getEvent()->getResult();
$checkResult->setData('is_available', false);
}
现在我想知道我需要把这段代码放在哪里?我不想为此创建另一个扩展。
请帮忙。
在我的自定义付款扩展中,我看到了以下页面 app/code/custompaymentgaetway/custom/Gateway/Config/config.php
class Config extends \Magento\Payment\Gateway\Config\Config{
}
我可以在这个类之前添加 if 条件吗?我认为这个类正在激活支付网关。
我可以在我的支付网关的前端模板中看到 \view\frontend\web\template\custompaymentgaetway.html。实际上,一旦条件为假,我想隐藏这个前端。
【问题讨论】:
-
隐藏扩展是什么意思?
-
在结帐页面我可以看到货到付款和自定义支付网关。如果条件为假,那么我需要从结帐页面隐藏自定义支付网关。你能帮忙解决这个问题吗?
-
webkul.com/blog/… 看到这个
-
非常感谢。但是这段代码需要写在 app/code/ 文件夹中。所以在那之后我必须运行 php bin/magento setup:upgrade 。我太担心 abi=out 运行这个命令了。这就是我不想创建其他扩展的原因。我可以在任何其他已安装的扩展中添加此代码吗?
-
你为什么担心 setup:upgrade 命令?它是 OOTB 命令,应该可以正常工作