Articles Menu
Headlines

Article Search

Search
Latest News
Automatically hide out of stock products in opencart 1.5.6
For out of stock products you can use stock statuses to inform customer that you had that product in stock but you dont anymore, howev... read more
Change the lenght of the product description in opencart listing
I have noticed a lot of people enquiring about this so Ill post  an easy and short solution to it. Just for clarificat... read more
Font Size and Font color missing in opencart 1.5.5 html editor
If you updated your opencart store to latest version 1.5.5 or 1.5.5.1 you might have noticed that in the admin Html Editor (for produc... read more
Adefault2 opencart free template
There is a template design competition going on in the opencart forum. I also created a theme for this competition and subm... read more
Headlines

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

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.


7 Comments To "How to add a view product link in opencart admin product list"
Jorge Augusto - 22/12/2013

Great post. Thanks for this code
dragoncorp - 31/10/2013

Thanks a lot, very useful code!!!!!!
@iSaulius - 24/08/2013

A lot Thanks !!!!!!!!!!!!!!!!
Erman - 18/03/2013

Great post. Thank you Flo. You saved my time..
David - 04/11/2012

Hello Flo, how can update code for products, which are not allowed to show on the shop, but you want to preview anyway? For example new products in preparation ... When you click on the link View in Main store and product is not allowed to show, you get the info about not found the product. David
Flo - 12/04/2012

You are right. Sorry, i will update the post.
Carlos Alberto - 12/04/2012

Now edit the file admin/view/template/catalog/product_form.tpl and find the code: <?php foreach ($product['action'] as $action) { ?> [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ] <?php } ?> This not in product_form.tpl, is in product_list.tpl

Write a comment

Your Name:


Your Comment: Note: HTML is not translated!

Enter the code in the box below:



Opencart templates © 2014