简体   繁体   中英

Programmatically update combinations in PrestaShop 1.7

I'm trying to update product combinations price. $c_key is the combination ID, but it doesn't update the price.

foreach ($c_area_input as $c_key => $c_area) {
    $price_c = (float)$c_price_area_input[$c_key] * (float)$c_area;
    $product->updateAttribute((int)$c_key,0, $price_c);
    Db::getInstance()->insert('areapacks_combination', array(
        'id_product' => (int)$id_product,
        'id_combination' => (int)$c_key,
        'item_area' => (float)$c_area,
        'price_item_area' => (float)$c_price_area_input[$c_key]
    ));
}

Try with :

foreach ($c_area_input as $c_key => $c_area) {
    $price_c = (float)$c_price_area_input[$c_key] * (float)$c_area;

    $product = new Product($id_product);
    $product->updateProductAttribute($c_key, $c_price_area_input[$c_key], $c_price_area_input[$c_key]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM