【问题标题】:Prestashop Get combination product from id'sPrestashop 从 id 获取组合产品
【发布时间】:2015-10-23 09:56:43
【问题描述】:

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

现在,我如何将这些“属性 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}

是否有任何辅助功能或类似的东西。喜欢:

::GetByAttributes($product_id, [ attr_id1, attr_id2, attr_id3 ] );

【问题讨论】:

  • 也许我误解了任务,但您已经有combinations(其他名称“product_attribute”,仅包含“属性”),因此客户可以从您显示的列表中选择组合,并且组合已经有价格等。我不确定你想从辅助函数中得到什么结果?

标签: php smarty e-commerce prestashop prestashop-1.6


【解决方案1】:

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

$productId = 123;
$attributeIds = [123, 1234];
$combinationId = (int) \Product::getIdProductAttributesByIdAttributes(
    $productId,
    $attributeIds
);

更新

正如@PululuK 在 PrestaShop 1.7.3.1 中的评论中所指出的,这已被弃用,我们应该改用 Product::getIdProductAttributeByIdAttributes(),请参阅 https://github.com/PrestaShop/PrestaShop/blob/develop/classes/Product.php#L6511

【讨论】:

  • 虽然只有代码的答案可能会为问题提供解决方案,但某种形式的解释将有助于使这个答案更有用。
  • 此功能自 ps 1.7.3.1 起已弃用,请参阅 github.com/PrestaShop/PrestaShop/blob/develop/classes/… 没有您可以使用的 getIdProductAttributeByIdAttributes
【解决方案2】:

我这里用的是 id_product 21 ,我的前缀表是 ps_ (默认),lang id 是 1 ,数量是为属性stock取的

这是我从 prestashop 代码中获取的查询,翻译成单个查询,根据需要更改它,它将给出产品属性 id、数量和用于组合的 prestashop 格式

选择 pac.id_product_attribute, (SELECT SUM(quantity) from ps_stock_available where id_product_attribute = pac.id_product_attribute) 作为数量,GROUP_CONCAT(agl.name, '-',al.name ORDER BY agl.id_attribute_group SEPARATOR '-') 作为 attribute_designation FROM ps_product_attribute_combination pac 左连接 ps_attribute a ON a.id_attribute = pac.id_attribute 左连接 ps_attribute_group ag ON ag.id_attribute_group = a.id_attribute_group 左连接 ps_attribute_langal ON ( id_attribute = al.id_attribute AND al.id_lang = 1) 左连接 ps_attribute_group_lang agl ON (ag.id_attribute_group = agl.id_attribute_group AND agl.id_lang = 1) 在哪里 pac.id_product_tribute IN (SELECT pa.id_product_attribute FROM ps_product_attribute pa WHERE pa.id_product = 21 GROUP BY pa.id_product_attribute) GROUP BY pac.id_product_attribute

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-06
    • 2017-12-09
    • 1970-01-01
    • 2014-08-15
    • 2023-03-05
    • 2014-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多