Custom fields are not inherited

  • Posts: 133
  • Thank you received: 6
3 years 4 months ago #338902

Hi
I created a product and set the custom field for it.
But when I create the variant product, instead of inheriting the custom field values from the original product, the default value specified in the custom field settings is inserted in the variant product. Is there a way to avoid this and change the value of the custom field in the variant product only when necessary?
This problem does not exist in the checkbox. But there are radio buttons and drop downs.

Please Log in or Create an account to join the conversation.

  • Posts: 83904
  • Thank you received: 13581
  • MODERATOR
3 years 4 months ago #338917

Hi,

The system won't set the values of the custom fields when the variants are generated.
So if you never edit a variant, it will automatically inherit the value of the main product on the frontend.
If you edit a variant, then the default values will be displayed in the custom fields and if you click on "save", it will save these values.
So the best would be to have empty default values for all your custom product fields, or to remove the custom fields area from the variant edit interface. This can be done by removing the code:

if(!empty($this->fields) && hikashop_acl('product/edit/customfields')) {
			foreach($this->fields as $fieldName => $oneExtraField) {
?>
		<dl id="<?php echo $this->fieldsClass->prefix; ?>product_<?php echo $fieldName; ?>" class="hika_options">
			<dt class="hikashop_product_<?php echo $fieldName; ?>"><label><?php echo $this->fieldsClass->getFieldName($oneExtraField); ?></label></dt>
			<dd class="hikashop_product_<?php echo $fieldName; ?>"><?php
				$onWhat = 'onchange';
				if($oneExtraField->field_type == 'radio')
					$onWhat = 'onclick';
				echo $this->fieldsClass->display($oneExtraField, $this->product->$fieldName, 'data[variant]['.$fieldName.']', false, ' '.$onWhat.'="window.hikashop.toggleField(this.value,\''.$fieldName.'\',\'product\',0,\''.$this->fieldsClass->prefix.'\');"');
			?></dd>
		</dl>
<?php		}
		}
from the product / variant view file via the menu Display>Views.
Note however, that if the fields are "required", then the system won't allow the saving without the custom field.

The following user(s) said Thank You: levelup

Please Log in or Create an account to join the conversation.

Time to create page: 0.313 seconds
Powered by Kunena Forum