Jump to content

Adding customm field in combination tab ?


dangee

Recommended Posts

Hi everyone,

 

I'm trying to add a custom field "Public Price" in the combinations tab but I can't figure out how to do it. This is what I did so far :

  • Create publicPrice column in ps_product_attribute
  • Add the field in combinations.tpl (override)
  • Modify Combination.php
    line 45 add
    public $publicPrice;


    line 79 add :

    'publicPrice' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 20),


  • modify AdminProductController.php
    line 771 add
    if (!isset($_POST['attribute_publicPrice'])) $_POST['attribute_publicPrice'] = 0;


    line 789 add

    $this->isProductFieldUpdated('attribute_publicPrice') ? Tools::getValue('attribute_publicPrice') : null,


    line 821 add

    Tools::getValue('attribute_publicPrice'),


    line 3447 add

    array_push($product_props,
      'price', 'publicPrice', 'wholesale_price', 'id_tax_rules_group', 'unit_price_ratio', 'on_sale',
      'unity', 'minimum_quantity', 'additional_shipping_cost',
      'available_now', 'available_later', 'available_date'
     );


    line 3709 add

    $comb_array[$combination['id_product_attribute']]['publicPrice'] = $combination['publicPrice'];


  • modify ProductController.php
    ligne 427 add
    $combinations[$row['id_product_attribute']]['publicPrice'] = (float)$row['publicPrice'];


After all that it's still not working and I don't know what else to do...I've already add a custom field to the product page, but combinations seems a bit different.

 

Any advice / help ??

 

THX.

 

ps : I'm using PS 1.5.4.

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Hey dangee, I follow your instruction above and finally figure out how to add a custom field in the combination tab & display it correctly :)

 

I strongly suggest you to turn on the dev mode

define('_PS_MODE_DEV_', true);

to get all potential errors.

 

1. If you enable shop => true in

'publicPrice' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 20),

I Think you needa create your desired column in ps_product_attribute_shop (not ps_product_attribute). In my case, I don't enable that option so I just create the column in ps_product_attribute.

 

2. You need to modify the updateAttribute() function (in product.php) by adding in 1 more parameter in order for PS to save your new custom field

 

3. In order to get your custom field displayed in the front end, you needa to modify getAttributesGroups() function (in product.php)

by selecting your custom field in the SQL query.

 

4. Similarly, In order to get your custom field displayed in the back office, you have to modify this function (in product.php)

public function getAttributeCombinationsById($id_product_attribute, $id_lang)

to get your custom field. That function is used inside ajaxProcessEditProductAttribute() function in the AdminProductsController.php

 

Now I've got it works. Thanks for your first tips anyways :)

 

If you've got any other questions, feel free to ask me.

Link to comment
Share on other sites

Hey dangee, I follow your instruction above and finally figure out how to add a custom field in the combination tab & display it correctly :)

 

I strongly suggest you to turn on the dev mode

define('_PS_MODE_DEV_', true);

to get all potential errors.

 

1. If you enable shop => true in

'publicPrice' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 20),

I Think you needa create your desired column in ps_product_attribute_shop (not ps_product_attribute). In my case, I don't enable that option so I just create the column in ps_product_attribute.

 

2. You need to modify the updateAttribute() function (in product.php) by adding in 1 more parameter in order for PS to save your new custom field

 

3. In order to get your custom field displayed in the front end, you needa to modify getAttributesGroups() function (in product.php)

by selecting your custom field in the SQL query.

 

4. Similarly, In order to get your custom field displayed in the back office, you have to modify this function (in product.php)

public function getAttributeCombinationsById($id_product_attribute, $id_lang)

to get your custom field. That function is used inside ajaxProcessEditProductAttribute() function in the AdminProductsController.php

 

Now I've got it works. Thanks for your first tips anyways :)

 

If you've got any other questions, feel free to ask me.

Hello. having in mind that you succeeded to make a change in the combination task, I am asking for your help to make a change in my site that sell tickets to concerts. I am using combinations to create separate tickets prices. Using the reference tab, I am showing the zones in which I sell tickets. I want a new area (to divide the reference tab) as radio buttons in order to use them as seats. for exemple- Price 1 refers to the Front area of a venue(mentioned in the Reference tab)- radio button seat 1, seat 2 and so on

Price 2 refers to the Back area of a venue(mentioned in the Reference tab)- radio button seat 9, seat 10 and so on

I hope that my requirements are understandable. Can you or anybody help with that?

Link to comment
Share on other sites

  • 3 weeks later...

Hey dangee, I follow your instruction above and finally figure out how to add a custom field in the combination tab & display it correctly :)

 

I strongly suggest you to turn on the dev mode

define('_PS_MODE_DEV_', true);

to get all potential errors.

 

1. If you enable shop => true in

'publicPrice' => array('type' => self::TYPE_FLOAT, 'shop' => true, 'validate' => 'isPrice', 'size' => 20),

I Think you needa create your desired column in ps_product_attribute_shop (not ps_product_attribute). In my case, I don't enable that option so I just create the column in ps_product_attribute.

 

2. You need to modify the updateAttribute() function (in product.php) by adding in 1 more parameter in order for PS to save your new custom field

 

3. In order to get your custom field displayed in the front end, you needa to modify getAttributesGroups() function (in product.php)

by selecting your custom field in the SQL query.

 

4. Similarly, In order to get your custom field displayed in the back office, you have to modify this function (in product.php)

public function getAttributeCombinationsById($id_product_attribute, $id_lang)

to get your custom field. That function is used inside ajaxProcessEditProductAttribute() function in the AdminProductsController.php

 

Now I've got it works. Thanks for your first tips anyways :)

 

If you've got any other questions, feel free to ask me.

 

 

Hi there

 

I am struggling with a similar issue here. Can you please help me out. 

 

I want to create a custom form with drop down list in product page and send the data to cart just as the product customization details are sent. I have created the form on the product page but I don't know the code that should be put to send the form data/details to the cart just as it is sent through the product customization tab.

 

 

Please can you help me?? I am a newbie and m lost. Please help. 

 

Thanks so much.

 

Mira

Link to comment
Share on other sites

Hey marcko, based on what you did, I'm sure you can modify the prestashop to achieve your requirements. Can you post your codes here so that we can know your progress & what goes wrong?

 

Hey mirapresta, can you try to follow marcko's instruction in the first post with some of my notice in the 3rd post?

It's probably easier if you post some of your codes here.

Link to comment
Share on other sites

  • 1 year later...

I have followed what you explained, the new field is correctly saved into the database but the value isn't populate in the new field in the edit combination form... I don't understand why, do you have any idea or do you need more information ?

<div class="form-group">
        <label class="control-label col-lg-3" for="attribute_number">
                {l s='Nombre d\'exemplaires'}
        </label>
        <div class="col-lg-3">
                <input maxlength="13" type="text" id="attribute_number" name="attribute_number" value="" />
        </div>
</div>

 

value is always empty ...

 

Thank you for your help !

Edited by Orpheo (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...

I have followed what you explained, the new field is correctly saved into the database but the value isn't populate in the new field in the edit combination form... I don't understand why, do you have any idea or do you need more information ?

<div class="form-group">
        <label class="control-label col-lg-3" for="attribute_number">
                {l s='Nombre d\'exemplaires'}
        </label>
        <div class="col-lg-3">
                <input maxlength="13" type="text" id="attribute_number" name="attribute_number" value="" />
        </div>
</div>

 

value is always empty ...

 

Thank you for your help !

 

Hello,

 

Same problem here. Value is stored into database, but when editing combinations, custom attribute field is not populated. Anyone can help please?

 

EDIT: There is one more file to edit, js/admin/products.js

 

It is answered here: https://www.prestashop.com/forums/topic/442471-adding-custom-fields-for-combinations-ps16/?do=findComment&comment=2062529

Edited by sucemaya (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...