如何以编程方式更新Prestashop产品状态?

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

我试图学习PS,我想通过外部脚本简单地更新所有Prestsahop产品的状态。

我有类似的方法可以使供应商禁用所有产品(例如):

<?php

include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');

$default_lang = Configuration::get('PS_LANG_DEFAULT');
$product = new Product();
if ($product->id_supplier = 2) {
    $product->active = 0;
    $product->update();
}

但是它未能引发PrestaShopDatabaseException

php prestashop
1个回答
0
投票

似乎您正在创建新产品,但没有填写必填字段。如果要更改现有产品,则需要在创建产品对象期间设置其ID。所以你的代码应该像

$product = new Product($id_product, true, $default_lang); // if you want to get certain language, if ont skip the last parameter

if ($product->id_supplier = 2) {
    $product->active = 0;
    $product->update();
}
© www.soinside.com 2019 - 2024. All rights reserved.