Please help us to make AbanteCart Ideal Open Source Ecommerce Solution for everyone.

Support AbanteCart eCommerce

Author Topic: How can I add a new Text Area field to Products?  (Read 12307 times)

Offline jaysbar

  • Full Member
  • ***
  • Posts: 139
  • Karma: +13/-5
    • View Profile
How can I add a new Text Area field to Products?
« on: August 12, 2016, 01:36:26 AM »
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

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4367
  • Karma: +302/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: How can I add a new Text Area field to Products?
« Reply #1 on: August 12, 2016, 08:26:38 AM »
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

Offline jaysbar

  • Full Member
  • ***
  • Posts: 139
  • Karma: +13/-5
    • View Profile
Re: How can I add a new Text Area field to Products?
« Reply #2 on: August 12, 2016, 05:11:38 PM »
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!

Offline jaysbar

  • Full Member
  • ***
  • Posts: 139
  • Karma: +13/-5
    • View Profile
Re: How can I add a new Text Area field to Products?
« Reply #3 on: August 15, 2016, 04:29:54 PM »
Please can someone break this down for me so I can follow some easy steps?

Offline jaysbar

  • Full Member
  • ***
  • Posts: 139
  • Karma: +13/-5
    • View Profile
Re: How can I add a new Text Area field to Products?
« Reply #4 on: August 17, 2016, 05:11:09 PM »
$10 to Abantecart for any help with this!

Offline eCommerce Core

  • Administrator
  • Hero Member
  • *****
  • Posts: 1602
  • Karma: +93/-1
    • View Profile
Re: How can I add a new Text Area field to Products?
« Reply #5 on: August 21, 2016, 10:51:35 AM »
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
Code: [Select]
        $fields = array('product_category', ...


Add below code somewhere after line with $this->data['form']['fields']['data']['model'] :
Code: [Select]
        $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

Offline jaysbar

  • Full Member
  • ***
  • Posts: 139
  • Karma: +13/-5
    • View Profile
Re: How can I add a new Text Area field to Products?
« Reply #6 on: August 23, 2016, 02:05:05 PM »
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.

« Last Edit: August 23, 2016, 02:07:50 PM by jaysbar »

Offline jaysbar

  • Full Member
  • ***
  • Posts: 139
  • Karma: +13/-5
    • View Profile
Re: How can I add a new Text Area field to Products?
« Reply #7 on: September 01, 2016, 10:58:57 AM »
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

Offline jaysbar

  • Full Member
  • ***
  • Posts: 139
  • Karma: +13/-5
    • View Profile
Re: How can I add a new Text Area field to Products?
« Reply #8 on: September 05, 2016, 04:54:44 AM »
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

Offline jaysbar

  • Full Member
  • ***
  • Posts: 139
  • Karma: +13/-5
    • View Profile
Re: How can I add a new Text Area field to Products?
« Reply #9 on: September 14, 2016, 05:43:41 PM »
I would be greatful for some help please.

 

Powered by SMFPacks Social Login Mod