Post by Qphoria » Wed Sep 03, 2008 4:42 am

This contrib adds a weight_factor to a product’s options. Each option multiplies its weight_factor against the base product weight to calculate the total product weight in the cart. For example:

Product A = 5lbs
-> Class:
----> X (weight_factor = 1.25)
----> Y (weight_factor = 1.75)
-> Size:
----> Medium (weight_factor = 0.5)
----> Large     (weight_factor = 1.5)


If you choose Product A with Class X and Size Large. The result is:
(5 * 1.25)  = 6.25
(5 * 1.5)    = 7.5
6.25 + 7.5 = 13.75

Or simply:
5 * (1.25 + 1.5) = 13.75lbs

If you choose Product A with Class X and Size Medium. The result is:
(5 * 1.25)  = 6.25
(5 * 0.5)    = 2.5
6.25 + 7.5 = 8.75

Or simply:
5 * (1.25 + 0.5) = 8.75lbs

Features:
- Option Weight Factor affects the total product weight in the cart. This makes it transparent to all weight-based shipping modules and no other updates are needed for them to support option weight.
- Supports all OpenCart weight classes (Pounds, Ounces, Kilograms, etc) (lb, oz, kg, etc).
- Options on product page will show price and pre-calculated +/- weight. (e.g. a weight factor of 1.5 on a 5lb product will show +0.5lb in the option drop down)
- Does weight conversion if Store weight class is set to a different value than the product weight class (e.g. Store in kg, product in lbs. 5lbs will show up as 2.27kg on the product page)
- Formatted to work with the Import/Export Contrib created by JNeuhoff. The Import/Export contrib. already has support for this new field.


To test the demo:
1.  Goto the Demo site. (product 1 is a 2lb product)
2.  Play with the options. Note the weight information on each option
3.  Add the item to the cart
4.  Verify the "Total Cart Weight" shows the correct weight.
(Note: The "Total Cart Weight" is a separate contrib that I made to help test this. But I haven't released it yet. )

DEMO
DOWNLOAD

Credits to JNeuhoff for the weight_factor idea instead of my original idea of creating separate weights per option

Enjoy
Q!
Last edited by Qphoria on Wed Sep 24, 2008 8:38 am, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by JNeuhoff » Wed Sep 03, 2008 5:06 pm

Excellent! That was quick!

Have you tested it with the Export/Import module, too?

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Qphoria » Wed Sep 03, 2008 7:13 pm

Yes indeed! Works as expected :)

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Wed Sep 03, 2008 10:34 pm

VERSION 0.2 RELEASED

-Fixed a bug where if a product had no options, it would attempt to multiply the product weight by zero.
----The only change is the library/cart/cart.php file.

DOWNLOAD
Last edited by Qphoria on Thu Sep 04, 2008 1:15 am, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by jty » Thu Sep 04, 2008 12:51 am

That was very quick.
If only I was as clever as you  :)
Thank-you

jty
Active Member

Posts

Joined
Sat Aug 30, 2008 8:19 am

Post by Qphoria » Sat Sep 06, 2008 2:31 am

VERSION 0.3 RELEASED

- Fixed a bug during the checkout confirm callback process. The cart serializes the data to be saved during the payment process, and then retrieves the info when the payment processer returns. It did not know how to retrieve weight_factor as it was not included with the serialized data.
---- The only change is the new catalog/controller/checkout_confirm.php file.

DOWNLOAD

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Wed Sep 24, 2008 8:40 am

VERSION 0.5 RELEASED

NEW FEATURES!

Added Option stock level and decrement abilities. Now options will use their own stock levels. If there the quantity in stock is 0, it will not show up in the list of options for the products.

Features:
- Separate stock levels for each option
- Separate stock decrement setting for each option
- Completely configurable from the Admin area.

DOWNLOAD

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by JNeuhoff » Thu Sep 25, 2008 12:50 pm

If you choose Product A with Class X and Size Medium. The result is:
(5 * 1.25)  = 6.25
(5 * 0.5)    = 2.5
6.25 + 7.5 = 8.75

Or simply:
5 * (1.25 + 0.5) = 8.75lbs
I don't want to spoil the party, but I think this needs a corection. For example:

Product X (weight = 5lb)

Option Size:
  Medium (1, the default) 
  Small (0.5) 
  Large (1.5)
Option Grade:
  Normal (1, the defult) 
  Light (0.5)
  Heavy (1.5)

If the customer chooses Product X with lets say the options Size=Small and Grade=Heavy then the following final weight is to be used for the checkout:

Product weight 5lb * 0.5 (from Size=Small) = 2.5lb
2.5lb * 1.5 (from Grade=Heavy) = 3.75lb

Or in summary:
Final weight = Product weight * (factor1 * factor2)

and NOT:
Final weight = Product weight * (factor1 + factor2)

Admittedly, it is quite rare to have products with two options influencing the weight, however, the above example shows that it can happen. We had a store selling timber flooring where both timber size and timber grade could influence the final weight.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Qphoria » Thu Sep 25, 2008 6:43 pm

Originally I had that equation but kept telling myself that was wrong. The thinking is that the factor is based off of the product weight at an individual level, not off the weight a previously refactored weight

I think your example shows an even more unlikely option here, and that is an option to reduce the weight of the original product. Like we said before, with the exception of selling Helium tanks online, you would rarely be going down in weight. If size small is 0.5 factor, then your original product weight should be set to the smallest possible weight, and the factors of each option should be added on top of it.

So in your example (and maybe my example was confusing too):
Product X (weight = 5lb)

Option Size:
  Medium (1, the default) 
  Small (0.5)    

  Large (1.5)
Option Grade:
  Normal (1, the defult)
  Light (0.5)

  Heavy (1.5)
The base product should've been declared at its lowest possible level first, then the weights would only increase

Product X weight = 2.5lbs
size:
Small (1, default)
Medium (1.25)
Large (1.5)

etc.

Granted, that is an ideal and maybe not how the thought process is for everyone. But the thinking is for accessories:

Computer: 5lbs
Additional battery (1.2) (+1lbs)
Carrying Case (1.2) (+1lbs)

Which actually does show my calculations are incorrect as well as I'm expecting it to be 5+1+1 = 7lbs
but
5 * (1.2 + 1.2) = 12

It should be 5 + ((5*1.2-5)) + ((5*1.2-5))

or

PW = Product Weight
OW1 = Option Weight1
OW2 = Option Weight2

Total = PW + ((PW * OW1) - PW) + ((PW * OW2) - PW)

But I just woke up and I'm still half asleep so none of this may make any sense to me by the time I get to work....

So.. To be continued... :)
Last edited by Qphoria on Thu Sep 25, 2008 6:45 pm, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Thu Sep 25, 2008 9:19 pm

Ok, I've had my coffee....

Now, to try the new equation with the "helium test":
Helium Tank : 5lb

Tank Size:
- Small (0.5)
- Med (1, default)
- Large (1.5)

Fill qty:
- Empty (1, default)
- Half-full tank (0.75)
- Full tank: (0.5)

Medium+Empty tank:
Total = 5 + ((5 * 1) - 5) + ((5 * 1) -5)
Total = 5 + (0) + (0)
Total = 5 + 0
Total = 5lbs <-- Correct (No weight change since both options were a factor of 1)

Medium+half-full tank:
Total = 5 + ((5 * 1) - 5) + ((5 * 0.75) -5)
Total = 5 + (0) + (-1.25)
Total = 5 - 1.25
Total = 3.75lbs <-- Correct (option1 is a wash and option2 takes off 25% of the weight)

Large+full tank:
Total = 5 + ((5 * 1.5) - 5) + ((5 * 0.5) -5)
Total = 5 + 2.5 + (-2.5)
Total = 5 + 0
Total = 5lbs <-- Correct (since option1 adds .5 and option 2 removes .5)

Small+full tank:
Total = 5 + ((5 * 0.5) - 5) + ((5 * 0.5) -5)
Total = 5 + (-2.5) + (-2.5)
Total = 5 - 5
Total = 0lbs <-- Correct (though likely no store will ever factor products to reduce the weight to 0, which is why they product should always be priced at its minimum and let the options increase the weight)

Assuming my math is correct (which is a dangerous assumption). Does this make better sense now?

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by JNeuhoff » Thu Sep 25, 2008 11:53 pm

As regards your formula:
Total = PW + ((PW * OW1) - PW) + ((PW * OW2) - PW)
It won't work for my example. The weight_factor is a factor, NOT a weight! Hence the formula should be:

Total weight = (PW * WF1) * WF2

where PW=Product weight, WF1=weight_factor for Option1, WF2=weight_factor for Option2

In your helium example, it would be as follows: (Assuming a full tank reduces the product weight (that of the tank itself) by half!)

Medium+Empty tank
Total weight = (5lb * 1) * 1 = 5lb

Medium+half-full tank:
Total weight = (5lb * 1) * 0.75 = 3.75lb

Large+full tank:
Total weight = (5lb *1.5) * 0.5 = 3.75lb

Small+full tank:
Total weight = ((5lb * 0.5) * 0.5 = 1.25lb


Or in my other example of the timber-flooring store:

Product Jarrah wood: 5kg

Option Size:
  1,000 mm * 250 mm (default weight_factor 1)
  1,000 mm * 125 mm (weight_factor 0.5)
  1,000 mm * 75 mm (weight_factor 0.25)
Option Thickness
  10 mm (default weight_factor 1)
   5  mm (weight_factor 0.5)
  20 mm (weight_factor 2)
  30 mm (weight_factor 3)

If the customer chooses the Size-option 1,000 mm * 125 mm and the Thickness option 30 mm then the total weight for the checkout is: Total_weight = (5kg * 0.5) * 3 = 7.5 kg

And yes, in our timber-store it frequently happens that options reduce the original product weight, because these guys prefer to sell the bigger quantities by default  :)


However, for your computer store example the correct formula would be indeed:

  total_weight = PW + ((PW * WF1)-PW) + ((PW * WF2)-PW)

Computer: 5lbs
  Option With Batteries:
    No batteries (default weight_factor 1) (+ 0lbs)
    Additional batteries (weight_factor 1.2) (+1lbs)
Option With Carrying Case:
    No Carrying Case (default weight factor 1) (+0 lbs)
    Carrying Case (weight_factor 1.2) (+1lbs)
   
If the customer chooses the Product Computer (5lbs) with the Batteries and the Carrying Case, the then total checkout weight is:
  total_weight = 5lbs + (5lbs * 1.2 - 5lbs) + (5lbs *1.2 - 5lbs) = 7lbs


I guess, we'll need another DB field specifying which weight formula is to be used for a given product! And if we do that, we might introduce another field called product_to_option.weight_operator with the possible values '*', '+', '-'

If the weight_operator='*' use the formula TW=PW*WF1*WF2...*WFn
If the weight_operator='+' use the formula TW=PW+(PW*WF1-PW)+(PW*WF2-PW)....+(PW*WFn-PW)
If the weight_operator='-' use the formula TW=PW-(PW*WF1-PW)-(PW*WF2-PW)....-(PW*WFn-PW)

What do you think?
Last edited by JNeuhoff on Fri Sep 26, 2008 12:41 am, edited 1 time in total.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by JNeuhoff » Fri Sep 26, 2008 12:48 am

Actually, your computer store example should look like this:

  total_weight = PW + PW * WF1 + PW * WF2

Computer: 5lbs
  Option With Batteries:
    No batteries (default weight_factor 0) (+ 0lbs)
    Additional batteries (weight_factor 0.2) (+1lbs)
Option With Carrying Case:
    No Carrying Case (default weight factor 0) (+0 lbs)
    Carrying Case (weight_factor 0.2) (+1lbs)
   
If the customer chooses the Product Computer (5lbs) with the Batteries and the Carrying Case, the then total checkout weight is:
  total_weight = 5lbs + (5lbs * 0.2) + (5lbs *0.2) = 7lbs


I guess all of this is higher shopping cart math, I have to ponder over it a bit more when I am fully awake again, have been up since 4:30am ....
Last edited by JNeuhoff on Fri Sep 26, 2008 12:58 am, edited 1 time in total.

Export/Import Tool * SpamBot Buster * Unused Images Manager * Instant Option Price Calculator * Number Option * Google Tag Manager * Survey Plus * OpenTwig


User avatar
Guru Member

Posts

Joined
Wed Dec 05, 2007 3:38 am


Post by Qphoria » Fri Sep 26, 2008 2:08 am

JNeuhoff wrote: Actually, your computer store example should look like this:

  total_weight = PW + PW * WF1 + PW * WF2

Computer: 5lbs
  Option With Batteries:
    No batteries (default weight_factor 0) (+ 0lbs)
    Additional batteries (weight_factor 0.2) (+1lbs)
Option With Carrying Case:
    No Carrying Case (default weight factor 0) (+0 lbs)
    Carrying Case (weight_factor 0.2) (+1lbs)
   
If the customer chooses the Product Computer (5lbs) with the Batteries and the Carrying Case, the then total checkout weight is:
  total_weight = 5lbs + (5lbs * 0.2) + (5lbs *0.2) = 7lbs
I think that is maybe where I got confused this morning in my equation too. tho the equation is the same value
((5*1.2)-5) is the same as 5*0.2, just with my fuzzy math  :P.

For your equation
Total weight = (PW * WF1) * WF2
You are requiring Option1 to exist before multiplying an additional multiplier
So if WF1 was 0...
(5 * 0) * 1.5 = 0 no matter what WF2 is.
What if there is a WF3? Would it depend on the previous options?
((((PW * WF1) * WF2) * WF3) * ..... * WFn)?

Options, the way they are implemented are more or less individual from each other.
The equation you are using for the flooring thickness is a dependent  on the size option. But really that would be a sub-option of Option 1, which I guess is a way of thinking outside-the-box for options. But yea perhaps the equation selection is necessary per option, per product to decide if you are using the individual method or the dependent method.

Way to crack open that can of worms!
http://www.unbannable.com/avatar.gif[/img]
Last edited by Qphoria on Fri Sep 26, 2008 2:30 am, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by jty » Sun Oct 05, 2008 10:08 pm

I think I broke it  :(
Problem with OptionWeight+Stock_v0.5 and Zone Based Shipping - Incorrect Shipping Calculation
To replicate;
Fresh install of Opencart 0.7.8, apply OptionWeight+Stock_v0.5 but no other mods
Configure to use zone based shipping with shipping cost of 500:7,20000:12
Only using Grams (g)

Test 1
Configure Product 2 - Green Motorbike to have weight of 499 (g)
Product 2 has no options
Add to cart 1 unit > correct shipping of $7
Add to cart of 2 units or more > incorrect. Shipping = $0.00

Test 2
Configure Product 3 to have one option
Product 3 weight = 499, Option weight = 0 or 1 (both give same results)
Add 1 unit to cart > Shipping is $7. Correct
Add 2 units > zero shipping. Incorrect
Add 3 or more units and Shipping is $7. Better than zero but should be $12 as over 500g

jty
Active Member

Posts

Joined
Sat Aug 30, 2008 8:19 am

Post by Qphoria » Sun Oct 05, 2008 10:11 pm

Stop breaking stuff!  ;) I'll take a look

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by jty » Mon Oct 06, 2008 9:25 pm

I tried to do further testing but still no joy
What I did discover is that I needed to apply Bruce's Bug Fix: Weight Conversion to get the cart weight correct.
For some strange reason adding 2 units gives a shipping of zero. Only "2".
1unit gives correct shipping, 3 or more gives incorrect shipping but not zero.
Wonder why 2 units result in zero shipping  ???

I give up  :'(
I shall wait until 0.7.9 comes out hoping the problem will magically disappear :o

jty
Active Member

Posts

Joined
Sat Aug 30, 2008 8:19 am

Post by Qphoria » Mon Oct 06, 2008 9:29 pm

Yes 0.7.9 will apply a fix similar to bruces that fixes the weight problem. However, based on some posts above this one, there are still a few more calculation changes that need to be made. I will address those today.

However, I am still unsure of the best way to handle JNeuhoff's request for handling "Serial dependent options". So the changes I make will only affect the existing structure of "Parallel dependent options" (meaning the options are based on the main product individually, not based on the product and other option values)

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by jty » Mon Oct 06, 2008 10:30 pm

I don't know what serial and parallel dependent option means
I'm a dumb dumb user  ::) but I do know that I am very happy with the current design and I was most impressed that you added the hide-option-when-no-stock and stock decrease per option

Regarding the above shipping issue, I also discovered that units of 13 and above give zero shipping like 2 units do. My product had no options, weight is 499g with shipping cost set per my above example ie 500:7,20000:12

But now I think you're not going to like me cos I think I broke it again. I'm sorry  :'(
This next issue deals with stock decrease
When products are purchased, the stock for both the product and the option is reduced.
Great, but the unit of stock for the option is reduced by 1 irrespective of how many units were purchased.
For example:
Product Stock = 10
Option Stock = 6
Buy units = 2

Expected result is Stock for Product should be 8 and option should be 4
But option stock only decreases by 1 unit so it shows 5 instead of 4

-------------
Another issue, this is more an enhancement request rather than a bug
Stock control is currently done on the product level and not the option level which means a customer can purchase more than the option's stock

eg. Have a T-Shirt with 2 colours - blue and green.
Set T-Shirt Product stock = 10
Blue Option Stock = 6
Green Option Stock = 4

Customer can place an order for 10 units of green even though there are only 4 units available
Cuz stock control is on the product level and not the options level

These stock issues aren't important to me. I won't be using stock control but I thought I would keep testing to see if I can break anything else while waiting for 0.7.9
I'm sorry  8)

jty
Active Member

Posts

Joined
Sat Aug 30, 2008 8:19 am

Post by Qphoria » Mon Oct 06, 2008 11:07 pm

jty wrote: I don't know what serial and parallel dependent option means
I'm a dumb dumb user  ::) but I do know that I am very happy with the current design and I was most impressed that you added the hide-option-when-no-stock and stock decrease per option
Not to worry. It just means that the current way I implemented the option weight is for each option to individually factor itself against the product weight. As opposed to the options relying on other options
For example:
(Product 1 * Option 1) + (Product 1 * Option 2) = Total Option Weight (Parallel: each option relies only on the base product)
instead of
(Product 1 * Option 1) * Option 2) = Total Option Weight (Serial: subsequent options rely on the previous option's calculation)
jty wrote: Regarding the above shipping issue, I also discovered that units of 13 and above give zero shipping like 2 units do. My product had no options, weight is 499g with shipping cost set per my above example ie 500:7,20000:12
Will be sure to test qty's from 1 to 100
jty wrote: But now I think you're not going to like me cos I think I broke it again. I'm sorry  :'(
This next issue deals with stock decrease
When products are purchased, the stock for both the product and the option is reduced.
Great, but the unit of stock for the option is reduced by 1 irrespective of how many units were purchased.
For example:
Product Stock = 10
Option Stock = 6
Buy units = 2

Expected result is Stock for Product should be 8 and option should be 4
But option stock only decreases by 1 unit so it shows 5 instead of 4
Hmm I thought I fixed that.. Ill take a look

jty wrote: -------------
Another issue, this is more an enhancement request rather than a bug
Stock control is currently done on the product level and not the option level which means a customer can purchase more than the option's stock

eg. Have a T-Shirt with 2 colours - blue and green.
Set T-Shirt Product stock = 10
Blue Option Stock = 6
Green Option Stock = 4

Customer can place an order for 10 units of green even though there are only 4 units available
Cuz stock control is on the product level and not the options level
Ah, yea that is a good point. I'll see if it can be done .

Thanks for all your help testing this :)

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Tue Oct 07, 2008 5:51 am

JNeuhoff wrote: I guess, we'll need another DB field specifying which weight formula is to be used for a given product! And if we do that, we might introduce another field called product_to_option.weight_operator with the possible values '*', '+', '-'

If the weight_operator='*' use the formula TW=PW*WF1*WF2...*WFn
If the weight_operator='+' use the formula TW=PW+(PW*WF1)+(PW*WF2)...+(PW*WFn)
If the weight_operator='-' use the formula TW=PW-(PW*WF1)-(PW*WF2)...-(PW*WFn)

What do you think?
Ok, my brain is starting to work again. I think I might know where to start on this now. I had previously been treating the option weight as a value separate from the product weight, which worked for the '+' method. but the '*' method would actually affect the base product weight, so it wouldn't be adding an option weight, it would be the resultant weight after options were applied to it.

So assuming I understand that to be the correct concept, I have taken steps to add that as the product weight.

Code: Select all

$tw = $product['weight']; //They all start with the base product weight
foreach ($options as $option) {
    switch($mode) {
        case '+'  : $tw += ($product['weight'] * $option['weight_factor']); // Accessory mode
        case '-'  : $tw -= ($product['weight'] * $option['weight_factor']); // Helium mode
        case '*'  : $tw *= $option['weight_factor']; // Flooring mode
    }
}
I believe that would yield:
'+' -> $product['weight'] + ($product['weight'] * $option['weight_factor']).... + ($product['weight'] * $option['weight_factor'])
'-' -> $product['weight'] - ($product['weight'] * $option['weight_factor']).... - ($product['weight'] * $option['weight_factor'])
'*' -> $product['weight'] * $option['weight_factor'].... * $option['weight_factor']

Am I getting warmer?
Last edited by Qphoria on Tue Oct 07, 2008 11:04 am, edited 1 time in total.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 2 guests