Php Prestashop从id获取组合产品

Php Prestashop从id获取组合产品,php,smarty,e-commerce,prestashop,prestashop-1.6,Php,Smarty,E Commerce,Prestashop,Prestashop 1.6,我试图在产品列表上显示数量、组合等。到目前为止,我已经可以很好地显示组合,这样我就可以从分配给产品的每个组中选择一个属性 现在,我如何将这些属性id组合成一个组合产品,以便查看价格、将其添加到购物车等 这是我获取组合的模块 function hookdisplayProductOnList($params){ $product=new Product($params['id_product']); $combinations=$product->getAttributeCo

我试图在产品列表上显示数量、组合等。到目前为止,我已经可以很好地显示组合,这样我就可以从分配给产品的每个组中选择一个属性

现在,我如何将这些属性id组合成一个组合产品,以便查看价格、将其添加到购物车等

这是我获取组合的模块

function hookdisplayProductOnList($params){
    $product=new Product($params['id_product']);
    $combinations=$product->getAttributeCombinations($this->context->language->id);

    $combArray = [];
    $combArrayIds = [];

    foreach( $combinations as $k => $v )
    {   
        if( !in_array($v["id_attribute"], $combArrayIds))
        {
            $combArrayIds[] = $v["id_attribute"];
            $combArray[ $v["group_name"] ][] = $v;
        }
    }

    $this->smarty->assign('combinations',$combArray);
    return $this->display(__FILE__, 'combinations.tpl');
}
这就是我输出组的方式

{foreach $combinations as $k=>$comb}

            <ul class="attribute-select" data-group="{$k}">
            {foreach from=$comb item=attr}
                <li data-combId="{$attr.id_attribute}" title="{l s='+'} {convertPrice price=$attr.unit_price_impact}">{$attr.attribute_name}</li>
            {/foreach}
            </ul><br />


{/foreach}

从产品ID和属性ID数组中,您可以得到产品属性ID。我想这就是您需要的

$productId = 123;
$attributeIds = [123, 1234];
$combinationId = (int) \Product::getIdProductAttributesByIdAttributes(
    $productId,
    $attributeIds
);
使现代化
正如PrestaShop 1.7.3.1中@PululuK的评论所指出的,这是不推荐的,我们应该使用Product::GetIdProductAttributeByDatAttributes,请参见。

从产品ID和属性ID数组中可以获得产品属性ID。我想这就是您需要的

$productId = 123;
$attributeIds = [123, 1234];
$combinationId = (int) \Product::getIdProductAttributesByIdAttributes(
    $productId,
    $attributeIds
);
使现代化
正如PrestaShop 1.7.3.1中@PululuK的评论所指出的,这是不推荐的,我们应该使用Product::GetIdProductAttributeByDatAttributes,请参见。

从产品ID和属性ID数组中可以获得产品属性ID。我想这就是您需要的

$productId = 123;
$attributeIds = [123, 1234];
$combinationId = (int) \Product::getIdProductAttributesByIdAttributes(
    $productId,
    $attributeIds
);
使现代化
正如PrestaShop 1.7.3.1中@PululuK的评论所指出的,这是不推荐的,我们应该使用Product::GetIdProductAttributeByDatAttributes,请参见。

从产品ID和属性ID数组中可以获得产品属性ID。我想这就是您需要的

$productId = 123;
$attributeIds = [123, 1234];
$combinationId = (int) \Product::getIdProductAttributesByIdAttributes(
    $productId,
    $attributeIds
);
使现代化
正如PrestaShop 1.7.3.1中@PululuK的评论所指出的,这是不推荐的,我们应该使用Product::GetIdProductAttributeByDatAttributes,请参见。

我在这里使用了id\u Product 21,我的前缀表是ps\uDefault,lang id是1,数量为atributes库存

这是我从prestashop代码中提取的查询,转换成单个查询,根据您的意愿进行更改,它将给出产品属性id、数量和用于组合的prestashop格式

function hookdisplayProductOnList($params){
    $product=new Product($params['id_product']);
    $combinations=$product->getAttributeCombinations($this->context->language->id);

    $combArray = [];
    $combArrayIds = [];

    foreach( $combinations as $k => $v )
    {   
        if( !in_array($v["id_attribute"], $combArrayIds))
        {
            $combArrayIds[] = $v["id_attribute"];
            $combArray[ $v["group_name"] ][] = $v;
        }
    }

    $this->smarty->assign('combinations',$combArray);
    return $this->display(__FILE__, 'combinations.tpl');
}
选择pac.id\u产品属性,
从可用的ps_stock_中选择SUMquantity,其中id_product_属性=pac.id_product_属性作为数量,组_CONCATagl.name,'-',al.name按agl.id\U属性\U组分隔符排序“-”作为ps\U产品属性\U组合pac的属性\U指定左连接ps\U属性a在a.id\U属性上=pac.id\U属性左连接ps\U属性\U组ag在ag.id\U属性上=a.id\U属性\U组左连接ps\U属性\U语言在a.id\U属性上=al.id\U属性和al.id\U语言=1左键连接ag.id\u attribute\u group=agl.id\u attribute\u group和agl.id\u lang=1,其中pac.id\u product\u属性从ps\u product\u属性pa中选择pa.id\u product\u属性,其中pa.id\u product=21组由pa.id\u产品属性组由pac.id\u产品属性,我的前缀表是ps_uu默认值,lang id是1,数量是针对atributes库存的

这是我从prestashop代码中提取的查询,转换成单个查询,根据您的意愿进行更改,它将给出产品属性id、数量和用于组合的prestashop格式

function hookdisplayProductOnList($params){
    $product=new Product($params['id_product']);
    $combinations=$product->getAttributeCombinations($this->context->language->id);

    $combArray = [];
    $combArrayIds = [];

    foreach( $combinations as $k => $v )
    {   
        if( !in_array($v["id_attribute"], $combArrayIds))
        {
            $combArrayIds[] = $v["id_attribute"];
            $combArray[ $v["group_name"] ][] = $v;
        }
    }

    $this->smarty->assign('combinations',$combArray);
    return $this->display(__FILE__, 'combinations.tpl');
}
选择pac.id\u产品属性,
从可用的ps_stock_中选择SUMquantity,其中id_product_属性=pac.id_product_属性作为数量,组_CONCATagl.name,'-',al.name按agl.id\U属性\U组分隔符排序“-”作为ps\U产品属性\U组合pac的属性\U指定左连接ps\U属性a在a.id\U属性上=pac.id\U属性左连接ps\U属性\U组ag在ag.id\U属性上=a.id\U属性\U组左连接ps\U属性\U语言在a.id\U属性上=al.id\U属性和al.id\U语言=1左键连接ag.id\u attribute\u group=agl.id\u attribute\u group和agl.id\u lang=1,其中pac.id\u product\u属性从ps\u product\u属性pa中选择pa.id\u product\u属性,其中pa.id\u product=21组由pa.id\u产品属性组由pac.id\u产品属性,我的前缀表是ps_uu默认值,lang id是1,数量是针对atributes库存的

这是我从prestashop代码中提取的查询,转换成单个查询,根据您的意愿进行更改,它将给出产品属性id、数量和用于组合的prestashop格式

function hookdisplayProductOnList($params){
    $product=new Product($params['id_product']);
    $combinations=$product->getAttributeCombinations($this->context->language->id);

    $combArray = [];
    $combArrayIds = [];

    foreach( $combinations as $k => $v )
    {   
        if( !in_array($v["id_attribute"], $combArrayIds))
        {
            $combArrayIds[] = $v["id_attribute"];
            $combArray[ $v["group_name"] ][] = $v;
        }
    }

    $this->smarty->assign('combinations',$combArray);
    return $this->display(__FILE__, 'combinations.tpl');
}
选择pac.id\u产品属性, 从可用的ps_stock_中选择SUMquantity,其中id_product_属性=pac.id_product_属性作为数量,组_CONCATagl.name,'-',al.name按agl.id\U属性\U组分隔符排序“-”作为ps\U产品属性\U组合pac的属性\U指定左连接ps\U属性a在a.id\U属性上=pac.id\U属性左连接ps\U属性\U组ag在ag.id\U属性上=a.id\U属性\U组左连接ps\U属性\U语言在a.id\U属性上=al.id\U属性和al.id\U语言=1在ag.id\u attribute\u group=agl.id\u attribute\u group和agl.id\u lang=1上左键连接ps\u attribute\u group\u lang,其中pac.id\u product\u属性位于SELECT pa.id\u product\u attri
但是从ps_product_属性pa中,pa.id_product=21按pa.id_product_属性分组按pac.id_product_属性

我在这里使用了id_product 21,我的前缀表是ps_默认值,lang id为1,数量为atributes库存

这是我从prestashop代码中提取的查询,转换成单个查询,根据您的意愿进行更改,它将给出产品属性id、数量和用于组合的prestashop格式

function hookdisplayProductOnList($params){
    $product=new Product($params['id_product']);
    $combinations=$product->getAttributeCombinations($this->context->language->id);

    $combArray = [];
    $combArrayIds = [];

    foreach( $combinations as $k => $v )
    {   
        if( !in_array($v["id_attribute"], $combArrayIds))
        {
            $combArrayIds[] = $v["id_attribute"];
            $combArray[ $v["group_name"] ][] = $v;
        }
    }

    $this->smarty->assign('combinations',$combArray);
    return $this->display(__FILE__, 'combinations.tpl');
}
选择pac.id\u产品属性,
从可用的ps_stock_中选择SUMquantity,其中id_product_属性=pac.id_product_属性作为数量,组_CONCATagl.name,'-',al.name按agl.id\U属性\U组分隔符排序“-”作为ps\U产品属性\U组合pac的属性\U指定左连接ps\U属性a在a.id\U属性上=pac.id\U属性左连接ps\U属性\U组ag在ag.id\U属性上=a.id\U属性\U组左连接ps\U属性\U语言在a.id\U属性上=al.id\U属性和al.id\U语言=1左键在ag.id\u attribute\u group=agl.id\u attribute\u group和agl.id\u lang=1中加入ps\u attribute\u group\u lang,其中pac.id\u product\u属性从ps\u product\u attribute pa中选择pa.id\u product\u属性,其中pa.id\u product=21按pa.id\u产品属性组按pac.id\u产品属性,但是您已经有了组合,其他名称product_属性只包含属性,因此客户可以从您显示的列表中选择组合,并且组合已经有了价格等。我不确定您希望从helper函数中得到什么结果?可能我误解了任务,但是您已经有了组合,其他名称product_属性只包含属性,因此客户可以从您显示的列表中选择组合,并且组合已经有了价格等。我不确定您希望从helper函数中得到什么结果?可能我误解了任务,但是您已经有了组合,其他名称product_属性只包含属性,因此客户可以从您显示的列表中选择组合,并且组合已经有了价格等。我不确定您希望从helper函数中得到什么结果?可能我误解了任务,但您已经有了仅包含属性的组合(其他名称product_属性),因此客户可以从您显示的列表中选择组合,并且组合已经有了价格等。我不确定您希望从helper函数中得到什么结果?虽然仅代码答案可能提供问题的解决方案,某种形式的解释将有助于使这成为一个更有用的答案。由于ps 1.7.3.1 See Nos您可以使用GetIdProductAttributeByIdAttributes,此函数已被弃用,而仅代码答案可能提供问题的解决方案,某种形式的解释将有助于使这成为一个更有用的答案。由于ps 1.7.3.1 See Nos您可以使用GetIdProductAttributeByIdAttributes,此函数已被弃用,而仅代码答案可能提供问题的解决方案,某种形式的解释将有助于使这成为一个更有用的答案。由于ps 1.7.3.1 See Nos您可以使用GetIdProductAttributeByIdAttributes,此函数已被弃用,而仅代码答案可能提供问题的解决方案,某种形式的解释将有助于使这成为一个更有用的答案。此函数已被弃用,因为ps 1.7.3.1 See Nos您可以使用GetIdProductAttributeByAdattributes