Is it true that this functionality is still not in production after seven years?
- 🇮🇱Israel jsacksick
No?
if (count($variations) === 0) { // Nothing to purchase, tell the parent form to hide itself. $form_state->set('hide_form', TRUE); $element['variation'] = [ '#type' => 'value', '#value' => 0, ]; return $element; } elseif (count($variations) === 1 && $this->getSetting('hide_single')) { /** @var \Drupal\commerce_product\Entity\ProductVariationInterface $selected_variation */ $selected_variation = reset($variations); $element['variation'] = [ '#type' => 'value', '#value' => $selected_variation->id(), ]; return $element; }
Where is this code snippet from? All our products are rendered with a variations dropdown even when they have just one variation.
- 🇳🇿New Zealand djroshi
Hey, I stumbled across this as I was wondering the same thing. Turns out this checkbox is on the order item type (as opposed to the product or product variation)
1. Go to /admin/commerce/config/order-item-types
2. On the order item type click the arrow next to edit and select Manage form display
3. At the top, next to Default, click Add to cart
4. Next to Purchased entity select Product variation title
5. Click the cog wheel to display the widget settings
6. Check the Hide if there's only one product variation checkboxThere is more information about configuring the add to cart form here: https://docs.drupalcommerce.org/commerce2/developer-guide/products/displ...
Thank you very much djroshi! I was already looking from a right place but I never figured out to change Product variations attributes to Product variation title. It was not very intuitive. :)