2014-05-21 6 views
4

내가 opencart에 새로운 오전, 나는 자동으로 opencart 웹 사이트/편집 제품을 추가/삭제하는 코드를 작성해야, 그래서 제 질문은 다음과 같다 : OpenCart는 자동으로 새로운 제품을 추가합니다. 제품 조작

어떻게 데이터베이스에 새로운 제품을 추가하기 자동으로 PHP와? (opencart에 몇 가지 방법이있을 수 있으므로 사용하거나 처음부터 코드를 작성해야합니까?)

추 신 : 예 : 멋지 네요 (제품 정보가 어레이에 있다고 가정)

PPS : 일부 제품이 자동으로 추가되지는 않습니다.

+0

부도, 당신은 모든 제품 관련 MySQL의 쿼리가 포함 된 관리 폴더에 모델/제품 폴더를 탐색하여 시작할 수 있습니다. 확장 기능을 탐색하고 거기에서 리드를 얻을 수도 있습니다.다음은 csv http://jonidbendo.com/portfolio/csv-update-module/을 통해 제품을 업데이트하기 위해 개발 한 모듈입니다. 최종선은 직접 개발해야하지만 opencart의 PHP 코드 재사용을 활용하여 제작 시간을 크게 단축 할 수 있습니다. –

+1

무엇을 시도 했습니까? 이러한 유형의 작업을 위해서는 opencart에서 약간의 데이터 흐름을 이해해야합니다. – elembivos

답변

9

배열에있는 경우 케이크 조각입니다. admin/model/catalogue에 addproduct()를 사용할 수있는 opencart에 메소드가 있습니다. $ 데이터 배열의 색인을 읽고 그 형식으로 배열을 가져 오십시오. 예를 들어,이 방법에서는 $ data [ 'model'], $ data [ 'image'] 등을 볼 수 있습니다. 이렇게하면 admin/controller/module/script.php에서 다음과 같이 새로운 컨트롤러 파일을 만들 수 있다고 가정합니다. 다음과 같은 코드가 있습니다.

<?php 
class ControllerCatalogProduct extends Controller { 
    public function index() { 
     $products = array(...); //your products here. Eg $products[0] has all the data for the first product 
     $this->load->model('catalog/product'); 
     foreach ($products as $data) { 
      $this->model_catalog_product->addProduct($data); 
     } 
    } 
} 
?> 

간단합니다. 그런 다음 이것을 호출하십시오 http://yoursite/admin/index.php?route=module/script

+0

3 번 줄의 주석은 $ products [1]이 아닌 "예 : $ products [0]이 첫 번째 제품의 모든 데이터를가집니다" – Andy

2

다음과 같이 연관 배열을 생성 한 다음 관리 섹션에 컨트롤러를 작성하여 처리 할 수 ​​있습니다. 이 배열에서는 대시 보드에 두 가지 언어가 설치되어있는 경우 다른 언어의 각 내용을 반복해야한다는 점에 유의해야합니다. 나는 아래에서 내 옆에 설치된 두 언어의 예를 가지고 당신은 당신의 배열이 구조를 따를 수 :

Array (
    [product_description] => Array 
     (
      [1] => Array 
       (
        [name] => "product name in first language" 
        [meta_description] => "meta description for first" language 
        [meta_keyword] => "meta keywords in first language" 
        [description] => "product description in first" language 
        [tag] => "product tags in first language" 
       ) 

      [2] => Array 
       (
        [name] => "first product in second language" 
        [meta_description] => "meta description in second language" 
        [meta_keyword] => "meta tags in second language" 
        [description] => "product description in second language" 

        [tag] => "product tags in second language" 
       ) 
      .... 
     ) 

    [model] => 
    [sku] => 
    [upc] => 
    [ean] => 
    [jan] => 
    [isbn] => 
    [mpn] => 
    [location] => 
    [price] => 2300000 
    [tax_class_id] => 9 
    [quantity] => 1 
    [minimum] => 1 
    [subtract] => 1 
    [stock_status_id] => 5 
    [shipping] => 1 
    [keyword] => 
    [image] => data/demo/htc_touch_hd_3.jpg 
    [date_available] => 1394-2-23 
    [length] => 40 
    [width] => 30 
    [height] => 20 
    [length_class_id] => 2 
    [weight] => 23000 
    [weight_class_id] => 1 
    [status] => 1 
    [sort_order] => 1 
    [manufacturer] => 
    [manufacturer_id] => 0 
    [category] => 
    [filter] => 
    [product_store] => Array 
     (
      [0] => 0 
     ) 

    [download] => 
    [related] => 
    [product_attribute] => Array 
     (
      [0] => Array 
       (
        [name] => attribute 1 
        [attribute_id] => 
        [product_attribute_description] => Array 
         (
          [1] => Array 
           (
            [text] => "first language content" 
           ) 

          [2] => Array 
           (
            [text] => "second language content"         ) 

         ) 

       ) 

     ) 

    [option] => 
    [points] => 
    [product_reward] => Array 
     (
      [1] => Array 
       (
        [points] => 
       ) 

     ) 

    [product_layout] => Array 
     (
      [0] => Array 
       (
        [layout_id] => 
       ) 

     ) 

) 

은 관리 측면에서 컨트롤러를 처리하기 위해, 나는 간단한 방법은 니콜이 마지막 대답에 말을 생각합니다.

0

당신은 제품 정보를 삽입하기 위해 5 개 테이블을 관리해야합니다.

  1. oc_product_description
  2. oc_product_to_category oqc_product
  3. oc_product_to_store

oc_product_to_layout 위에서 솔루션도 괜찮했다.

네, 제품을 추가하거나 위 표의 Excel에서 직접 가져 오기 위해 PHP 스크립트를 직접 작성할 수 있습니다.

좋은 하루, Hiren이

관련 문제