Hey Support,
I am having an issue with the rendering of Product Attributes. I created a custom select attribute and created all of the options for it BUT I quickly realized that the actual value for the options is the ID and not the value I entered into the backend.
I was able to determine that this is hard set in Corals/modules/Ecommerce/Classes/Ecommerce.php line 674
Am I going to need to create a custom plugin that extends the Ecommerce class and create a new Scope in order to do this or is there a flag I am missing to tell the renderProductOptions method to use the user defined values for the select options rather than the id?
Thank you,
Matthew
Attachments
Please login or Register to submit your answer
Hello Matthew,
Thanks for reaching us, can you please inform us how to reproduce the issue, for example, what is the attribute details you created?
Hey Support,
I have updated my question with 2 screenshots. Its simply the way the product attribute renders on the product. If you create a product attribute of type select, and assign option values and displays to it, when it is rendered on the product page the client see’s the value is assigned as the ID and not the values defined in the product-attribute-screenshot.png.
The fields are being rendered on the product_single.blade.php file using the following:
@if($product->globalOptions->count())
{!! $product->renderProductOptions(‘global_options’,null, [‘class’=>’form-control form-control-sm’]) !!}
@endif
This calls the renderProductOptions method in Product.php which then invokes the renderAttribute method in Ecommerce.php.
In Ecommerce.php line 674 the following is what sets the product attribute fields for the select type:
$input = CoralsForm::{$field->type}(‘options[‘ . $field->id . ‘]’, $field->label, $field->options->pluck(‘option_display’, ‘id’)->toArray(), $asFilter ? false : $field->required, $value, $attributes, ‘select2’);
This tells the blade file to render it using the option_display and the id instead of the option_value.
Please let me know if you still have questions.
Thank you,
Matthew
I should add, I want the option_value to show because I have defined those values as HEX codes. When the user selects an option, Javascript will take the HEX code from the select option value and change the background color of an HTML element. I know I could make an ajax call to a custom controller to retrieve the option_value from the id of the attribute but that really seems excessive to do it that way.
I really appreciate your help on this!
Thank you,
Matthew
Hello Matthew,
Unfortunately, this can be made by custom development, it will be 4 hours of development to add it to our platform as we cannot manage different coding for each customer