magento2: Wrong drop-down option labels for configurable products attributes using custom source
Preconditions
- Magento 2.1.1 (updated from 2.0.8)
- PHP 5.6.25
- MySQL 5.6.23
Steps to reproduce
- Create a module with a custom Model
- Create an attribute for the product entity with a custom source referencing the new Model
- Create an attribute set with the new attribute
- Create a configurable product using the new attribute set and a few associated simple products
- While ererything is working fine, update from 2.0.8 to 2.1.1
Expected result
- On the backend, the product edit pages should show options for the dropdown that are returned by the getSpecificOptions() of the class extending AbstractSource
- On the frontend, the product view page should show only available options of the simple products associated to the configurable product
Actual result
On the backend product edit page, everything seems all right, all options are loaded from the custom source / database table


On the frontend, the configurable product drop-downs show the correct attribute name and the right amount of options for each attribute, but the <option> labels and values show wrong data, like “Male” and “Not Specified” or even “null”


This error also appears on the product configuration modal (backend / new order).


Inspecting the code of the product view page, I’ve found this part where we see the wrong option labels being applied (the attribute labels are correect, only the options labels are wrong):
<script type="text/x-magento-init"> { "#product_addtocart_form": { "configurable": { "spConfig": {"attributes":{"286":{"id":"286","code":"ticketsale_session","label":"Session","options":[{"id":"1","label":"Male","products":["72","73","74","75"]},{"id":"3","label":"Not Specified","products":["76","77","78","79"]}],"position":"0"},"287":{"id":"287","code":"ticketsale_sector","label":"Sector","options":[{"id":"1","label":"Male","products":["72","73","76","77"]},{"id":"4","label":null,"products":["74","75","78","79"]}],"position":"1"},"288":{"id":"288","code":"ticketsale_ticket_type","label":"Ticket Type","options":[{"id":"32","label":"Full price","products":["72","74","76","78"]},{"id":"33","label":"Half price","products":["73","75","77","79"]}],"position":"2"}},"template":"R$<%- data.price %>","optionPrices":{ /* removed for simplicity */ },"productId":"71","chooseText":"Choose an Option...","images":[],"index":{"/* removed for simplicity */}, "onlyMainImg": true } } } </script>
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 23 (4 by maintainers)
I’ve literally had a breakdown after months of working on my magento 2 project (a very challenging to develop ticket sale module). After struggling with reverse engineering and getting to understand Magento 2 inner workings, I ended up with heart problems due to stress, which caused me to undergo a pacemaker implant surgery last December.
In the end, nowadays I just have the confidence to debug issues and most of the times conclude that some things are just a brand new magento bug. Some of them, we fix with plugins of our own, never editing core files.
I second that:
I have replicated the same issue on magento 2.3.2.
Magento attributes like
colordo show correctly. Custom attributes show correct on product pages but when you go on the cart page they show empty. Proceeding with the order when i get the email i still do not see the attribute values. The Values are missing also on the order page on the admin area. So the attribute values are missing on:Default magento attributes work as expected
I find this a really severe bug! Using configurable products with own attribute values is a valid use case for Magento shops. That’s one of a couple of reasons why I used Magento 1. Now finding out that this couldn’t be fixed withing more than 6 months makes it really annoying.
But as important this problem is I cannot see others (people, developer, etc.) complaining about this. I couldn’t find any other bug reports or hints about this problem execept this bug report here.
Really strange.