Using a custom field in a variant product

  • Posts: 100
  • Thank you received: 1
11 years 2 months ago #94857

HI

I have the following setup

1 main product, 1 option and 2 variants.

I have created a custom field (called maximum_place) and assigned it to the Main Product. I would like to display this custom field in the variant drop down combo.

I can't seem to figure out how to reference this field in the view product and file option.php.

I have tried

$optionElement->maximum_place and $optionElement->main->maximum_place but i get nothing...

Have i called it correctly.

Thanks

Patrick

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

  • Posts: 81677
  • Thank you received: 13102
  • MODERATOR
11 years 2 months ago #95021

Hi,

If you want to have the value of custom field in the main product of the option, it should indeed be $optionElement->maximum_place or $optionElement->main->maximum_place but only inside the foreach($this->element->options as $optionElement){ block of code in the option.php file.
Outside that block is will be more complex.
Something like that:
$optionElement = reset($this->element->options);
echo $optionElement->main->maximum_place;

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

  • Posts: 100
  • Thank you received: 1
11 years 2 months ago #95031

HI Nicolas

I have used the following in the option.php file below line 86

$this->row->prices = array($variant->prices[$k]);
$optionElement = reset($this->element->options);
$text = $variant->start_date.$text;
$text.=" Remaining Spots " . $variant->product_quantity. " of " . $optionElement->main->maximum_place . ' '.($positive?'+':'').strip_tags($this->loadTemplate());


However, I still don't get the value which has been set in the custom field in the Main product.

Am I still doing something incorrect.

Thanks

Patrick

Last edit: 11 years 2 months ago by paddyrolls.

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

  • Posts: 81677
  • Thank you received: 13102
  • MODERATOR
11 years 2 months ago #95054

Is the value in the main product or in the option ?
If it's in the main product it should be either $this->element->maximum_place or $this->element->main->maximum_place

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

  • Posts: 100
  • Thank you received: 1
11 years 2 months ago #95245

HI Nicolas

Thank you for the information

The custom field was on the main product so $this->element->maximum_place worked.

:)

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

Time to create page: 0.061 seconds
Powered by Kunena Forum