# Versandkostenberechnung nach Regionen Erweiterte SQL Abfrage

**URL:** <https://forum.shopware.com/t/versandkostenberechnung-nach-regionen-erweiterte-sql-abfrage/63305>\
**Category:** Administration\
**Created:** [3. Dezember 2019 um 08:52 UTC](https://forum.shopware.com/t/versandkostenberechnung-nach-regionen-erweiterte-sql-abfrage/63305 "2019-12-03T08:52:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pArc23](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@pArc23](https://forum.shopware.com/u/pArc23)\
**Post date:** [3. Dezember 2019 um 08:52 UTC](https://forum.shopware.com/t/versandkostenberechnung-nach-regionen-erweiterte-sql-abfrage/63305/1 "2019-12-03T08:52:29Z")

</div>

Hallo,&nbsp;

ich versuche eine Versandkostenberechnung nach Regionen (AreaID) durch zuführen. Dafür habe ich in der Versandkostenberechnung folgendes ergänzt:

(SELECT areaID FROM s\_core\_countries &nbsp;WHERE id = us.countryID) AS areaId

In der Versandart habe ich unter eigene berechnung folgendes ergänzt:

&nbsp;

IF(  
&nbsp; &nbsp; areaId = 1,  
&nbsp; &nbsp; 4.99,  
IF(  
&nbsp; &nbsp; areaId = 2,  
&nbsp; &nbsp; 9.99,  
IF(  
&nbsp; &nbsp; areaId = 3,  
&nbsp; &nbsp; 14.99,  
IF(  
&nbsp; &nbsp; areaId = 4,  
&nbsp; &nbsp; 29.99,  
))))

Leider lädt sich der Offcanvas Warenkorb mit dieser Ergänzung immer tot. Es scheint also was im Versandkostenmodul nicht zu stimmen. Der Vollständigkeit halber der ganze Eintrag in der erweiterten SQL-Abfrage:&nbsp;

MAX(a.topseller) as has\_topseller, MAX(at.attr3) as has\_comment, MAX(b.esdarticle) as has\_esd, MAX(at.att\_sperrgut=„1“) AS sperrgut, MAX(d.shippingfree) &nbsp;AS allshippingfree, MAX(at.att\_spedition=„1“) AS spedition, (SELECT areaID FROM s\_core\_countries &nbsp;WHERE id = us.countryID) AS areaId

Wenn ich meine Ergänzung rausnehme funktioniert es wieder Einwandfrei, habt ihr irgendwelche Ideen? Das Thema lässt mich langsam verzweifeln.

Beste Grüße,

Martin

---

<div class="post-metadata">

**Author:** ![pArc23](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@pArc23](https://forum.shopware.com/u/pArc23)\
**Post date:** [3. Dezember 2019 um 22:03 UTC](https://forum.shopware.com/t/versandkostenberechnung-nach-regionen-erweiterte-sql-abfrage/63305/2 "2019-12-03T22:03:35Z")

</div>

Als Ergänzung hier mal noch die Fehlermeldung:

&nbsp;

An exception occurred while executing ‘SELECT MIN(d.instock\>=b.quantity) as instock, MIN(d.instock\>=(b.quantity+d.stockmin)) as stockmin, MIN(a.laststock) as laststock, SUM(d.weight\*b.quantity) as weight, SUM(IF(a.id,b.quantity,0)) as count\_article, MAX(b.shippingfree) as shippingfree, SUM(IF(b.modus=0,b.quantity\*CAST(b.price as DECIMAL(10,2))/b.currencyFactor,0)) as amount, SUM(IF(b.modus=0,b.quantity\*ROUND(CAST(b.price as DECIMAL(10,2))/(100+t.tax)\*100,2)/b.currencyFactor,0)) as amount\_net, SUM(CAST(b.price as DECIMAL(10,2))\*b.quantity) as amount\_display, MAX(d.length) as `length`, MAX(d.height) as height, MAX(d.width) as width, u.id as userID, MAX(a.topseller) as has\_topseller, MAX(at.attr3) as has\_comment, MAX(b.esdarticle) as has\_esd, MAX(at.att\_sperrgut=“1”) AS sperrgut, MAX(d.shippingfree) AS allshippingfree, MAX(at.att\_spedition=“1”) AS spedition, (SELECT areaID FROM s\_core\_countries WHERE id = us.country\_id) AS areaId, (IF( areaId = 1, 4.99, IF( areaId = 3, 9.99, IF( areaId = 4, 14.99, )))) as calculation\_value\_111, SUM(IF(b.modus=0 AND oba.swag\_is\_free\_good\_by\_promotion\_id IS NULL,b.quantity\*CAST(b.price as DECIMAL(10,2))/b.currencyFactor,0)) as amount, SUM(IF(b.modus=0 AND oba.swag\_is\_free\_good\_by\_promotion\_id IS NULL,b.quantity\*ROUND(CAST(b.price as DECIMAL(10,2))/(100+t.tax)\*100,2)/b.currencyFactor,0)) as amount\_net FROM s\_order\_basket b LEFT JOIN s\_articles a ON b.articleID = a.id AND b.modus = 0 AND b.esdarticle = 0 LEFT JOIN s\_user u ON u.id = ? AND u.active = 1 LEFT JOIN s\_order\_basket\_attributes oba ON b.id = oba.basketID LEFT JOIN s\_articles\_details d ON (d.ordernumber = b.ordernumber) AND d.articleID = a.id LEFT JOIN s\_core\_tax t ON t.id = a.taxID LEFT JOIN s\_articles\_attributes at ON at.articledetailsID = d.id LEFT JOIN s\_user\_addresses ub ON ub.user\_id = u.id AND ub.id = ? LEFT JOIN s\_user\_addresses us ON us.user\_id = u.id AND us.id = ? WHERE b.sessionID = ? GROUP BY b.sessionID’ with params [null, 0, 0, “fcaa8c74084bb454a0c99f1494df0a56f44d6267eeb5d5f6b0d34eb0db40eef2”]: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘)))) as calculation\_value\_111, SUM(IF(b.modus=0 AND oba.swag\_is\_free\_good\_by\_pro’ at line 10 in vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php on line 131

---

<div class="post-metadata">

**Author:** ![EikeBrandtWarneke](https://avatars.discourse-cdn.com/v4/letter/e/cdc98d/32.png) [@EikeBrandtWarneke](https://forum.shopware.com/u/EikeBrandtWarneke)\
**Post date:** [4. Dezember 2019 um 07:19 UTC](https://forum.shopware.com/t/versandkostenberechnung-nach-regionen-erweiterte-sql-abfrage/63305/3 "2019-12-04T07:19:19Z")

</div>

IF( areaId = 4, 14.99, ))))

Fällt dir was auf?

Viele Grüße  
[https://www.digitvision.de](https://www.digitvision.de)

---

<div class="post-metadata">

**Author:** ![pArc23](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@pArc23](https://forum.shopware.com/u/pArc23)\
**Post date:** [6. Dezember 2019 um 13:54 UTC](https://forum.shopware.com/t/versandkostenberechnung-nach-regionen-erweiterte-sql-abfrage/63305/4 "2019-12-06T13:54:54Z")

</div>

Hi Eike,

ja, hinter 14,99 fehlt natürlich noch was. Beim vielen Testen irgendwie untergegangen, das war aber leider nicht die Ursache des Problems.

Falls die Lösung mal einen interessieren sollte, so läuft es:

IF(  
&nbsp; &nbsp; @areaId = 1,  
&nbsp; &nbsp; 4.99,  
IF(  
&nbsp; &nbsp; @areaId = 3,  
&nbsp; &nbsp; 9.99,  
IF(  
&nbsp; &nbsp; @areaId = 4,  
&nbsp; &nbsp; 14.99,  
&nbsp; &nbsp; 29.99  
)))
