2014-03-13 3 views
1

내가하려는 것은 Opencart (admin 패널) 내의 product_list.tpl 파일을 편집하여 열에 제품 속성을 표시하는 것입니다.Opencart 제품 속성을 product_list.tpl에 추가하십시오.

여기는 달성하려는 Im의 이전 및 이후 스크린 샷입니다. (포토샵으로 심하게 수행)

enter image description here

이제 메신저 PHP와 좀 좋아. 나는 테이블에 배치하기위한 정확한 코드가 필요하지 않습니다.

현재이 목록을 작성하는 방법은 다음과 같습니다.

<?php foreach ($products as $product) { ?> 
      <tr> 
       <td style="text-align: center;"><?php if ($product['selected']) { ?> 
       <input type="checkbox" name="selected[]" value="<?php echo $product['product_id']; ?>" checked="checked" /> 
       <?php } else { ?> 
       <input type="checkbox" name="selected[]" value="<?php echo $product['product_id']; ?>" /> 
       <?php } ?></td> 
       <td class="center"><img src="<?php echo $product['image']; ?>" alt="<?php echo $product['name']; ?>" /></td> 
       <td class="left"><?php echo $product['name']; ?></td> 
       <td class="left"><?php echo $product['model']; ?></td> 
       <td class="left"><?php if ($product['special']) { ?> 
       <span style="text-decoration: line-through;"><?php echo $product['price']; ?></span><br/> 
       <span style="color: #b00;"><?php echo $product['special']; ?></span> 
       <?php } else { ?> 
       <?php echo substr($product['price'], 0, -2); ?> (ex. VAT) 
       <?php } ?></td> 
       <td class="right"><?php if ($product['quantity'] <= 0) { ?> 
       <span style="color: #FF0000;"><?php echo $product['quantity']; ?></span> 
       <?php } elseif ($product['quantity'] <= 5) { ?> 
       <span style="color: #FFA500;"><?php echo $product['quantity']; ?></span> 
       <?php } else { ?> 
       <span style="color: #008000;"><?php echo $product['quantity']; ?></span> 
       <?php } ?></td> 
       <td class="left"><?php echo $product['status']; ?></td> 
       <td class="right"><?php foreach ($product['action'] as $action) { ?> 
       <a class="editbutton" href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> 
       <?php } ?></td> 
      </tr> 
      <?php } ?> 

이것은 목록에서 foreach 제품을 수행하는 루프입니다. 지금 제품을 편집에서, 당신은 속성을 볼 수있는 속성을 얻을 수있는 핸들은

<?php echo $product_attribute['name']; ?> 

하지만 내가 Product_list.tpl 파일 내에이를 넣어 경우, 나는 PHP는 오류가 메신저 내가 어떻게 든해야 추측 얻을 product_list.tpl에 데이터를 제공하는 컨트롤러 파일을 수정하고 제품 속성을 가져 오는 함수를 추가하십시오.하지만이를 수행하는 방법은 확실하지 않습니다.

아무도 도와 줄 수 있습니까?

+0

'catalog/product.php' 컨트롤러의 1041-1063 행을 살펴보고 같은 코드의'getList()'메소드에 비슷한 코드를 추가하십시오. 그 주위를 놀고 특정 질문을하십시오. –

답변

0

네, 제품 속성을 컨트롤러 (/admin/controller/catalog/product.php)에 가져 와서보기에 사용할 수 있도록해야합니다.

약간의 복잡성은 제품에 여러 속성이있을 수 있으므로 배열로 가져온 다음보기에서 배열을 반복해야 할 필요가 있다는 것입니다.

제품 모델 (admin/model/catalog/product.php)에는 getProductAttributes ($ product_id) 메소드가 있습니다. 컨트롤러에서 이것을 호출하면 제품 속성을 가져올 수 있어야합니다.

NB. 이 컨트롤러는 목록에있는 모든 제품을 가져 와서 모든 제품 목록을 반복하는 루프 내에서 제품 속성을 가져와야합니다.이 버전에서는 다음과 같이이 루프가 350 행에서 시작됩니다.

$results = $this->model_catalog_product->getProducts($data); 

foreach ($results as $result) { 
당신이 모델에 전화를 추가하는 경우이에 속성을 얻을 수

$this->data['products'][] = array(
       'product_id' => $result['product_id'], 
       'name'  => $result['name'], 
       'model'  => $result['model'], 
       'price'  => $result['price'], 
       'special' => $special, 
       'image'  => $image, 
       'quantity' => $result['quantity'], 
       'status'  => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), 
       'selected' => isset($this->request->post['selected']) && in_array($result['product_id'], $this->request->post['selected']), 
       'action'  => $action 
      ); 

:

당신이 (라인 375의 주위에) 각 제품에 대한 모든 데이터를로드하는 코드를 볼이 루프 내부

$this->data['products'][] = array(
       'product_id' => $result['product_id'], 
       'name'  => $result['name'], 
       'model'  => $result['model'], 
       'price'  => $result['price'], 
       'special' => $special, 
       'image'  => $image, 
       'quantity' => $result['quantity'], 
       'status'  => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), 
       'selected' => isset($this->request->post['selected']) && in_array($result['product_id'], $this->request->post['selected']), 
       'action'  => $action, 
       'attributes' => $this->model_catalog_product->getProductAttributes($result['product_id']); 

      ); 

그런 다음 $ product [ 'attributes'] 배열을 사용하여 뷰에서 반복 할 수 있습니다. 루프 내에서 각 제품을 반복합니다.

<?php 
    foreach ($products as $product) { 
     foreach ($product['attributes'] as $attribute) { 
      echo "$attribute<br>"; 
     } 
    } 
?> 

NB. 나는 이것을 테스트하지 않았기 때문에 복사 및 붙여 넣기가 작동하지 않을 수 있지만 올바른 방향으로 가야합니다.

+0

나는 당신이 말한 것을 시도해 보았고 그것을 테스트하기 위해 슈퍼 단순한 루프를 만들었습니다. '그러나 나는 단지 "Array"라는 단어를 계속 반복적으로 사용합니다. 각 속성과 관련하여 Foreach 루프를 수행해야한다고 추측합니다. 그러나이 작업을 수행하는 방법은 확실하지 않습니다 ... – Blackline

+0

예, 위의 편집 된 최종 코드 블록을 볼 수 있습니다. 또는 다음과 같이 할 수 있습니다. jx12345

+0

안녕하세요, 오랫동안 대답 없음 :) 나는 아직도 이것을 파악할 수 없습니다. 내 product.php 내에 \t '속성'=> $ this-> model_catalog_product-> getProductAttributes ($ result [ 'product_id']), 그리고 내 product_list.tpl에 "; }?> 하지만 여전히 "Array"가 반복해서 반복됩니다. – Blackline

관련 문제