购物车规则添加产品限制(prestashop 8.0)

问题描述 投票:0回答:0

我正在 PRESTASHOP 网站上创建自动购物车规则。

我找不到对产品施加限制以使购物车规则有效的方法。我通过插入数据 $id_cart_rule 和 $id_group 通过 SQL 添加了对特定组的限制,但是对于产品限制,存在 3 个表:ps_cart_rule_product_rule、ps_cart_rule_product_rule_group 和 ps_cart_rule_product_rule_value。这意味着为 id_product_rule 和 id_product_rule_group 创建具有 id 的对象。

我卡住了,有人知道怎么办吗?

这是我当前的代码,它创建了一个篮子规则并为每个组添加了一个限制。

$date = strtotime($r['date']); $date_formated = date("Y-m-d", $date);

    $id_product =  Product::getIdBy(['external_reference' => $r['code_produit'] ]);
    $id_group =    Group::getIdBy(['external_reference' => $r['cat_tarifaire'] ]);
    $id_customer = Customer::getIdBy(['external_reference' => $r['code_client'] ]);

    $cartRule = new CartRule();

    if($id_customer) {
        $cartRule->id_customer = $id_customer;
    }

    $cartRule->name = array($this->langId => "test_promoX+Y");
    $cartRule->date_from = $date_formated;
    $cartRule->date_to = "2050-01-01";
    $cartRule->active = true;
    $cartRule->group_restriction = true;
    $cartRule->product_restriction = true;

    if($id_product) {
        $cartRule->gift_product = $id_product;
    }

    $cartRule->save();

    $id_cart_rule = $cartRule->id;

    if($id_group > 0)
    {
        $groupRestriction = \Db::getInstance()->getValue(
            "INSERT INTO
            "._DB_PREFIX_."cart_rule_group
            (id_cart_rule, id_group)
            VALUES ($id_cart_rule, $id_group)
            " );
    }


    return true;
}

我尝试在所有prestashop native classes里搜索cart rule和products相关的,直接在sql里找解决方案

php mysql prestashop
© www.soinside.com 2019 - 2024. All rights reserved.