Post by AmericanFizz » Thu Apr 16, 2015 9:19 pm

Hey guys,

Been working on this today, and thought it might be useful for some of you.

This is for adding extra fields from your MySQL database to the admin section. You can then echo them accordingly within your product listing template.

This is a rough tutorial based on OpenCart and assumes a basic knowledge of PHP and MySQL. You should be able to make sense of what I have written by referring to the original OpenCart code.

This does not cover echo'ing the information on the product listing or adding the information to the database, as I would assume you already know how if you've come this far! :)

Step 1
Edit: /admin/controller/catalog/product.php

Find:

Code: Select all

$data['entry_name'] = $this->language->get('entry_name');
Add after:

Code: Select all

$data['entry_YOUR-ENTRY'] = $this->language->get('entry_YOUR-ENTRY');
Find:

Code: Select all

$data['help_keyword'] = $this->language->get('help_keyword');
Add after:

Code: Select all

$data['help_YOUR-ENTRY'] = $this->language->get('help_YOUR-ENTRY');
Find:

Code: Select all

$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
Add after:

Code: Select all

		
		if (isset($this->request->post['YOUR-ENTRY'])) {
			$data['YOUR-ENTRY'] = $this->request->post['YOUR-ENTRY'];
		} elseif (!empty($product_info)) {
			$data['YOUR-ENTRY'] = $product_info['YOUR-ENTRY'];
		} else {
			$data['YOUR-ENTRY'] = '';
		}
Step 2
Edit: /admin/language/english/catalog/product.php

Find:

Code: Select all

$_['entry_name']             = 'Product Name';
Add after:

Code: Select all

$_['entry_YOUR-ENTRY']             = 'Your Entry Name';
Find:

Code: Select all

$_['help_keyword']           = 'Do not use spaces, instead replace spaces with - and make sure the keyword is globally unique.';
Add after:

Code: Select all

$_['help_YOUR-ENTRY']           = 'Your help description';
Step 3
Edit: /admin/model/catalog/product.php

Find:

Code: Select all

 . "', sku = '" . $this->db->escape($data['sku'])
Add immediately after (same line, no spaces):

Code: Select all

 . "', YOUR-ENTRY = '" . $this->db->escape($data['YOUR-ENTRY'])
There are two of these on this page. Be sure to do both.

Step 4
Edit: /admin/view/template/catalog/product_form.tpl

You can either create your own tab, which is easy to figure out for yourself, or you can add to an existing tab.

Find:

Code: Select all

<div class="tab-pane"
Add after:

Code: Select all

<div class="form-group">
                <label class="col-sm-2 control-label" for="input-YOUR-ENTRY"><span data-toggle="tooltip" title="<?php echo $help_YOUR-ENTRY; ?>"><?php echo $entry_YOUR-ENTRY; ?></span></label>
                <div class="col-sm-10">
                  <input type="text" name="YOUR-ENTRY" value="<?php echo $YOUR-ENTRY; ?>" placeholder="<?php echo $entry_YOUR-ENTRY; ?>" id="input-YOUR-ENTRY" class="form-control" />
                </div>
              </div>
As long as you have added the columns to your MySQL database, this should all work just fine :)

New member

Posts

Joined
Fri Dec 13, 2013 9:56 pm
Who is online

Users browsing this forum: No registered users and 6 guests