For a client I'm creating a custom report that they need to show the coupons sold for a given product in the shop.

Right now I'm stuck at the point that if I join the tables required by using the node-id, the query works, and gives the wanted results...
But... If I have a product that had already had sales and not yet had been given the feature of coupon-creation, upon activating it, all orders (from the same user) with that product in it are joined to the same coupon code...

This could be a problem if the shop-owners change a product over time, for one that as previously a physical item that would be shipped, and now is no longer, but instead an item that only triggers a coupon-code that has to be sent by e-mail.

It look's to me like the coupons are only linkable by using the node-id, whereas in some use cases there's a need to link them directly to the order.

Am I overlooking something, or is this by design, and for a good reason (which I'm not noticing ;-)) ?

Comments

wodenx’s picture

Ubercart doesn't keep track of the specific features associated with a product when it is ordered, so if you modify a product's features after it's sold, you'll have the issue you describe. uc_coupon_purchase does keep track of every coupon purchased, linked to the user who purchased it, but not linked to the order in which it was purchased. I guess this would probably be a useful feature, but not sure when I will have time to implement it. If you are writing a custom module, you could implement hook_uc_coupon_purchase() and save the information in your own table. Or, you could simply instruct your client to change the SKU for a product if they add or remove features, and use the SKU to filter your results.