作为Opencart的新手,我正在添加带有静态数组的产品,仅用于测试addProduct函数,但无法使其正常工作。
静态数组:
$data['pid'] = $this->model_catalog_product->addProduct([
'product_description' => [['name' => 'bakbuişte', 'description' => '', 'meta_title' => 'metaraba', 'meta_description' => '', 'meta_keyword' => '', 'tag' => '']],
'model' => 'amabigun',
'sku' => '',
'upc' => '',
'ean' => '',
'jan' => '',
'isbn' => '',
'mpn' => '',
'location' => '',
'price' => '',
'tax_class_id' => '0',
'quantity' => '1',
'minimum' => '1',
'subtract' => '1',
'stock_status_id' => '6',
'shipping' => '1',
'date_available' => '2019-12-31',
'length' => '',
'width' => '',
'height' => '',
'length_class_id' => '1',
'weight' => '',
'weight_class_id' => '1',
'status' => '1',
'sort_order' => '1',
'manufacturer' => '',
'manufacturer_id' => '',
'category' => '',
'filter' => '',
'product_store' => array(0 => '0',),
'download' => '',
'related' => '',
'option' => '',
'image' => '',
'points' => '',
'product_reward' => array(1 => array('points' => '',),),
'product_seo_url' => array(0 => array(1 => '',),),
'product_layout' => array(0 => '',)
]);
此块之后,我在oc_product
表中看到的条目与其他条目一样,但在Admin> Catalog> Products列表中看不到。还有其他我应该准备的小东西吗?
答案 0 :(得分:1)
看一看addProduct()
函数,您将看到一些执行向description
表插入的代码,如下所示:
foreach ($data['product_description'] as $language_id => $value) {
...
}
根据该逻辑, 阵列键为language_id 。在您的阵列中,您具有:
'product_description' => [['name' => 'bakbuişte', 'description' => '', 'meta_title' => 'metaraba', 'meta_description' => '', 'meta_keyword' => '', 'tag' => '']],
由于未定义数组键,因此您的描述将分配给键0
。您的语言表中是否有{_ {1}}的language_id?可能不会。典型的(默认)opencart安装使用一种语言,其language_id为0
。考虑到这一点,您的数组应如下所示:
1
当您使用错误的language_id编写描述行时,事情会失败的原因是,使用以下查询检索了产品列表:
'product_description' => [1 => ['name' => 'bakbuişte', 'description' => '', 'meta_title' => 'metaraba', 'meta_description' => '', 'meta_keyword' => '', 'tag' => '']],
注意到末尾的SELECT *
FROM product p
LEFT JOIN product_description pd ON (p.product_id = pd.product_id)
WHERE pd.language_id = '1';
条件吗?如果您的描述表缺少与language_id 1相对应的行,则查询将忽略您的产品行。