【问题标题】:Product is listed on database is not listed in Admin > Products List数据库中列出的产品未在“管理”>“产品列表”中列出
【发布时间】:2019-12-31 00:07:39
【问题描述】:

作为一名 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 表中的条目就像其他人一样,但在管理 > 目录 > 产品列表中没有。还有什么小东西需要准备吗?

【问题讨论】:

    标签: opencart opencart-3 opencart-module


    【解决方案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。你的语言表中有0 的language_id 吗?可能不是。典型的(默认)opencart 安装有一种语言,其 language_id 为 1。考虑到这一点,您的数组应如下所示:

    '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 的对应行,查询将忽略您的产品行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-02
      • 2017-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多