How can I add a new Text Area field to Products?

Started by jaysbar, August 12, 2016, 01:36:26 AM

Previous topic - Next topic

jaysbar

Hi All,

I want to add a new field to the Products page (for every product) called Supplier. How can I do this? I do not want it as an Option because I need to add the Supplier name to every product. This field must not appear on my store front.

Any help would be appreciated!

Thanks

J

abantecart

Hello Jaysbar,

You can do this with simple extension hook or with core code edit (be aware of updates)

1. Create new field in the database
(if you use extension, you can add field creation to install.sql and delete into uninstall.sql)

For extension:
2. In main extension driver, hook into admin product controller for display and submit process.
Handle the value as needed.

3. For quick save you will need to add hook as well.

Remember to use dev tools to generate extension and save yourself time.
https://github.com/abantecart/developer_tools_extension


For core controllers:
1. Edit function _getForm in /admin/controller/pages/catalog/product.php to add your field

2. Edit model: /admin/model/catalog/product.php
Add your field in SQLs that are needed. Mainly in functions addProduct and updateProduct. Could be more

Use new field in storefront as you needed.

I think that is it.
Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

jaysbar

Hi

Thank you for the update. Do you mean that I have to do the following?

1. In this file
/admin/controller/pages/catalog/product.php

2. Add these lines:
$this->loadModel('catalog/supplier');
       $this->data['supplier'] = array(0 => $this->language->get('text_none') );
        $results = $this->model_catalog_supplier->getSuppliers();
        foreach( $results as $r ) {
            $this->data['suppliers'][ $r['supplier_id'] ] = $r['name'];
        }

3. And at the end of "$fields = array('product_category'," add this line
'supplier',

                      

It looks a bit difficult just for 1 text field!

jaysbar

Please can someone break this down for me so I can follow some easy steps?

jaysbar


eCommerce Core

AbanteCart is MVC and you need to update Model and controller to add new field.
It is pretty simple.
1. You add field in the product table. I assume this is already done.
2. Update model for product where field will be read and saved.
3. Update controller to pass HTML element with new field to view.

That is it for admin update. If you need to use (and I assume you do need) new field on storefront, you will need to update model and controller on storefront to get this data and display.

Below is the example, how you would this:

2. Locate /admin/model/catalog/product.php
Locate method
public function addProduct($data){

Add below line to SQL constructing:
supplier = '" . $this->db->escape($data['supplier']) . "',

3. Locate /admin/controller/pages/catalog/product.php
In function private _getForm add below code:

Add  supplier to below fields array
        $fields = array('product_category', ...


Add below code somewhere after line with $this->data['form']['fields']['data']['model'] :

        $this->data['form']['fields']['data']['supplier'] = $form->getFieldHtml(array(
'type' => 'textarea',
'name' => 'supplier',
'value' => $this->data['supplier'],
        'required' => false,
));


You are done.

FYI. To avoid programming to begin with you, can use product features that will add virtual field to products.
https://marketplace.abantecart.com/product-features-or-attributes?keyword=product&category_id=0
"If you're in the luckiest one per cent of humanity, you owe it to the rest of humanity to think about the other 99 per cent."
― Warren Buffett

jaysbar

#6
Hi

I implemented all of the suggested changes to both product.php pages. In SQL I also created the new field (see attached). But when I add a new product, I cannot see the new 'supplier' field.

I am baffled as to how other people are not using a Supplier field, most businesses would use it.


jaysbar

Hi

I'm still stuck with this and wonder if someone can help me to add a new field to the product page only to be seen by Admin. I want to add a field call Supplier.

Thanks

jaysbar

Friends

I'm still stuck with this and would really appreciate it is someone can give me some simpler instructions to follow so I can add a new field to the Products page just for Admin to view.

Thanks

jaysbar


Forum Rules Code of conduct
AbanteCart.com 2010 -