OpenCart Ecommerce Content Management System - Displaying the product name in the admin screen

I started using the Open Cart 1.5 ecommerce content management system and think it is one of the best ecommerce systems out there. It compares well against Zen Cart and OS Commerce and as a programmer, I am changing things to suit my needs and the ecommerce needs of my clients.

Here's the problem (See below for the solution)

Today, I came across a problem that was silently bugging me for the past week and that is when I am editing a product in the admin system, I sometimes forget what product I am editing. With over 500 products, you can easily get lost. The problem is that Open Cart does not show you the product name while you are editing in one of its many tabs including "Data", "Link", and "Design". It just says "Product". I would like it show the name of the product that I am editing wherever I am. I went to work to make that happen and solve this problem.

You can have this code, but you need to edit 2 files (a controller and a view) in Open Cart's MVC system (Model Viewer Controller) framework. You can also edit the language file, but it is optional.

  1. The controller file: \admin\controller\catalog\product.php
  2. The language file: \admin\language\english\catalog\product.php
  3. Your view file: admin\view\template\catalog\product_form.tpl

Open these three files and I will give you the code to add:


The resolved OpenCart product editing admin screen

Editing the Controller

		$this->data['product_title'] = $this->language->get('product_title'); // Initiate the product_title variable for the view when entering a new product.
		if(isset($this->request->get['product_id']))
		{
			$this->data['product_title'] = $this->data['product_description'][1]['name']; // Change the product_title variable for the view if we are editing an existing product.
		}

This is pretty simple and it only takes 4 lines:

In the first line, we set up a new view variable through the MVC system called product_title.

$this->data['product_title'] is the line that the view will use to show your product title. If you want, you can get it from the language file or simply hard code it.

To use the language file (which is optional), add $this->data['product_title'] = $this->language->get('product_title');

To hard code it without the language file, you simply add

$this->data['product_title'] = "New Product";

That is it for the controller file. You need to add this code to the line of code above "if (isset($this->request->post['model'])) {"

Adding the code to your view

<?php echo $heading_title . ": $product_title"; ?>

Editing the view is quick and only takes one line.

Look for the line of code with <?php echo $heading_title towards the top. You simply add your $product_title variable that you set up in the controller.

That is it! Your product title will now display.

Optionally adding the New Product Label to your Language file

$_['product_title'] = "New Product";

As I mentioned before, this is optional. If you like keeping your controller clean, you can add the New Product label to your language files.

This will be used when you insert a new product.

That is the whole thing. A total of 6 lines in 3 files solves this issue and it works well. No models are necessary here.

More by this Author


Comments 4 comments

psychicdog.net profile image

psychicdog.net 5 years ago

Cheers HWI. It is great to have another php person here on hubpages who thinks along these lines! This probably reads as trivial to others, but like you HWI, I get obsessive about these little details as these can be highly annoying for a client who you have set this up for.


hotwebideas profile image

hotwebideas 5 years ago from New York Author

Hey Psychic Dog, I am glad you like the way I think and am glad to know another programmer thinks the same way I do.

Wait till you see the Open Cart extension that I just developed called the "Super Message Kit". I hope it will blow people away and I am releasing it this weekend.

I will contact you when it is up.


ijmilton 4 years ago

Thank you for the code, just what I was looking for.


hotwebideas profile image

hotwebideas 4 years ago from New York Author

@ijmilton, no problem. Glad it works for you.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working