[Skip to main content](#vessel-content)

#   Using the "field" class

##

- **[DomB22](/forum/user/82577-domb22 "View DomB22's Profile")**
- [![DomB22's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/82577-domb22 "View DomB22's Profile") Topic Author
- [ Offline](/forum/user/82577-domb22)

Less More

- Posts: 9
- Thank you received: 1
-
-

2 years 4 months ago -  2 years 4 months ago [\#361814](#361814) by [DomB22](/forum/user/82577-domb22 "View DomB22's Profile")  *[Using the "field" class](/forum/31-development/908338-using-the-field-class#361814 "-- HikaShop version -- : 5.1.0 -- Joomla version -- : 4.4.5  Hello, I'm a relative beginner with Hikashop but I've experience with Woocommerce. For a plugin development project I need to interact with the hikashop&#95;field table. More precisely I want to retrieve all the values of a singledropdown field based on its field&#95;realname and then update them. I understand that I must start with hikashop&#95;get('class.field'); but then I'm lost ; I've looked into the code of com&#95;hikashop/classes/field.php but without success (and because it extends hikashopClass maybe the answer is in the base class) Any pointer would be appreciated, thank you.")* was created by *[DomB22](/forum/user/82577-domb22 "View DomB22's Profile")*

-- HikaShop version -- : 5.1.0
-- Joomla version -- : 4.4.5

Hello,
I'm a relative beginner with Hikashop but I've experience with Woocommerce.
For a plugin development project I need to interact with the hikashop_field table. More precisely I want to retrieve all the values of a singledropdown field based on its field_realname and then update them.
I understand that I must start with hikashop_get('class.field'); but then I'm lost ; I've looked into the code of com_hikashop/classes/field.php but without success (and because it extends hikashopClass maybe the answer is in the base class)
Any pointer would be appreciated, thank you.

Last edit: 2 years 4 months ago by [DomB22](/forum/user/82577-domb22 "View DomB22's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwODMzOC11c2luZy10aGUtZmllbGQtY2xhc3M/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

2 years 4 months ago [\#361816](#361816) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Using the "field" class](/forum/31-development/908338-using-the-field-class#361816 "-- HikaShop version -- : 5.1.0 -- Joomla version -- : 4.4.5  Hello, I'm a relative beginner with Hikashop but I've experience with Woocommerce. For a plugin development project I need to interact with the hikashop&#95;field table. More precisely I want to retrieve all the values of a singledropdown field based on its field&#95;realname and then update them. I understand that I must start with hikashop&#95;get('class.field'); but then I'm lost ; I've looked into the code of com&#95;hikashop/classes/field.php but without success (and because it extends hikashopClass maybe the answer is in the base class) Any pointer would be appreciated, thank you.")*

Hi,

I suppose you'll want to do something like this: Code:

$class = hikashop_get('class.field'); $field = $class-&gt;get($field_column_name, $field_table); foreach($field-&gt;field_value as $value =&gt; $valueObject) { echo $valueObject-&gt;title; }

While this could allow you to, for example, run a script, to update the values of custom fields in the database, based on what you're trying to do, you might be able to use a lighter approach.
What you could do is to make an override of hikashopFieldClass ( [ www.hikashop.com/support/documentation/6...ntation.html#classes](https://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#classes) ) and in your extended override class, override the loadValues method in order to change the values. This way you could change the values of the field on the fly when the field is being loaded.
This way, you don't have to create a plugin. Just an override file with a few lines of code in it.

The following user(s) said Thank You: [DomB22](/forum/user/82577-domb22 "View DomB22's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwODMzOC11c2luZy10aGUtZmllbGQtY2xhc3M/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[DomB22](/forum/user/82577-domb22 "View DomB22's Profile")**
- [![DomB22's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/82577-domb22 "View DomB22's Profile") Topic Author
- [ Offline](/forum/user/82577-domb22)

Less More

- Posts: 9
- Thank you received: 1
-
-

2 years 4 months ago [\#361823](#361823) by [DomB22](/forum/user/82577-domb22 "View DomB22's Profile")  Replied by *[DomB22](/forum/user/82577-domb22 "View DomB22's Profile")* on topic *[Using the "field" class](/forum/31-development/908338-using-the-field-class#361823 "-- HikaShop version -- : 5.1.0 -- Joomla version -- : 4.4.5  Hello, I'm a relative beginner with Hikashop but I've experience with Woocommerce. For a plugin development project I need to interact with the hikashop&#95;field table. More precisely I want to retrieve all the values of a singledropdown field based on its field&#95;realname and then update them. I understand that I must start with hikashop&#95;get('class.field'); but then I'm lost ; I've looked into the code of com&#95;hikashop/classes/field.php but without success (and because it extends hikashopClass maybe the answer is in the base class) Any pointer would be appreciated, thank you.")*

Thank you for the reply and the override tip, Nicolas.
Per the following code I managed to retrieve a field value based on its namedkey and no error is raised.
However the new field value with the added option is not saved into the database, I must be missing another thing?

Code:

$class = hikashop_get('class.field'); $field = $class-&gt;getField('couleur', 'product'); $lenew = new stdClass(); $lenew-&gt;value = "azur"; $lenew-&gt;disabled = 0; $field-&gt;field_value['bleue'] = $lenew; $class-&gt;save($field));

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwODMzOC11c2luZy10aGUtZmllbGQtY2xhc3M/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[DomB22](/forum/user/82577-domb22 "View DomB22's Profile")**
- [![DomB22's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/82577-domb22 "View DomB22's Profile") Topic Author
- [ Offline](/forum/user/82577-domb22)

Less More

- Posts: 9
- Thank you received: 1
-
-

2 years 4 months ago [\#361825](#361825) by [DomB22](/forum/user/82577-domb22 "View DomB22's Profile")  Replied by *[DomB22](/forum/user/82577-domb22 "View DomB22's Profile")* on topic *[Using the "field" class](/forum/31-development/908338-using-the-field-class#361825 "-- HikaShop version -- : 5.1.0 -- Joomla version -- : 4.4.5  Hello, I'm a relative beginner with Hikashop but I've experience with Woocommerce. For a plugin development project I need to interact with the hikashop&#95;field table. More precisely I want to retrieve all the values of a singledropdown field based on its field&#95;realname and then update them. I understand that I must start with hikashop&#95;get('class.field'); but then I'm lost ; I've looked into the code of com&#95;hikashop/classes/field.php but without success (and because it extends hikashopClass maybe the answer is in the base class) Any pointer would be appreciated, thank you.")*

FYI I achieved what I wanted with : Code:

$class-&gt;addValue($field-&gt;field_id, 'bleue', 'azur', 0);

but I'm still intested in understanding my previous error.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwODMzOC11c2luZy10aGUtZmllbGQtY2xhc3M/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86584
- Thank you received: 14325
-
-

2 years 4 months ago -  2 years 4 months ago [\#361826](#361826) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Using the "field" class](/forum/31-development/908338-using-the-field-class#361826 "-- HikaShop version -- : 5.1.0 -- Joomla version -- : 4.4.5  Hello, I'm a relative beginner with Hikashop but I've experience with Woocommerce. For a plugin development project I need to interact with the hikashop&#95;field table. More precisely I want to retrieve all the values of a singledropdown field based on its field&#95;realname and then update them. I understand that I must start with hikashop&#95;get('class.field'); but then I'm lost ; I've looked into the code of com&#95;hikashop/classes/field.php but without success (and because it extends hikashopClass maybe the answer is in the base class) Any pointer would be appreciated, thank you.")*

Hi,

Ah right, I forgot about the save part. You can't use the save method directly. The field_value attribute is discarded because it isn't in a valid form. You need to set the field_value in the format that is the same as what you can see in the database.
So you'll have to do something like this: Code:

$field_value = array(); foreach($field-&gt;field_value as $value =&gt; $object) { $field_value = $object-&gt;title.'::'.$value.'::'.$object-&gt;disabled; } $field-&gt;field_value = implode("\n", $field_value);

Then, the save call will take into account the field_value.

The addValue method is actually way better for adding / updating values. I had forgotten about it.

Last edit: 2 years 4 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

The following user(s) said Thank You: [DomB22](/forum/user/82577-domb22 "View DomB22's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50LzkwODMzOC11c2luZy10aGUtZmllbGQtY2xhc3M/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.085 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
