Adding a Tax Order modifier throws SQL error, missing sort column #196

Closed
NobrainerWeb opened this Issue Nov 13, 2013 · 3 comments

Projects

None yet

2 participants

Contributor

So i just added GlobalTax to OrderModifiers:
Order::set_modifiers(array("GlobalTaxModifier"));
GlobalTaxModifier::set_for_country('DK', 0.25, 'VAT', 'exclusive');

This gives me the following error, but the tax does show up in the template below the error message:
(Also described here, but i see no solution: http://www.silverstripe.org/e-commerce-modules/show/21688)

[User Error] Couldn't run query: SELECT DISTINCT "OrderAttribute"."ClassName", "OrderAttribute"."Created", "OrderAttribute"."LastEdited", "TaxModifier"."Rate", "OrderAttribute"."ID", CASE WHEN "OrderAttribute"."ClassName" IS NOT NULL THEN "OrderAttribute"."ClassName" ELSE 'OrderAttribute' END AS "RecordClassName", "Sort" FROM "OrderAttribute" LEFT JOIN "TaxModifier" ON "TaxModifier"."ID" = "OrderAttribute"."ID" WHERE ("TaxModifier"."ID" = 15) AND ("OrderAttribute"."ClassName" IN ('TaxModifier','FlatTaxModifier','GlobalTaxModifier')) ORDER BY "Sort" ASC, "OrderAttribute"."Created" ASC LIMIT 1 Unknown column 'Sort' in 'field list'

Any fix for this?
I see the demo http://demo.ss-shop.org/cart/ can show tax and does not throw the error?

Contributor

I got rid of the error message by changing line 52 of OrderModifier.php into:
public static $default_sort = ""Created" ASC"; //"Sort" ASC, throws a mysql error, see: http://www.silverstripe.org/e-commerce-modules/show/21688

(Removing the part about Sort)

No idea what other problems this might bring

Hey, Thomas, I ran into this as well. I think this one is also a Silverstripe bug (silverstripe/silverstripe-framework#1682?source=cc) that doesn't show signs of getting fixed either. I used pretty much the same solution as you but if you do it via yml you don't have to change any core files:

OrderModifier:
  default_sort: '"Created" ASC'
TaxModifier:
  default_sort: '"Created" ASC'
FlatTaxModifier:
  default_sort: '"Created" ASC'
GlobalTaxModifier:
  default_sort: '"Created" ASC'
Contributor

Hey Mark, thanks for getting back on this - i think you are right, this is a SilverStripe bug.
I will use your solution, better than changing core files :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment