我试图学习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失败
发布于 2019-09-30 15:47:42
您似乎创建了一个新产品,但没有填写必填字段。如果要更改现有产品,则需要在创建产品对象时设置其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();
}发布于 2019-09-30 17:49:44
据我所知,您希望禁用特定供应商的所有产品
首先,您希望从数据库中的表ps_product中获取所有产品in的列表。然后按每个id_product实例化一个产品对象,如果它具有您提到的id_supplier条件,则将其禁用
require(dirname(__FILE__).'/../config/config.inc.php');
// getting list of product_id
$product_ids = Db::getInstance()->executeS('select id_product from ps_product');
foreach($product_ids as $item) {
$product = new Product($item['id_product']);
if ($product->id_supplier == 2) {
$product->active = false;
$product->update();
}
}https://stackoverflow.com/questions/58131779
复制相似问题