A
A
animr2017-08-28 19:32:19
opencart
animr, 2017-08-28 19:32:19

How to display the result of a function in a tpl (MVC) template?

Good people, tell me how to display the result of the function from the controller in the opencart tpl template:
Model:

public function getColorProduct($sku) {		
    $sql = "SELECT * FROM " . DB_PREFIX . "product GROUP BY sku = '{$sku}'";				
        
    $ColorProduct = array();
    $query = $this->db->query($sql);
    foreach ($query->rows as $result) {
      $ColorProduct[$result['product_id']] = $this->getProduct($result['product_id']);
    }
    return $ColorProduct;		
  }

View: throws an error here Notice: Undefined variable: Color_Sku in .../product/preview/horizontal.tpl on line 78
/*вот 78 строка*/ <?php if ($Color_Sku ) { ?> 
    <?Php foreach ($Color_Sku as $ColorSku) { ?>			
       <div class="color_div_sku_id">	
         <?Php echo $ColorSku['sku']; ?>	
       </div>			
    <?Php } ?> 
 <?Php } else { ?> 
       <div class="color_div_sku_id">
        <p>No!</p>
       </div>
<?Php } ?>

Controller:
$Color_Sku = $this->model_catalog_product->getColorProduct($data['sku']);		
var_dump($Color_Sku); //Массив заполнен

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
zoozag, 2017-08-30
@animr

Usually data from controller to view is passed via $this->data in Opencart 1.5 and $data in Opencart > 2.0
1.5
2.0

$data['Color_Sku'] = $this->model_catalog_product->getColorProduct($data['sku']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question