Open aschempp opened 7 years ago
Is there no way we could store the value and unit in their own columns? That would be way easier to use and should be pretty ease to handle with callbacks as well.
I can't see why anyone would want to filter for everything in kg
. I think if you want to filter you want to know what products (or what combination of products) weigh more than e.g. 2 kg. So, imho no need to split up units and and values. Moreover, I guess we should convert and store the smallest unit (I guess mg
?).
Regarding the unit conversion to the smallest possible that can't work. How do you know if I am not going to sell micrograms of my product?
Forget my last comment, I was thinking about the other thing (decimal quantity) 😄
Well I also thought about the range filter 😉 Splitting it up would not be neccessary as the DB would be able to cope with "1 kg" and just ignore the string text as far as I know.
create a "base_uom"-field (e.g. "kg") in Storeconfig and store only the multiplier to this base_uom (uom = unit of measure). For a product with a unit of "KG", store value "1", for a product with a unit of "gramm" store '0.001'.
For Listings, use something like
SELECT SUM(product.weight*uom_multiplier*quantity) as weight
For appendix use the String "base_uom" (KG,t,gramm,foo).
Benefits: a) user have full controll over different weights and the uom's b) APIs of logistic-providers (DHL,Hermes,UPS,Schenker...) have different needs on submission of weights, it would be easy to handle c) in listings/reports: show all in base_uom and/or product_uom
I came up with the idea to use
load_callback
andsave_callback
to save the shipping weight as readable value (e.g.1,kg
or just1 kg
) in the database. Conversion would be easy (explode(',', $value)
), and the advantage would be that the value is actually useable in the database, e.g. for filtering.I have two things though:
1,kg
(comma separated values, better to useFIND_IN_SET
, e.g. to get all withkg
) or store it as1 kg
, human readable value. Because neither the value nor the unit can contain white space or comma, both would be no problem.1 kg
and just CAST (so that the string will be dropped)?@Toflar @qzminski please let me know your thoughts.