从Magento获取特定属性,如果该属性值包含特定数据,请将特定字符串分配给变量
问题描述:
我试图做的是获取名为“特殊产品”的属性,然后查看它的特定类型特殊产品; garminpilot,garminpilotpro,garminpilotpremium和garmintrainer。然后,如果产品上存在这些文件,请将特定文本字符串分配给变量$ specialproductmsg。从Magento获取特定属性,如果该属性值包含特定数据,请将特定字符串分配给变量
这是我目前拥有的。有没有更好的方法来做到这一点?更有效率的东西?
$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 = '';
}
答
您可以使用三元运算符是这样的:
$types = ['garminpilot', 'garminpilotpro', 'garminpilotpremium', 'garmintrainer'];
$specialproductmsg = in_array($specialtype, $types)
? 'You have ordered an online course. Please visit http://example.com/onlinecourse to view your online course.'
: '';
不,不是我的知识。 –