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

#   Custom fields errors

##

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

10 years 9 months ago -  10 years 9 months ago [\#228891](#228891) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[Custom fields errors](/forum/27-checkout/875842-custom-fields-errors?start=20#228891 "-- HikaShop version -- : 2.4.0 -- HikaMarket version -- : 1.6.1 -- Joomla version -- : 3.3.6 -- PHP version -- : 5.4.16  HI,  I've noticed the following errors concerning product custom fields:  1. If a custom field (in my case order field) is assigned to a single product and is marked as required, an required field error is displayed for all the products no matter that this custom field is assigned to a single product. And no matter that the custom field itself is not displayed in other products order form.  2. In HS-&gt;Config-&gt;display-&gt;customFields-&gt;someCustomField the assigned categories for that custom field are not visible although they exist in DB  Regards!")*

Hello,
Here is a patch that will enable you to support the restrictions of order custom fields on products and categories. You'll just have to edit the "administrator/components/com_hikashop/classes/field.php" file and add these lines : Code:

//if required field of the table order and products or categories restriction if($field-&gt;field_table == 'order' &amp;&amp; ($field-&gt;field_products != 'all' &#124;&#124; $field-&gt;field_categories != 'all')){ $cartClass = hikashop_get('class.cart'); $fieldClass = hikashop_get('class.field'); $cart = $cartClass-&gt;loadFullCart(true); $inCart = false; $restricted_products = array (); $restricted_categories = array(); //Product check if($field-&gt;field_products != 'all'){ $restricted_products = explode(',', $field-&gt;field_products); $restricted_products = array_filter($restricted_products); foreach($cart-&gt;cart_products as $cart_product){ if(in_array($cart_product-&gt;product_id, $restricted_products)) $inCart = true; } } //Category check if($field-&gt;field_categories != 'all' &amp;&amp; !$inCart){ $restricted_categories = explode(',', $field-&gt;field_categories); $restricted_categories = array_filter($restricted_categories); $cart_categories = $fieldClass-&gt;getCategories('order', $cart); foreach($restricted_categories as $restricted_category){ if($field-&gt;field_with_sub_categories &amp;&amp; in_array($restricted_category, $cart_categories['parents'])) $inCart = true; else if(!$field-&gt;field_with_sub_categories &amp;&amp; in_array($restricted_category, $cart_categories['originals'])) $inCart = true; } } if(!$inCart) return true; }

Just after these lines : Code:

function check(&amp;$field,&amp;$value,$oldvalue) { if(is_string($value)) $value = trim($value); if(!$field-&gt;field_required &#124;&#124; is_array($value) &#124;&#124; strlen($value) &#124;&#124; strlen($oldvalue)) return true;

Last edit: 10 years 9 months ago by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile").

The following user(s) said Thank You: [filiar](/forum/user/33070-filiar "View filiar's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg3NTg0Mi1jdXN0b20tZmllbGRzLWVycm9ycz9zdGFydD0yMCZ0bXBsPW1hcmtkb3du) 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.047 seconds

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