currently, if an attribute field is not checked as required on the product variation form and then you create a product and do not assign an attribute from this attribute type you will get errors and an nonfunctional add to cart form. in many cases, some of the attributes available to a variation type are not needed so the attribute should be ignored if it is not assigned to any product during the product variation creation process.

it appears that now ALL attributes must be assigned to each product variation or errors occur. I believe this is the error

TypeError: Argument 1 passed to Drupal\Core\Entity\EntityViewBuilder::view() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /var/www/html/mysite/web/modules/contrib/commerce/modules/product/src/Element/CommerceProductRenderedAttribute.php on line 41 in Drupal\Core\Entity\EntityViewBuilder->view() (line 110 of /var/www/html/mysite/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php) #0 /var/www/html/mysite/web/modules/contrib/commerce/modules/product/src/Element/CommerceProductRenderedAttribute.php(41): Drupal\Core\Entity\EntityViewBuilder->view(NULL, 'add_to_cart') #1 [internal function]: Drupal\commerce_product\Element\CommerceProductRenderedAttribute::processRadios(Array, Object(Drupal\Core\Form\FormState), Array) #2 /var/www/html/ergodesk/web/core/lib/Drupal/Core/Form/FormBuilder.php(993): call_user_func_array(Array, Array) #3 /var/www/html/ergodesk/web/core/lib/Drupal/Core/Form/FormBuilder.php(1056): Drupal\Core\Form\FormBuilder->doBuildForm('commerce_order_...', Array, Object(Drupal\Core\Form\FormState)) #4 /var/www/html/ergodesk/web/core/lib/Drupal/Core/Form/FormBuilder.php(1056): Drupal\Core\Form\FormBuilder->doBuildForm('commerce_order_...', Array, Object(Drupal\Core\Form\FormState)) #5 /var/www/html/ergodesk/web/core/lib/Drupal/Core/Form/FormBuilder.php(1056): Drupal\Core\Form\FormBuilder->doBuildForm('commerce_order_...', Array, Object(Drupal\Core\Form\FormState)) #6 /var/www/html/ergodesk/web/core/lib/Drupal/Core/Form/FormBuilder.php(1056): Drupal\Core\Form\FormBuilder->doBuildForm('commerce_order_...', Array, Object(Drupal\Core\Form\FormState)) #7

CommentFileSizeAuthor
#5 Selection_008.jpg127.85 KBpyxio

Comments

drupalstrap created an issue. See original summary.

pyxio’s picture

Issue summary: View changes
drugan’s picture

Category: Feature request » Bug report
Status: Active » Postponed (maintainer needs more info)

Have you the Commerce Correct Attributes submodule enabled?

If not, please enable it because the Commerce Extended Attributes parent module does not handle displaying attributes on the Add to cart form. What it does allows to set a customer facing label and simplifies administering attributes on the admin/commerce/product-attributes page and on a product variation type edit form.

After enabling the CCA you can use optional or required attributes in any configuration. You may set up how optional fields are displayed and whether to hide a field if it has no options for the current combination. See more:

https://github.com/drugan/commerce_xattributes/tree/8.x-1.x/modules/comm...

If it does not help I need to replicate your product variation type which gives the error:

How many attributes?
Which of them are optional?
In which order they are displayed on the Add to cart form?
Which values on each of the attributes?
Which variations (attribute value combinations) were created with the attributes?
Which particular variation gives the error on the Add to cart form?

Would be even better if you'd made screenshots of what you see on your pages.

pyxio’s picture

OK. So here is exactly what i have done. i have created a new product variation type and assigned a few attributes. for widget i chose Correct attributes list. under manage fields i have unchecked the required field box to ensure any attributes are optional. then i create a test product and i leave all attributes at -None-. after saving the product i receive this error

TypeError: Argument 1 passed to Drupal\Core\Entity\EntityViewBuilder::view() must implement interface Drupal\Core\Entity\EntityInterface, null given, called in /srv/bindings/d219d1dd3a5540bf83ce053a9db6083f/code/web/modules/contrib/commerce/modules/product/src/Element/CommerceProductRenderedAttribute.php on line 41 in Drupal\Core\Entity\EntityViewBuilder->view() (line 110 of /srv/bindings/d219d1dd3a5540bf83ce053a9db6083f/code/web/core/lib/Drupal/Core/Entity/EntityViewBuilder.php) #0

if i go back to the product and assign attributes it then works. so i must assign an attribute from each type on the variation form otherwise the page crashes due to the error above.

pyxio’s picture

StatusFileSize
new127.85 KB
drugan’s picture

Assigned: Unassigned » drugan
Status: Postponed (maintainer needs more info) » Active

I was able to reproduce the bug. It happens when a variation type has optional attribute(s) of the rendered attribute type. BTW, in this case you should not assign all optional attributes values as in your screenshot. Just the rendered type attributes have to be assigned. The reason is that it has not (can't) have -None- value by its nature just because it may render multiple fields on the attribute value and those fields might be anything you can think of (not only rendered color, for example).

Before I'll find a proper solution for the bug you may try the following:

Go to the admin/commerce/config/order-item-types/YOUR_ORDER_ITEM_TYPE/edit/form-display (Default form mode!) and assign Correct attributes select list widget for the order item type which is used by your buggy variation type.

Check Hide empty field checkbox and save the form display mode settings.

Remove the variation with all empty attributes. Actually it is a legal variation in the case when all attributes are optional and I'll promise to support it but for now it should be avoided. You may easily to find this variation on a product edit form as it has N/A variation title. Again, remove it if it has at least one optional attribute of the rendered attribute type.

  • drugan committed 5c5142c on 8.x-1.x
    Issue #2946747 by drupalstrap: support unrequired attributes
    
drugan’s picture

Please, test the latest changes with and without Hide empty field checkbox checked.

UPDATE: do not forget to clear caches before the test.

drugan’s picture

Status: Active » Fixed

OK, close it and make a new beat4 release in order to get more test cases.

Feel free to reopen the issue if you still have some problems.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.