Versandkosten Eigene Berechnung mit IF/ELSE bzw. Case/When

Wir verwenden bei den Versandkosten zur Berechnung ein Freitextfeld und nutzen bei eigene Berechnung folgende Formel: SUM(at.attr2*b.quantity). Nun sollte ohne alle Versandarten zu duplizieren, für einen Subshop ein anderes Freitextfeld (attr4) abgefragt werden. In Worten ausgedrückt: Wenn multishopID gleich X dann berechne die Summe aus Freitextfeld attr4, ansonsten die Summe aus Freitextfeld attr2. Ich habe schon verschiedenes in dieser Richtung probiert, z.B. folgender Code: CASE WHEN (b.multishopID!=4) THEN SUM(at.attr2\*b.quantity) ELSE (SUM(at.attr4\*b.quantity)) Geht das irgendwie? Vielleicht ist nur die Syntax falsch?

Hallo, müsste sowas in der Richtung sein, ist allerdings jetzt nicht getestet SUM(IF(b.multishopID != 4, at.attr2\*b.quantity)ELSE(at.attr4\*b.quantity)) alternativ könnte auch jeweils eine Eigene Bedingung und dann jeweils die Berechnung angelegt werden, allerdings müssten dann alle Versandkosten doppelt angelegt werden. Eigene Bedingungen b.multishopID != 4 Eigene Berechnung at.attr2\*b.quantity Dann sollte die Versandart nur erscheinen wenn man sich in dem entsprechenden Shop befindet. Viele Grüße Oliver

Danke, aber so klappt es leider nicht, da folgender Fehler kommt: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')ELSE(at.attr4\*b.quantity))) as calculation\_value\_13, (SUM(at.attr2\*b.quantity))' at line 12 in Zend/Db/Statement/Pdo.php on line 234 Stack trace: #0 Zend/Db/Statement.php(300): Zend\_Db\_Statement\_Pdo-\>\_execute(Array) #1 Zend/Db/Adapter/Abstract.php(479): Zend\_Db\_Statement-\>execute(Array) #2 Zend/Db/Adapter/Pdo/Abstract.php(238): Zend\_Db\_Adapter\_Abstract-\>query('\r\n\t\t\tSELECT\r\n\t\t...', Array) #3 Enlight/Components/Db/Adapter/Pdo/Mysql.php(75): Zend\_Db\_Adapter\_Pdo\_Abstract-\>query('\r\n\t\t\tSELECT\r\n\t\t...', Array) #4 Zend/Db/Adapter/Abstract.php(755): Enlight\_Components\_Db\_Adapter\_Pdo\_Mysql-\>query('\r\n\t\t\tSELECT\r\n\t\t...', Array) #5 Enlight/Components/Adodb.php(259): Zend\_Db\_Adapter\_Abstract-\>fetchRow('\r\n\t\t\tSELECT\r\n\t\t...', Array) #6 engine/core/class/sAdmin.php(3302): Enlight\_Components\_Adodb-\>GetRow('\r\n\t\t\tSELECT\r\n\t\t...', Array) #7 engine/core/class/sAdmin.php(3383): sAdmin-\>sGetDispatchBasket(2, NULL) #8 [internal function]: sAdmin-\>sGetPremiumDispatches(2, NULL) #9 cache/proxies/sAdminProxy.php(11): call\_user\_func\_array(Array, Array) #10 Enlight/Hook/HookManager.php(179): Shopware\_Proxies\_sAdminProxy-\>executeParent('sGetPremiumDisp...', Array) #11 cache/proxies/sAdminProxy.php(37): Enlight\_Hook\_HookManager-\>executeHooks(Object(Shopware\_Proxies\_sAdminProxy), 'sGetPremiumDisp...', Array) #12 engine/core/class/sAdmin.php(2426): Shopware\_Proxies\_sAdminProxy-\>sGetPremiumDispatches(2) #13 Shopware/Controllers/Frontend/Checkout.php(1017): sAdmin-\>sGetDispatches(2) #14 Shopware/Controllers/Frontend/Checkout.php(107): Shopware\_Controllers\_Frontend\_Checkout-\>getSelectedDispatch() #15 [internal function]: Shopware\_Controllers\_Frontend\_Checkout-\>cartAction() #16 cache/proxies/ShopwareControllersFrontendCheckoutProxy.php(11): call\_user\_func\_array(Array, Array) #17 Enlight/Hook/HookManager.php(179): Shopware\_Proxies\_ShopwareControllersFrontendCheckoutProxy-\>executeParent('cartAction', Array) #18 cache/proxies/ShopwareControllersFrontendCheckoutProxy.php(23): Enlight\_Hook\_HookManager-\>executeHooks(Object(Shopware\_Proxies\_ShopwareControllersFrontendCheckoutProxy), 'cartAction', Array) #19 Enlight/Controller/Action.php(148): Shopware\_Proxies\_ShopwareControllersFrontendCheckoutProxy-\>cartAction() #20 Enlight/Controller/Dispatcher/Default.php(521): Enlight\_Controller\_Action-\>dispatch('cartAction') #21 Enlight/Controller/Front.php(214): Enlight\_Controller\_Dispatcher\_Default-\>dispatch(Object(Enlight\_Controller\_Request\_RequestHttp), Object(Enlight\_Controller\_Response\_ResponseHttp)) #22 Shopware/Components/HttpCache/HttpKernel.php(79): Enlight\_Controller\_Front-\>dispatch() #23 Symfony/Component/HttpKernel/HttpCache/HttpCache.php(434): Shopware\Components\HttpCache\HttpKernel-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #24 Shopware/Components/HttpCache/AppCache.php(234): Symfony\Component\HttpKernel\HttpCache\HttpCache-\>forward(Object(Symfony\Component\HttpFoundation\Request), true, NULL) #25 Symfony/Component/HttpKernel/HttpCache/HttpCache.php(403): Shopware\Components\HttpCache\AppCache-\>forward(Object(Symfony\Component\HttpFoundation\Request), true) #26 Symfony/Component/HttpKernel/HttpCache/HttpCache.php(303): Symfony\Component\HttpKernel\HttpCache\HttpCache-\>fetch(Object(Symfony\Component\HttpFoundation\Request), true) #27 Shopware/Components/HttpCache/AppCache.php(158): Symfony\Component\HttpKernel\HttpCache\HttpCache-\>lookup(Object(Symfony\Component\HttpFoundation\Request), true) #28 Symfony/Component/HttpKernel/HttpCache/HttpCache.php(192): Shopware\Components\HttpCache\AppCache-\>lookup(Object(Symfony\Component\HttpFoundation\Request), true) #29 Shopware/Components/HttpCache/AppCache.php(110): Symfony\Component\HttpKernel\HttpCache\HttpCache-\>handle(Object(Symfony\Component\HttpFoundation\Request), 1, true) #30 Shopware/Bootstrap.php(70): Shopware\Components\HttpCache\AppCache-\>handle(Object(Symfony\Component\HttpFoundation\Request)) #31 Enlight/Application.php(192): Shopware\_Bootstrap-\>run() #32 shopware.php(83): Enlight\_Application-\>run() #33 {main} Bei eigene Bedingung benötige ich ja zwei Bedingungen und zwei Berechnungen. Das klappt dann so auch nicht. Ich denke mit IF Else und der richtigen Syntax könnte es ggf. irgendwie klappen. Hat jemand noch einen Tipp für mich?

Ich habe auch änliches problem 1. Ich brauche für jedes Produkt eigene Versandskosten innerhalb der EU-Länder. Das habe ich mit dem Feld ‚attr4‘ gelöst. 2. Berechnung des Versandskosten in der EU: SUM(at.attr4*b.quantity) 3. Berechnung der kleinen Produkte nach Staffelung: - bis 3 Produkte Versandkosten 8,60 Euro - 3-6 Produkte Versandskosten 15 Euro - ab 7 Produkte Versandkosten 20 Euro Nach recherchieren habe ich eine Formel entwickelt: CASE WHEN MIN((SELECT SUM(quantity) FROM s\_order\_basket WHERE articleID=21)) \> 0 AND MIN((SELECT SUM(quantity) FROM s\_order\_basket WHERE articleID=21)) \< 4 THEN SUM(at.attr4\*b.quantity) + 8.6 WHEN MIN((SELECT SUM(quantity) FROM s\_order\_basket WHERE articleID=21)) \> 3 AND MIN((SELECT SUM(quantity) FROM s\_order\_basket WHERE articleID=21)) \< 7 THEN SUM(at.attr4\*b.quantity) + 15 WHEN MIN((SELECT SUM(quantity) FROM s\_order\_basket WHERE articleID=21)) \> 6 THEN SUM(at.attr4\*b.quantity) + 20 ELSE SUM(at.attr4\*b.quantity) END Alles hat super funktioniert, soweit nur eine Session in Warenkorb(s_order_basket) liegt. Wenn 2-3 Sessions in Warenkorb liegen, werden alle Produkte mitgerechnet. Als Lösung brauche ich ‚sessionID‘ SELECT SUM(quantity) FROM s\_order\_basket WHERE articleID=21 AND sessionID=?????? Wie kann man die aktuelle ‚sessionID‘ zur Abfrage hinzufügen? Vielen Dank im Voraus