2017-08-10 33 views
1

我试图做的是获取名为“特殊产品”的属性,然后查看它的特定类型特殊产品; garminpilot,garminpilotpro,garminpilotpremiumgarmintrainer。然后,如果产品上存在这些文件,请将特定文本字符串分配给变量$ 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 = ''; 
} 
+0

不,不是我的知识。 –

回答

0

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

$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.' 
    : '';