Post by crunchor » Tue Jul 30, 2013 10:47 am

I have no idea why this is not in the default opencart. This is like a must have stuff for a store.
heizo wrote:So I searched and did not find any resources on this, so I will type one up.

You will need MySql Knowledge and some php knowledge

Step 1.
First thing first, add your new fields to the product table in the database - this should be the easy part.

Step 2.
Open up product.php in admin/controller/catalog, you will want to copy and paste this piece of code. inside the getForm functions, (around line 707)

Code: Select all

if (isset($this->request->post['Table Name'])) {
      		$this->data['Table Name'] = $this->request->post['Table Name'];
    	} elseif (isset($product_info)) {
			$this->data['Table Name'] = $product_info['Table Name'];
		} else {
      		$this->data['Table Name'] = '';
    	}
also you will want to add the language variables like so (around line 521)

Code: Select all

$this->data['entry_table name'] = $this->language->get('entry_table name');
I kept my post names the same as my table names so as not to confuse myself, I would suggest doing the same.
For every field you want, copy and paste that code.

Step 3.
Open up the product_form.tpl file locate admin/view/template/catalog/.
This is pretty easy, just find a spot in the table and plug in your form fields. Look for the tab makers to tell what page you are adding to.

Code: Select all

<div id="tab-data">
This would be the data tab, you can figure out the names of the other ones.

I will give a couple of examples, here is a drop down

Code: Select all

<tr>
              <td><?php echo $entry_Table Name; ?></td>
              <td><select name="Table Name">
                  <?php foreach ($Table Names as $Table Name) { ?> // This is just looping over an array I built in the previouse page (step 2) and now loops here
                  <?php if ($Table Name['Table Name_id'] == $Table Name) { ?>
                  <option value="<?php echo $Table Name['Table Name_id']; ?>" selected="selected"><?php echo $Table Name['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $Table Name['Table Name_id']; ?>"><?php echo $Table Name['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select></td>
            </tr>
And here is just a regular input box:

Code: Select all

            <tr>
              <td><?php echo $entry_Table name; ?></td>
              <td><input type="text" name="Table name" value="<?php echo $Table name; ?>" /></td>
              </td>
            </tr>
Step 4.
Now open up the product.php in admin/language/english/catalog/

Add an entry

Code: Select all

$_['entry_Table Name']              = 'Descripton of field:';
Step 5.
Here is the tricky part, you will have to edit 2 queries in admin/model/catalog/product.php.

You want to edit in 2 places:

Code: Select all

public function addProduct($data) {
		$this->db->query("INSERT INTO " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', artist = '" . $this->db->escape($data['artist']) . "', bioLink = '" . $this->db->escape($data['bioLink']) . "', relatedCategory = '" . $this->db->escape($data['relatedCategory']) . "', upc = '" . $this->db->escape($data['upc']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_added = NOW()");

and here:

Code: Select all

public function editProduct($product_id, $data) {
		$this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', sku = '" . $this->db->escape($data['sku']) . "', sku = '" . $this->db->escape($data['sku']) . "', artist = '" . $this->db->escape($data['artist']) . "', bioLink = '" . $this->db->escape($data['bioLink']) . "', relatedCategory = '" . $this->db->escape($data['relatedCategory']) . "', upc = '" . $this->db->escape($data['upc']) . "', location = '" . $this->db->escape($data['location']) . "', quantity = '" . (int)$data['quantity'] . "', minimum = '" . (int)$data['minimum'] . "', subtract = '" . (int)$data['subtract'] . "', stock_status_id = '" . (int)$data['stock_status_id'] . "', date_available = '" . $this->db->escape($data['date_available']) . "', manufacturer_id = '" . (int)$data['manufacturer_id'] . "', shipping = '" . (int)$data['shipping'] . "', price = '" . (float)$data['price'] . "', points = '" . (int)$data['points'] . "', weight = '" . (float)$data['weight'] . "', weight_class_id = '" . (int)$data['weight_class_id'] . "', length = '" . (float)$data['length'] . "', width = '" . (float)$data['width'] . "', height = '" . (float)$data['height'] . "', length_class_id = '" . (int)$data['length_class_id'] . "', status = '" . (int)$data['status'] . "', tax_class_id = '" . (int)$data['tax_class_id'] . "', sort_order = '" . (int)$data['sort_order'] . "', date_modified = NOW() WHERE product_id = '" . (int)$product_id . "'");

Now that the admin side is done, we have to get this information on the other side... the user side.

Step 1.
Open up product.php in catalog/controller/product.

Add your language lines like so (around line 139)

Code: Select all

$this->data['entry_table name'] = $this->language->get('entry_table name');
Next add in your variable names containing the data (line 186ish)

Code: Select all

$this->data['table name'] = $product_info['table name'];
Step 2.
Open Up product.php in catalog/language/english/product/

Add your new names

Code: Select all

$_['text_table name']       = 'table name';

Step 3.

Open product.php in catalog/model/catalog/

Update the getProduct function, the mysql statement on line 14. Your prefix for your table names will be p.table name

Then add your entries to the array on line 18

Code: Select all

'table name'       => $query->row['table name'],
Step 4.
Add your fields to the product page in your template.

Finished :)

Cheers

Active Member

Posts

Joined
Wed Jun 05, 2013 10:29 am

Post by sims11tz » Tue Sep 03, 2013 12:33 pm

This kicks ass, thanks!!!!!!!!!!!!!!!!!!!!!!!!!

I also figured out how to make your new property a ckeditor wysiwyg editor field

in product_form.tpl

CKEDITOR.replace('THE ID OF YOUR CUSTOM FIELD', {
filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>'
});

Newbie

Posts

Joined
Wed Sep 12, 2012 12:08 pm

Post by Kakur007 » Sun Nov 24, 2013 11:52 pm

Hello,

I have tried tutorial but no luck in OC 1.5.6. Looking for help to fix it because its urgent. I have modified everything like in tutorial but not showing up custom field.

Code: Select all

PHP Notice:  Undefined index: warranty in /www/apache/domains/www.digitaltrade.eu/htdocs/vqmod/vqcache/vq2-catalog_controller_product_product.php on line 277
That's only error in log. Looking really help with this. Appreciated!

Regards,
Kaur

GoGoNano is passionate about creating eco-friendly bio cleaners and waterproofing sprays that people feel safe to use within their home and around their family.
https://www.gogonano.com


New member

Posts

Joined
Sun Nov 17, 2013 8:44 pm


Post by billynoah » Tue Nov 26, 2013 7:32 am

post line 277 of that file and maybe someone can help.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by Kakur007 » Tue Nov 26, 2013 5:49 pm

Code: Select all

$this->data['warranty'] = $product_info['warranty'];
I have made warranty field to DB and everything else as showed in tutorial. Client side not showing up new field for warranty. I'm thinking that I added something in wrong place, because not using default theme. But it didn't seem wrong places at all. Any help appreciated need to get it working as fast as possible.

Regards,
Kaur

GoGoNano is passionate about creating eco-friendly bio cleaners and waterproofing sprays that people feel safe to use within their home and around their family.
https://www.gogonano.com


New member

Posts

Joined
Sun Nov 17, 2013 8:44 pm


Post by billynoah » Tue Nov 26, 2013 10:24 pm

Yeah, tough to say without seeing your database and model files. The mistake is likely somewhere in there.

Make sure the database fields exist and make sure the model file contains the line:

'warranty' => $query->row['warranty'],

in the proper place.

If it's still not working pm me and I can try to help.

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm

Post by megaz » Mon Jan 27, 2014 7:39 am

Thankssss Jimmyyyy :)
i want to ask u a question please ...

can i make this field "size" is a drop down menu and fill it from another admin page ??

to be like the Filter Module (Autocomplete control) ...

THANKS :)

Newbie

Posts

Joined
Sun Jan 26, 2014 5:57 am

Post by thakursunny1501 » Mon May 19, 2014 10:24 pm

Hello friend,

Please give me a favour,,

I want to enter an certificate image field in product table . How can i achieved it in opencart


Posts

Joined
Mon May 19, 2014 10:20 pm

Post by thakursunny1501 » Fri May 23, 2014 5:05 pm

I have add the custom field in opencart product table,,,,,,,,,,, but when i m going to edit a product in edit form then custom field shows nothing,,,,,,how could i show value in edit form,,,,,,,,,,,, the value are present in database but it does not show in edit form

please gve me the solution if u no.....
thanks in advance for ur help


Posts

Joined
Mon May 19, 2014 10:20 pm

Post by Webmart » Sun Jun 01, 2014 10:49 pm

I'm need to add new custom field using a drop down menu:

Code: Select all

<tr>
              <td><?php echo $entry_Table Name; ?></td>
              <td><select name="Table Name">
                  <?php foreach ($Table Names as $Table Name) { ?> // This is just looping over an array I built in the previouse page (step 2) and now loops here
                  <?php if ($Table Name['Table Name_id'] == $Table Name) { ?>
                  <option value="<?php echo $Table Name['Table Name_id']; ?>" selected="selected"><?php echo $Table Name['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $Table Name['Table Name_id']; ?>"><?php echo $Table Name['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select></td>
            </tr>


You example is clear but of course menu is white, how to add options? (something like, IT,EN,DE,JP etc)

Newbie

Posts

Joined
Thu May 16, 2013 10:37 pm

Post by KaBing » Tue Aug 19, 2014 11:15 pm

Thax fot the tutorial. I think it works on 1.5.6 version. But im getting eror:
"Notice: Undefined variable: text_position in .../catalog/view/theme/..."
My field called "position" could enibody please help me understand where did i lost this variable.

Newbie

Posts

Joined
Tue Aug 19, 2014 11:08 pm

Post by KaBing » Tue Aug 19, 2014 11:24 pm

Great tutorial, thx, i think it works even on 1.5.6 version, but im getting eror:
"Notice: Undefined variable: text_position in
.../catalog/view/theme/hed20/template/product/product.tpl"

Please someone help me define this variable?

Newbie

Posts

Joined
Tue Aug 19, 2014 11:08 pm

Post by salman0405 » Wed Nov 19, 2014 9:52 pm

i uploaded the files as per the instruction.
problem : admin - product - "size field" when i add values it does not save.
what am i doing wrong?
yes i did add the value in the database

Newbie

Posts

Joined
Wed Nov 19, 2014 8:22 pm
Who is online

Users browsing this forum: No registered users and 6 guests