Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL Error in Subscriptions Widget #13

Open
AugustMiller opened this issue Oct 30, 2018 · 8 comments
Open

SQL Error in Subscriptions Widget #13

AugustMiller opened this issue Oct 30, 2018 · 8 comments
Assignees

Comments

@AugustMiller
Copy link

When adding the Subscriptions widget to the dashboard, it no longer loads, and presents the following error:

SQLSTATE[42703]: Undefined column: 7 ERROR: column subscriptions.planid does not exist

Unfortunately, I don't know enough about joins to understand why this isn't working (planId is indeed a column in the commerce_subscriptions table…), so my fussing with the source didn't unearth an explanation.

This is in version 2.0.9, on Craft 3.0.28, and Commerce 2.0.0-beta.12.1.

Let me know if you need any other info!

@bymayo
Copy link
Owner

bymayo commented Oct 31, 2018

@AugustMiller Ahh yes - I think this is due to Commerce changing the way plans are referenced (https://github.com/craftcms/commerce/blob/develop/CHANGELOG-v2.md#security) I'll push a fix for this tomorrow.

@bymayo
Copy link
Owner

bymayo commented Nov 2, 2018

@AugustMiller I can't seem to replicate this issue. I've hit you up on Slack but doesn't look like you've been on. If you can jump on there or post more details in here we can solve this 💪

@AugustMiller
Copy link
Author

AugustMiller commented Nov 20, 2018

This is embarrassing—I think I'd only tried this on a site without any subscriptions configured?

Unfortunately, I can't get a test subscription set up at the moment, but I'm curious to know whether emptying your available Subscriptions produces the same error?

Edit: Probably worth investigating for the ding-dongs like me who click around hastily, and might inadvertently take down their dashboard 😉 (Or maybe hiding the widgets that don't apply to the apps where it's installed?)

@bymayo
Copy link
Owner

bymayo commented Nov 21, 2018

@AugustMiller I think hiding widgets that don't apply is a good idea! I'll be pushing a fix for this later this week :)

@bymayo bymayo self-assigned this Nov 21, 2018
@AugustMiller
Copy link
Author

FYI—tried a few more widgets, and even relevant ones seem to generate SQL errors.

It seems most errors are just mismatched column names, or potentially issues with case-sensitivity?

For context, this app uses Postgres—apologies for not mentioning this in the original issue!

@bymayo
Copy link
Owner

bymayo commented Nov 29, 2018

@AugustMiller I'll run tests using a Postgres database then - But could you paste some of the errors your getting in to this issue?

@AugustMiller
Copy link
Author

AugustMiller commented Dec 7, 2018

So sorry this has dragged on! 😥

Got a couple messages for you—overall, it seems like the case sensitivity in Postgres is responsible for most of these?

bymayo\commercewidgets\widgets\ProductsTop::getProducts()

SQLSTATE[42703]: Undefined column: 7 ERROR: column items.purchasableid does not exist
LINE 3: ...purchasables" "purchasables" ON purchasables.id = items.purc...
^
HINT: Perhaps you meant to reference the column "items.purchasableId".
The SQL being executed was: SELECT "variants"."productId" AS "id", "variants"."sku" AS "sku", SUM(items.total) as totalRevenue, count(*) as totalOrdered
FROM "commerce_lineitems" "items"
LEFT JOIN "commerce_purchasables" "purchasables" ON purchasables.id = items.purchasableId
LEFT JOIN "commerce_variants" "variants" ON variants.id = purchasables.id
GROUP BY "items"."purchasableId"
ORDER BY "totalRevenue" DESC
LIMIT 5

bymayo\commercewidgets\widgets\TotalRevenueOrders::getRevenueOrdersRow(['label' => 'Today', 'date' => '03 Dec 2018'])

SQLSTATE[42703]: Undefined column: 7 ERROR: column orders.totalprice does not exist
LINE 1: SELECT COALESCE(sum(orders.totalPrice), 0) as totalRevenue, ...
^
HINT: Perhaps you meant to reference the column "orders.totalPrice".
The SQL being executed was: SELECT COALESCE(sum(orders.totalPrice), 0) as totalRevenue, COALESCE(count(orders.id), 0) as totalOrders
FROM "commerce_orders" "orders"
WHERE ("orders"."isCompleted"=1) AND (DATE_FORMAT(orders.dateCreated, "%Y-%m-%d")='2018-12-07')
LIMIT 1

bymayo\commercewidgets\widgets\TopCustomers::getCustomers()

SQLSTATE[42703]: Undefined column: 7 ERROR: column orders.totalprice does not exist
LINE 1: SELECT count(*) as totalOrders, SUM(orders.totalPrice) as to...
^
HINT: Perhaps you meant to reference the column "orders.totalPrice".
The SQL being executed was: SELECT count(*) as totalOrders, SUM(orders.totalPrice) as totalRevenue, "orders"."email", "orders"."customerId"
FROM "commerce_orders" "orders"
WHERE "orders"."isCompleted"=1
GROUP BY "orders"."email"
ORDER BY "totalOrders" DESC
LIMIT 5

bymayo\commercewidgets\widgets\Goal::getTotals()

SQLSTATE[42703]: Undefined column: 7 ERROR: column orders.totalpaid does not exist
LINE 1: ...OALESCE(count(*), 0) as totalOrders, COALESCE(SUM(orders.tot...
^
HINT: Perhaps you meant to reference the column "orders.totalPaid".
The SQL being executed was: SELECT COALESCE(count(*), 0) as totalOrders, COALESCE(SUM(orders.totalPaid),0) as totalRevenue
FROM "commerce_orders" "orders"
WHERE (WEEK(orders.datePaid)='49') AND (YEAR(orders.datePaid)='2018')
LIMIT 1

bymayo\commercewidgets\widgets\SubscriptionPlans::getSubscriptionPlans()

SQLSTATE[42703]: Undefined column: 7 ERROR: column subscriptions.planid does not exist
LINE 3: ... JOIN "commerce_subscriptions" "subscriptions" ON subscripti...
^
HINT: Perhaps you meant to reference the column "subscriptions.planId".
The SQL being executed was: SELECT "plans".*, COUNT(subscriptions.planId) as activeSubscriptions
FROM "commerce_plans" "plans"
LEFT JOIN "commerce_subscriptions" "subscriptions" ON subscriptions.planId = plans.id
WHERE "plans"."isArchived"=0
GROUP BY "plans"."id"
ORDER BY "dateCreated" DESC
LIMIT 4

@bymayo
Copy link
Owner

bymayo commented Jan 4, 2019

@AugustMiller I'm having difficulties fixing this issue, as I've just installed the widgets on a fresh site that only has orders (No subscriptions) and the widgets / CMS doesn't error when enabling subscriptions widgets with no plans available.

Also with the Postgres errors, they do look like case errors, but looking at my queries i'm targeting them with the correct case (Not like it says in the error).

Is there any more information you can give, or if your happy to jump on Slack one day we can bash this error out a bit easier?

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

No branches or pull requests

2 participants