从Magento获取特定属性,如果该属性值包含特定数据,则将特定字符串分配给变量

时间:2017-08-10 20:46:26

标签: php magento

我尝试做的是获取名为“ specialproduct ”的属性,然后查看特定类型的特殊产品; garminpilot garminpilotpro garminpilotpremium garmintrainer 。然后,如果产品上存在这些字符串,请将特定文本字符串分配给变量 $ specialproductmsg

这就是我现在拥有的。有没有更好的方法来做到这一点?还有什么更有效的吗?

$specialtype = $item->getProduct()->getAttributeText('specialproduct');

if(in_array($specialtype, array('garminpilot','garminpilotpro','garminpilotpremium','garmintrainer'))) {
    $specialproductmsg = 'You have ordered an online course. Please visit http://example.com/onlinecourse to view your online course.';
}
else {
    $specialproductmsg = '';
}

1 个答案:

答案 0 :(得分:0)

您可以使用这样的三元运算符:

NotificationChannel
相关问题