Articles Menu

Article Search

Search

Latest Articles
Since opencart 2.0.1 each time you create a module instance fom the main module , this gets added to the modules list. If you create a lot of modules you will have a very long modules list and will.. Read More
In opencart 2.x by default you have the option to add new fields in the customer registration form that will display in the account  registration page and on the checkout registration page (ev.. Read More
In this article I am reffering to the module system present in opencart 2.0.1.0 and up. Initially opencart 2.0 came with a changed module system, where you added module instances on the module .. Read More
There are lots of extensions on the opencart extension directory to bulk modify product prices. However if you only have to do this once in a while or you are looking for a quick free way to do thi.. Read More
All Articles

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.

Posted by Flo

7 Comments To "How to add a view product link in opencart admin product list"

Jorge Augusto On 22 Dec 2013
Great post. Thanks for this code Reply to this comment
dragoncorp On 31 Oct 2013
Thanks a lot, very useful code!!!!!! Reply to this comment
@iSaulius On 24 Aug 2013
A lot Thanks !!!!!!!!!!!!!!!! Reply to this comment
Erman On 18 Mar 2013
Great post. Thank you Flo. You saved my time.. Reply to this comment
David On 04 Nov 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 Reply to this comment
Flo On 12 Apr 2012
You are right. Sorry, i will update the post. Reply to this comment
Carlos Alberto On 12 Apr 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 Reply to this comment

Write a comment

Your Name:


Enter the code in the box below:

Your Comment:
Note: HTML is not translated!
Opencart templates © 2014