isotope / core

Core repository of Isotope eCommerce, an eCommerce extension for Contao Open Source CMS
https://isotopeecommerce.org
135 stars 107 forks source link

Convert shipping weight to "readable" value #1720

Open aschempp opened 7 years ago

aschempp commented 7 years ago

I came up with the idea to use load_callback and save_callback to save the shipping weight as readable value (e.g. 1,kg or just 1 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. store it as 1,kg (comma separated values, better to use FIND_IN_SET, e.g. to get all with kg) or store it as 1 kg, human readable value. Because neither the value nor the unit can contain white space or comma, both would be no problem.
  2. should the value be converted to a generic value? Like store all values in KG in the database so the shipping weight is actually sortable? would sorting be easier with 1 kg and just CAST (so that the string will be dropped)?

@Toflar @qzminski please let me know your thoughts.

qzminski commented 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.

Toflar commented 7 years ago

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?).

qzminski commented 7 years ago

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?

qzminski commented 7 years ago

Forget my last comment, I was thinking about the other thing (decimal quantity) 😄

aschempp commented 7 years ago

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.

HenryVolkmer commented 7 years ago

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