# buy-widget-form twig Fehler

**URL:** <https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536>\
**Category:** Programmierung\
**Created:** [7. Februar 2020 um 09:36 UTC](https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536 "2020-02-07T09:36:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![shoshosho](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@shoshosho](https://forum.shopware.com/u/shoshosho)\
**Post date:** [7. Februar 2020 um 09:36 UTC](https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536/1 "2020-02-07T09:36:42Z")

</div>

Hallo , versuche die buy-widget-form zu erweitern bzw dem select Element eine Klasse zu geben.&nbsp;

Leider nicht ohne Fehlermeldung

**An exception has been thrown during the rendering of a template („Warning: range(): step exceeds the specified range“).**

Meine buy-widget-form.html.twig

```
{% sw_extends '@Storefront/storefront/page/product-detail/buy-widget-form.html.twig' %}

{% block page_product_detail_buy_quantity %}
    
        {% for quantity in range(product.minPurchase, product.calculatedMaxPurchase, product.purchaseSteps) %}
            
                {{ quantity }}{% if product.packUnit %} {{ product.packUnit }}{% endif %}
            
        {% endfor %}
    
{% endblock %}

```

Hab nur die Klasse selectpicker zum select Element hinzugefügt

Link zur originalen buy-widget-form.twig.html

[https://github.com/shopware/platform/blob/master/src/Storefront/Resources/views/storefront/page/product-detail/buy-widget-form.html.twig](https://github.com/shopware/platform/blob/master/src/Storefront/Resources/views/storefront/page/product-detail/buy-widget-form.html.twig)

---

<div class="post-metadata">

**Author:** ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)\
**Post date:** [10. Februar 2020 um 10:59 UTC](https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536/2 "2020-02-10T10:59:57Z")

</div>

bist du im dev mode (APP\_ENV=dev)?

---

<div class="post-metadata">

**Author:** ![shoshosho](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@shoshosho](https://forum.shopware.com/u/shoshosho)\
**Post date:** [10. Februar 2020 um 15:23 UTC](https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536/3 "2020-02-10T15:23:01Z")

</div>

Jap, bin ich.

---

<div class="post-metadata">

**Author:** ![brettvormkopp](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/brettvormkopp/32/7788_2.png) [@brettvormkopp](https://forum.shopware.com/u/brettvormkopp)\
**Post date:** [10. Februar 2020 um 16:26 UTC](https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536/4 "2020-02-10T16:26:07Z")

</div>

Sicher dass selectpicker in **name=""** stehen soll?

---

<div class="post-metadata">

**Author:** ![shoshosho](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@shoshosho](https://forum.shopware.com/u/shoshosho)\
**Post date:** [11. Februar 2020 um 08:42 UTC](https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536/5 "2020-02-11T08:42:07Z")

</div>

Nein, habs auch bereits in class="" gesetzt aber ändert die Fehlermeldung nicht.

Grüße

---

<div class="post-metadata">

**Author:** ![AlexGalax](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/alexgalax/32/9925_2.png) [@AlexGalax](https://forum.shopware.com/u/AlexGalax)\
**Post date:** [11. Februar 2020 um 09:23 UTC](https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536/6 "2020-02-11T09:23:31Z")

</div>

Schau dir mal `vendor\shopware\storefront\Resources\views\storefront\page\product-detail\buy-widget-form.html.twig` deiner Installation (nicht github Repo) an, dort sieht der Block anders aus. Da wird vorher nämlich die Variable $maxQuantity gesetzt, ohne die vermitlich das Warning erzeugt wird.

```
                            {% block page_product_detail_buy_quantity %}
                                {% if page.product.maxPurchase %}
                                    {% if page.product.availableStock < page.product.maxPurchase %}
                                        {% set maxQuantity = page.product.availableStock %}
                                    {% else %}
                                        {% set maxQuantity = page.product.maxPurchase %}
                                    {% endif %}
                                {% else %}
                                    {% set maxQuantity = shopware.config.core.cart.maxQuantity %}
                                {% endif %}

                                
                                    {% for quantity in range(page.product.minPurchase, maxQuantity, page.product.purchaseSteps) %}
                                        
                                            {{ quantity }}{% if page.product.packUnit %} {{ page.product.packUnit }}{% endif %}
                                        
                                    {% endfor %}
                                
                            {% endblock %}

```

&nbsp;

---

<div class="post-metadata">

**Author:** ![lucahollenbach](https://avatars.discourse-cdn.com/v4/letter/l/ecc23a/32.png) [@lucahollenbach](https://forum.shopware.com/u/lucahollenbach)\
**Post date:** [21. Dezember 2020 um 10:54 UTC](https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536/7 "2020-12-21T10:54:14Z")

</div>

Hallo zusammen,&nbsp;

ich stehe aktuell vor ähnlichem&nbsp;Problem. Ich möchte gerne eine unterschiedliche Mengenstaffelung für eine Netto-Preis-Kundengruppe erstellen.  
Ich befinde mich in der&nbsp;`...storefront\page\product-detail\buy-widget-form.html.twig` meines Themes. Und hole mir den min purchase (free4) und die  
purchase steps (free5) aus&nbsp;Zusatzfeldern aus der Administration.

```
{% block page_product_detail_buy_quantity %}
    

        {% set distributorMinPurchase = product.translated.customFields.free4 %}
        {% set distributorPurchaseSteps = product.translated.customFields.free5 %}

        {% if context.currentCustomerGroup.displayGross == false %}
            {% for quantity in range(distributorMinPurchase, product.calculatedMaxPurchase, distributorPurchaseSteps) %}
                
                    {{ quantity }}
                    {% if quantity == 1 %}
                        {% if product.translated.packUnit %} {{ product.translated.packUnit }}{% endif %}
                    {% else %}
                        {% if product.translated.packUnitPlural %}
                            {{ product.translated.packUnitPlural }}
                        {% elseif product.translated.packUnit %}
                            {{ product.translated.packUnit }}
                        {% endif %}
                    {% endif %}
                
            {% endfor %}
        {% else %}
            {% for quantity in range(product.minPurchase, product.calculatedMaxPurchase, product.purchaseSteps) %}
                
                    {{ quantity }}
                    {% if quantity == 1 %}
                        {% if product.translated.packUnit %} {{ product.translated.packUnit }}{% endif %}
                    {% else %}
                        {% if product.translated.packUnitPlural %}
                            {{ product.translated.packUnitPlural }}
                        {% elseif product.translated.packUnit %}
                            {{ product.translated.packUnit }}
                        {% endif %}
                    {% endif %}
                
            {% endfor %}
        {% endif %}
    
{% endblock %}

```

In free4 und free5 ist jeweils die integer 25 übergeben. Somit erwarte ich eine Mengenstaffelung von 25, 50, 75, 100… maxPurchase.  
Dies ist jedoch nur der Fall wenn ich:

```
{% set distributorPurchaseSteps = 25 %}

```

hardcodiert setze. Er kommt also einfach nicht mit dem Zusatzfeld klar. Ich habe auch schon unterschiedliche Zusatzfelder angelegt jedoch bekomme ich  
immer wieder den Fehler:

An exception has been thrown during the rendering of a template („Warning: range(): step exceeds the specified range“).

in der Produktdetailseite. Hat jemand eine Idee, an was das liegen könnte?

Viele Grüße!

---

<div class="post-metadata">

**Author:** ![lhairman](https://avatars.discourse-cdn.com/v4/letter/l/cdc98d/32.png) [@lhairman](https://forum.shopware.com/u/lhairman)\
**Post date:** [22. Dezember 2020 um 20:34 UTC](https://forum.shopware.com/t/buy-widget-form-twig-fehler/64536/8 "2020-12-22T20:34:02Z")

</div>

Sieht für mich nach dem falschen Datentyp aus. Ich denke die Variable wird als String interpretiert, schau mal hier nach einer Konvertierung in einen Int

[https://twig.symfony.com/doc/2.x/filters/format\_number.html](https://twig.symfony.com/doc/2.x/filters/format_number.html)
