2016-07-07 2 views
0

그래서 Opencart 1.5.6을 가지고 있고 최신 제품 모듈에 표시되지 않도록 한 범주를 숨길 필요가 있습니다 ... PHP를 수정하여 제 3 자 모듈을 사용하지 못하게 할 수 있습니까?최신 제품 모듈 OpenCart에서 일부 카테고리를 숨기는 방법?

<?php 
class ControllerModuleLatest extends Controller { 
    protected function index($setting) { 
     $this->language->load('module/latest'); 

     $this->data['heading_title'] = $this->language->get('heading_title'); 

     $this->data['button_cart'] = $this->language->get('button_cart'); 

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

     $this->load->model('tool/image'); 

     $this->data['products'] = array(); 

     $data = array(
      'sort' => 'p.date_added', 
      'order' => 'DESC', 
      'start' => 0, 
      'limit' => $setting['limit'] 
     ); 

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

     foreach ($results as $result) { 
      if ($result['image']) { 
       $image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']); 
      } else { 
       $image = false; 
      } 

      if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { 
       $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))); 
      } else { 
       $price = false; 
      } 

      if ((float)$result['special']) { 
       $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))); 
      } else { 
       $special = false; 
      } 

      if ($this->config->get('config_review_status')) { 
       $rating = $result['rating']; 
      } else { 
       $rating = false; 
      } 

      $this->data['products'][] = array(
       'product_id' => $result['product_id'], 
       'thumb'  => $image, 
       'name'  => $result['name'], 
       'price'  => $price, 
       'special' => $special, 
       'rating'  => $rating, 
       'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']), 
       'href'  => $this->url->link('product/product', 'product_id=' . $result['product_id']), 
      ); 
     } 

     if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/latest.tpl')) { 
      $this->template = $this->config->get('config_template') . '/template/module/latest.tpl'; 
     } else { 
      $this->template = 'default/template/module/latest.tpl'; 
     } 

     $this->render(); 
    } 
} 
?> 

답변

0

먼저 받아야합니다 제품 카테고리 : : 나는 그래서 여기 어딘가에 catalog\controller\module\latest.php의 이해

내 코드 제품이없는 경우

$get_categories = $this->model_catalog_product->getCategories($result['product_id']); 

그런 in_array 기능 확인 특정 카테고리, 예를 들어 여기에 24가 카테고리의 ID입니다.

if(!in_array(24, $categories)) 

그래서 파일은 다음과 같습니다

<?php 
    class ControllerModuleLatest extends Controller { 
     protected function index($setting) { 
      $this->language->load('module/latest'); 

      $this->data['heading_title'] = $this->language->get('heading_title'); 

      $this->data['button_cart'] = $this->language->get('button_cart'); 

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

      $this->load->model('tool/image'); 

      $this->data['products'] = array(); 

      $data = array(
       'sort' => 'p.date_added', 
       'order' => 'DESC', 
       'start' => 0, 
       'limit' => $setting['limit'] 
      ); 

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

      foreach ($results as $result) { 
       if ($result['image']) { 
        $image = $this->model_tool_image->resize($result['image'], $setting['image_width'], $setting['image_height']); 
       } else { 
        $image = false; 
       } 

       if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) { 
        $price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax'))); 
       } else { 
        $price = false; 
       } 

       if ((float)$result['special']) { 
        $special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax'))); 
       } else { 
        $special = false; 
       } 

       if ($this->config->get('config_review_status')) { 
        $rating = $result['rating']; 
       } else { 
        $rating = false; 
       } 

       $get_categories = $this->model_catalog_product->getCategories($result['product_id']); 
       $categories = array(); 
       foreach($get_categories as $category){ 
        $categories[] = $category['category_id']; 
       } 

       if(!in_array(24, $categories)){ 
        $this->data['products'][] = array(
         'product_id' => $result['product_id'], 
         'thumb'  => $image, 
         'name'  => $result['name'], 
         'price'  => $price, 
         'special' => $special, 
         'rating'  => $rating, 
         'reviews' => sprintf($this->language->get('text_reviews'), (int)$result['reviews']), 
         'href'  => $this->url->link('product/product', 'product_id=' . $result['product_id']), 
        ); 
       } 
      } 

      if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/latest.tpl')) { 
       $this->template = $this->config->get('config_template') . '/template/module/latest.tpl'; 
      } else { 
       $this->template = 'default/template/module/latest.tpl'; 
      } 

      $this->render(); 
     } 
    } 
    ?> 
+0

난 그냥 하나를 추가하는 시도에 의해 범주의 다음 몇 : (있는 경우와 in_array (83 | 88 | 94 | 92 | 95 | 90 | 91 | 86 | 78 |! 84 | 89 | 93 | 87 | 85, 그러나이 모듈에서 그 범주를 여전히 볼 수있는 결과는 없습니다! :(어떤 생각? –

+0

고마워요. 하나의 카테고리를 숨길 때만 작동합니다. 어떻게 그들을 숨길 수 있습니까? 나는 쉼표로 시도했습니다. 또한 83 | 88 | 94 결과가 없습니다 : ( –

+0

) (12, $ 카테고리) &&! in_array (18, $ 카테고리)) {' – DigitCart

관련 문제