I have just spent a few minutes working out exactly how the discount fields work in product kits, and there are a couple of problems.

Basically, it doesn't make sense to combine a price field and a discount field into one, and even if you do, it isn't implemented properly. Here is my suggestion. Lookup the price of that product when it is added to the kit, and show it off to the side somewhere. Then allow the user to either enter a relative price change which could be positive or negative, or an absolute price. This could be two fields, and if the absolute price is set, the relative price change is ignored. Or it could be one field with a radio button specifying whether it is absolute or relative.

But, if you leave it like it is, there is actually a bug. I don't want to discount the price at all, so I set the discount to zero. The note that I finally noticed underneath says that positive numbers become actual prices rather than discounts. Zero is not positive--at least not in my book :-), but it is treated as the price. In other words, it discounts it 100%, even though I set the discount to 0.

I hope that helps.
-Joseph

Comments

rszrama’s picture

Assigned: Unassigned » Island Usurper
Island Usurper’s picture

Status: Active » Needs review
StatusFileSize
new2.23 KB

How important is the absolute value discount to people? It's fairly simple to just allow relative price adjustments, as this patch demonstrates. Are there any actual benefits to fixing the price of the kit to a certain amount?

rszrama’s picture

I think so. Being able to just throw a few products together and say "This all for $25!" is a big win, esp. if you don't have to do the math to discount component products to the right value and keep up with that if the individual product prices fluctuate.

Island Usurper’s picture

Status: Needs review » Needs work

Well then, I guess I'll have to figure out a different interface. Maybe there can be a separate price field for the entire product kit, and if it's left blank, it adds up the individual component prices with their adjustments. Should there be an explicit checkbox to control this behavior or not? I'd like to make it simple and as idiot-proof as possible.

cha0s’s picture

I think your idea is good, though I don't think a checkbox is necessary. If the 'total' or some such field is set at all, it would override the component prices... Seems easy enough to make clear in the #description.

jtbayly’s picture

I also think that absolute pricing is beneficial.

As for the interface, I'd say that the checkbox might be a good idea. However, I could see it going either way.

-Joseph

Island Usurper’s picture

Status: Needs work » Needs review
StatusFileSize
new5.78 KB

I've added a "Total price" text field to the product kit form. It's empty by default because the discounts need to be stored with the component products. When a value is entered into this field, the update function calculates the discount value of each product, taking its quantity and relative price into account. More expensive products will get proportionally higher discounts.

Island Usurper’s picture

Status: Needs review » Needs work

Product kits now always update their price when their components' prices change, even if we set it with a total price beforehand. I'll have to mark the set-priced kits somehow.

Island Usurper’s picture

Status: Needs work » Needs review
StatusFileSize
new9.46 KB

Now the patch adds a column to uc_product_kits called "synchronized", which is a boolean flag to update the kit price when true. It's supposed to have the same value for all products in the kit, so don't be changing it manually.

rszrama’s picture

The update function misspells synchronized as syncronized. I fixed this, but I'm not sure what I'm supposed to do to test this patch...

rszrama’s picture

StatusFileSize
new9.47 KB

Ok, created a kit, and it set the product price properly initially. However, upon going in to edit the kit to adjust the total price, I see that the default total is doubled. It also automatically sets the discount to "plus the kit price." Might need to review the defaults on the product kit form. I've attached my patch w/ the typo fixed.

rszrama’s picture

Status: Needs review » Needs work
Island Usurper’s picture

Status: Needs work » Needs review
StatusFileSize
new10.52 KB

uc_product_kit_insert() hadn't been updated for the new discount paradigm, so it was being set in the database that way when the kit was first made.

Patch fixes this and a few other problems.

cha0s’s picture

Status: Needs review » Needs work

Hey, I tested this patch.

The prices look good on the node page (although setting the kit_total to some value that can't be divided equally into the amount of products in the kit looks a little weird, but appears to function when viewing the node), however once you get to checkout the prices are wrong. I tried setting individual discounts and setting the kit_total, neither appeared to work correctly.

Island Usurper’s picture

I must be bad at picking test data. I haven't even seen any rounding errors, though that's probably because those price fields allow up to three decimal places now.

Can you show me what numbers you put in?

Island Usurper’s picture

Version: 6.x-2.0-beta2 » 6.x-2.x-dev
Status: Needs work » Needs review
StatusFileSize
new10.01 KB

There were some issues with updating the prices of the component products, so here's a new patch.

rszrama’s picture

Status: Needs review » Needs work

The code works well as far as I can see, but the rounding needs to be fixed to two decimal places or something. It's pretty unwieldy getting automated adjustments of -4940.1018268943. : )

After that, I'd say this is good to go!

Island Usurper’s picture

Status: Needs work » Fixed
StatusFileSize
new10.07 KB

Alright then. Discount amounts are being rounded to 3 digits, for much the same reasons that other prices are allowed to have that many.

Thanks for the reviews.

Island Usurper’s picture

Status: Fixed » Needs review
StatusFileSize
new933 bytes

Despite already committing #18, there's still a bug when the total kit price is set to something more than the sum of the individual product kits. In the cart, the product kits have a price much lower than intended because there was some leftover logic that is used when the discount actually increases the product price.

Simple patch to remove that if/else block is attached.

Island Usurper’s picture

Status: Needs review » Fixed

Probably should have committed this earlier, but those who are still on the beta5 will need to apply the patch themselves to have kits that put price increases on their component products. Hopefully that's not something that happens a whole lot.

Status: Fixed » Closed (fixed)

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