我正在构建我的第一个prestshop。我有几个产品的属性组合对价格有影响。在列表视图中,我想检测产品是否有多个附加组合,以便在价格之前显示'from'。
我没能找到一种方法来访问与product_list.tpl的属性或组合相关的任何东西。我在product.php中找到了一个函数,它可能适合我想要实现的目标。
public function hasAttributes()
{
if (!Combination::isFeatureActive())
return 0;
return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT COUNT(*)
FROM `'._DB_PREFIX_.'product_attribute` pa
'.Shop::addSqlAssociation('product_attribute', 'pa').'
WHERE pa.`id_product` = '.(int)$this->id
);
}
从product_list 。我可以访问产品类中的其他东西,例如:'features',我希望以类似的方式获得属性。
我唯一能找到的‘features’被声明为变量的地方是在产品控制器中,作为这个数组的一部分:
$this->context->smarty->assign(array( ...
所以我认为应该这样做,添加一个变量并指向产品类中所需的函数。但不管我输入什么,它就是不工作。我做错了什么?这是正确的方法吗?
提前感谢。
网站地址:rhum-martinique.de
您可以使用ProductCore::getAttributeCombinaisons
方法并使用count
函数检查其结果
将此功能添加到文件/config/config.inc.php
function count_product_combinations($id_product)
{
$product = new Product($id_product);
return count($product->getAttributeCombinaisons(Context::getContext()->language->id));
}
将以下代码添加到您的tpl文件:
{if count_product_combinations($product.id_product) > 1}
<span class="price-prefix">{l s='From'}</span>
{/if}