Prestashop 1.6 product_list:获取附加属性组合的数量

时间:2015-06-06 15:15:18

标签: php e-commerce prestashop

我正在构建我的第一个prestashop。我有几个产品的属性组合会对价格产生影响。在列表视图中,我想检测一个产品是否附加了多个组合,以显示一个'来自'在价格之前。

我无法找到从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.tpl我可以访问产品类中的其他内容,例如'特征'我希望以类似的方式获得属性。
我唯一能找到的地方'功能'声明为变量的是在产品控制器中,作为此数组的一部分:

$this->context->smarty->assign(array( ...

所以我认为这是最好的方法,添加一个变量并指向产品类中的所需函数。但无论我在这里进入什么,它都没有成功。我究竟做错了什么?这是正确的做法吗?

提前致谢。

您可以在rhum-martinique.de

查看该网站

1 个答案:

答案 0 :(得分:0)

您可以使用方法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}
相关问题