For example...
The Current way
1. The controller calls the model function for getProductsByCategoryId()
2. The model function does a select * for all products in that category and returns ALL DATA to the controller
3. The controller then makes a SUBSET of what we assumed to be "relevant" parts of that data.
4. The controller makes that smaller subset available to the view.
Code: Select all
$results = $this->model_catalog_product->getProductsByCategoryId($category_id);
$this->data['products'][] = array(
'name' => $result['name'],
'model' => $result['model'],
'sku' => $result['sku'],
'href' => HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id']),
);
Instead we will try
1. The controller calls the model function for getProductsByCategoryId()
2. The model function does a select * for all products in that category and returns ALL DATA to the controller
3. The controller passes that full array of ALL DATA to the view.
Then you will be able to simply echo the name of the field:
Code: Select all
$this->data['products'] = $this->model_catalog_product->getProductsByCategoryId($category_id);
<?php echo $products[$j]['location']; ?>
<?php echo $products[$j]['price']; ?>
<?php echo $products[$j]['weight']; ?>
<?php echo $products[$j]['any_field']; ?>
etc
Even new custom db fields will be available automatically with no controller changes.
This change would be made in all places that display product info:
category, search, manufacturer, modules, homepage, etc
This will cut down on some code and the lack of subset array creation might even improve performance slightly
This is related to my earlier discussions on this topic
http://forum.opencart.com/viewtopic.php ... ata#p53453