How to add a view product link in opencart admin product list

Posted by Flo on 25 Feb 2012

Sometimes after you insert or edit a product in opencart admin you would like to see the result in frontend. Currently to do that you would have to go to the opencart frontend and then navigate trough the path to that product.

The below trick will show you how to add a view product in store frontend  link in the opencart admin product listing. And in the case you use multistore , this will ad a view link for each store the product belongs to.

First edit the file admin/controller/catalog/product.php and find the line:

$this->data['delete'] = $this->url->link('catalog/product/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');

And below it add the code: 

$this->data['store'] = HTTP_CATALOG;
$this->data['stores'] = array();

$this->load->model('setting/store');

$results = $this->model_setting_store->getStores();

foreach ($results as $result) {
$this->data['stores'][] = array(
'name' => $result['name'],
'id' => $result['store_id'],
'href' => $result['url']
);
}

Now edit the file admin/view/template/catalog/product_list.tpl and find the code:

<?php foreach ($product['action'] as $action) { ?>
[ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
<?php } ?>

Below it add the code: 

<?php
$this->load->model('catalog/product');
$product_store = $this->model_catalog_product->getProductStores($product['product_id']);
?>
<?php if (in_array(0, $product_store)) { ?>
[<a onClick="window.open('<?php echo $store . 'index.php?route=product/product&product_id=' . $product['product_id']; ?>');">View in Main store</a>]<br />
<?php } ?>
<?php foreach ($stores as $storel) { ?>
<?php if (in_array($storel['id'], $product_store)) { ?>
[<a onClick="window.open('<?php echo $storel['href'] . 'index.php?route=product/product&product_id=' . $product['product_id']; ?>');">View in <?php echo $storel['name']; ?></a>]<br />
<?php } ?>
<?php } ?>

That is all.