Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Prestashop 1.6产品列表:获取附加属性组合的数量_Php_E Commerce_Prestashop - Fatal编程技术网

Php Prestashop 1.6产品列表:获取附加属性组合的数量

Php Prestashop 1.6产品列表:获取附加属性组合的数量,php,e-commerce,prestashop,Php,E Commerce,Prestashop,我正在建造我的第一个普雷斯塔什酒店。我有一些产品的属性组合会对价格产生影响。在列表视图中,我想检测产品是否附加了多个组合,以便在价格之前显示“from” 我无法从product_list.tpl中找到任何与属性或组合相关的方法。 我在product.php中找到了一个函数,它可能适合我要实现的目标 public function hasAttributes() { if (!Combination::isFeatureActive()) return 0; ret

我正在建造我的第一个普雷斯塔什酒店。我有一些产品的属性组合会对价格产生影响。在列表视图中,我想检测产品是否附加了多个组合,以便在价格之前显示“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.tpl中,我可以访问产品类中的其他内容,例如“features”,我希望以类似的方式获得属性。
我能找到的唯一一个将“功能”声明为变量的位置是在product controller中,作为此数组的一部分:

$this->context->smarty->assign(array( ...
所以我假设这就是方法,添加一个变量并指向product类中所需的函数。但不管我在这里输入什么,它都不起作用。我做错了什么?这是正确的方法吗

提前谢谢


您可以在

上查看该网站。您可以使用方法
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}
{if count\u product\u组合($product.id\u product)>1}
{l s='From'}
{/if}

感谢您的反馈。我已经用hasAttributes尝试过类似的东西,但没有骰子。不幸的是,您的解决方案也不起作用:致命错误:对非objectposted:调用成员函数GetAttributeCombinAsons()。您的代码段位于第105行,当前已注释掉。变量
$product
不是
对象
,而是
数组
,我将编辑我的应答致命错误:未捕获-->Smarty编译器:模板中的语法错误。。。{$productObj=new Product($Product.id_Product,false);}“未知函数”Product“smarty似乎混淆了函数的类