作为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列表中看不到。还有其他我应该准备的小东西吗?
[看一下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
。您的语言表中是否有一个0
的language_id?可能不会。典型的(默认)Opencart的安装有一个语言与1
的LANGUAGE_ID。考虑到这一点,你的阵列应该是这样的:
'product_description' => [1 => ['name' => 'bakbuişte', 'description' => '', 'meta_title' => 'metaraba', 'meta_description' => '', 'meta_keyword' => '', 'tag' => '']],
当你写的说明行与错LANGUAGE_ID事情失败的原因是,该产品列表与这样的查询检索:
SELECT *
FROM product p
LEFT JOIN product_description pd ON (p.product_id = pd.product_id)
WHERE pd.language_id = '1';
注意的where
条件在结束了吗?如果您的描述表缺少与language_id 1相对应的行,则查询将忽略您的产品行。