簡體   English   中英

Opencart 模塊錯誤:警告:opencart/admin/model/catalog/product.php 中的非法字符串偏移“model”

[英]Opencart module error: Warning: Illegal string offset 'model' in opencart/admin/model/catalog/product.php

我試圖創建一個模塊來自動將產品從外部數據庫導入到 Opencart 的數據庫中。

我按照所有可用的文檔來構建模塊。 創建控制器、視圖、語言文件。 我沒有創建模型文件,因為我使用的是 opencarts 模型。

在我的控制器opencart/admin/controller/extension/module/auto_product_import.php

我開始與我的外部數據庫建立連接。 然后我執行查詢以檢索所有產品及其數據(價格、描述等)。

之后,我創建一個數組以滿足 opencart 模型的需要,並用我新檢索的數據填充它:

    for ($i=0; $i < 1; $i++) { 
                $products_data_array[] = array(
                    'product_description' => array(
                        'name' => strval($results['product_CODE'][$i]),
                        'meta_description' => strval($results['DESCR'][$i]),
                        'meta_keyword' => strval($results['product_CODE'][$i]),
                        'description' => strval($results['DESCR'][$i]),
                        'tag' => strval($results['CODCODE'][$i]),
                    ),
                    'custom_id' => $results['custom_ID'][$i],
                    'model' => $results['product_CODE'][$i], 
                    'sku' => '', 
                    'upc' => '', 
                    'ean' => '', 
                    'jan' => '', 
                    'isbn' => '', 
                    'mpn' => '', 
                    'location' => '', 
                    'price' => $results['PRICE'][$i], 
                    'tax_class_id' => '',
                    'quantity' => '',
                    'minimum' => '',
                    'subtract' => '',
                    'stock_status_id' => '5',
                    'shipping' => '',
                    'keyword' => '', 
                    'image' => '',
                    'date_available' => '',
                    'length' => '',
                    'width' => '',
                    'height' => '',
                    'length_class_id' => '',
                    'weight' => strval($results['weight'][$i]),
                    'weight_class_id' => '',
                    'status' => '1',
                    'sort_order' => '',
                    'manufacturer' => $brand, 
                    'manufacturer_id' => '', 
                    'category' => strval($results['category'][$i]), 
                    'filter' => '', 
                    'product_store' => array(
                        '0' => 0
                    ),
                    'download' => '',
                    'related' => '',
                    'product_attribute' => array(
                        '0' => array(
                            'name' => '',
                            'attribute_id' => '', 
                            'product_attribute_description' => array(
                                '1' => array(
                                        'text' => "first language content"
                                )
                            )
                        )
    
                    ),
                    'option' => '',
                    'points' => '',
                    'product_reward' => array(
                        '1' => array(
                            'points' => ''
                        )
                    ),
                    'product_layout' => array(
                        '0' => array(
                                'layout_id' => '' 
                        )
                    )
                );

Note: Use for loop with 1 itteration for testing purpuses Note: Some items of the opencart's array are empty cause i dont have data to import for them

然后我加載 opencart 的模型來添加產品:

$this->load->model('catalog/product');

然后我使用以下方法導入產品:

$this->model_catalog_product->addProduct($products_data_array);

當我加載我的模塊時,我收到以下消息:


Warning: Illegal string offset 'model' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'custom_id' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'sku' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'upc' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'ean' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'jan' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'isbn' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'mpn' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'location' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'quantity' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'minimum' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'subtract' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'stock_status_id' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'date_available' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'manufacturer_id' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'shipping' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'price' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'points' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'weight' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'weight_class_id' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'length' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'width' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'height' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'length_class_id' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'status' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'tax_class_id' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'sort_order' in opencart/admin/model/catalog/product.php on line 4
Warning: Illegal string offset 'product_description' in opencart/admin/model/catalog/product.php on line 12

我試圖修改product.php模型,但我沒有運氣。 :( 它還插入一行新產品,但所有字段都是空的,它只獲取和 ID。我什至檢查了我的新數組 jsut 以防萬一。但我沒有發現任何問題。

有誰知道出了什么問題或我錯過了什么?

看起來 addProduct() 用於一次添加 1 個產品,並且您要發送整個產品陣列。

嘗試這個:

foreach ($products_data_array as $product) {
    $this->model_catalog_product->addProduct($product);
}

在我重組陣列后問題解決了。 子數組應該有一個子數組,其中的 language_id 作為鍵。

函數數組的結構應該是這樣的:

$products_data_array[] = array(

                'product_description' => array(
                    '0' => array(
                        'name' => $name,
                        'meta_description' => $meta_description,
                        'meta_title' => $meta_title,
                        'meta_keyword' => $meta_keyword,
                        'description' => $description,
                        'tag' => $tag,
                    )
                ),
                'mciid' => $mciid,
                'model' => $model, 
                'sku' => '', 
                'upc' => '', 
                'ean' => '', 
                'jan' => '', 
                'isbn' => '', 
                'mpn' => '', 
                'location' => '', 
                'price' => $price, 
                'tax_class_id' => '',
                'quantity' => '',
                'minimum' => '',
                'subtract' => '',
                'stock_status_id' => '5',
                'shipping' => '',
                'keyword' => '', 
                'image' => '',
                'date_available' => '',
                'length' => '',
                'width' => '',
                'height' => '',
                'length_class_id' => '',
                'weight' => $weight,
                'weight_class_id' => '',
                'status' => '1',
                'sort_order' => '',
                'manufacturer' => $brand, 
                'manufacturer_id' => '111', 
                'category' => $category, 
                'filter' => '', 
                'product_store' => array(
                    '0' => 0
                ),
                'download' => '',
                'related' => '',
                'product_attribute' => array(
                    '0' => array(
                        'name' => '',
                        'attribute_id' => '', 
                        'product_attribute_description' => array(
                            '1' => array(
                                    'text' => "first language content"
                            )
                        )
                    )

                ),
                'option' => '',
                'points' => '',
                'product_reward' => array(
                    '1' => array(
                        'points' => ''
                    )
                ),
                'product_layout' => array(
                    '0' => array(
                            'layout_id' => '2' 
                    )
                )
            );

注意:此數組在 Opencart 3.0.3.8 版上有效。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM