It is quite frequent to need to filter orders by product count, for example "display all the orders that have at least 5 products". We cannot do that efficiently right now, because there is no explicit uc_orders.product_count column. I suggest we add one.

Comments

rszrama’s picture

Are you referring to an additional column in the uc_orders table? If so, sounds good to me, and it could be updated just like the order_total column is.

mikejoconnor’s picture

subscribe

makara’s picture

Status: Active » Needs review
StatusFileSize
new3.83 KB

Adding patch for DRUPAL-6--2. Please review.

thill_’s picture

StatusFileSize
new28.29 KB

This patch works as expected except it doesn't set the value in the new column for existing orders.
The value is set correctly for new orders after the patch however.

This might not up a requirement of the update function, just noting the results of testing.

Island Usurper’s picture

Status: Needs review » Needs work

I think the update function should populate the column, since all of the necessary data is right there in the database.

Can we call it "product_count"? Unless there's a specific reason to, saying "order product count" sounds redundant to me, and "product_count" is long enough as it is.

makara’s picture

Status: Needs work » Needs review
StatusFileSize
new4.11 KB

Hi, here is the new patch.

The pre-populate queries should be quick enough, but I'm not sure. Please review.

Island Usurper’s picture

Status: Needs review » Fixed
StatusFileSize
new3.44 KB

Thanks, makara. I figured out a way to move the summing query outside of the loop, so there are fewer queries running during the update now.

It updated my database correctly, so it's committed.

thill_’s picture

Status: Fixed » Needs work

Something went wrong on the update here,

user warning: 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 'WHERE order_id = 1234' at line 1 query: UPDATE uc_orders SET WHERE order_id = 1234

I got this for every single order on the update.php results page.

Island Usurper’s picture

Version: 6.x-2.x-dev » 6.x-2.0-rc4
Status: Needs work » Needs review
StatusFileSize
new0 bytes

Blarg! I think something like this happens every time we get to the 4th of the version level.

It turns out that drupal_write_record() is a very bad thing to use right after you change the schema. The schema is cached until the end of the updates, so you either have to clear the cache before you use drupal_write_record(), or just use db_query().

While I'm pretty sure I could rewrite this update to use just one query, I still think it would run for too long on sites with thousands and thousands of orders. So, I've left the queries the way they are and added batch functionality to the update. I also split the updates up since any failed updates due to timeout issues will still add the product_count column in their database.

Island Usurper’s picture

Category: feature » bug
Priority: Normal » Critical
Island Usurper’s picture

StatusFileSize
new1.49 KB

An actual patch would be good, no?

Island Usurper’s picture

Status: Needs review » Fixed

Got test results from thill_, and I got it to work on a couple of different sites. Committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.