Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unit_multiplier cannot be decimal + possible documentation bug #188

Open
traboukos opened this issue May 20, 2014 · 6 comments
Open

unit_multiplier cannot be decimal + possible documentation bug #188

traboukos opened this issue May 20, 2014 · 6 comments

Comments

@traboukos
Copy link
Contributor

Hi,

I am trying to use ups shipping calculators with the Spree 2.0 branch and weight units in grams and I am having some problems. The documentation in the README states.

It is important to note that by default this variable is set to have a value of 16 expecting weights to be entered in lbs

Say you have your weights in kg you would have to set the multiplier to 0.0283495

Spree::ActiveShipping::Config[:unit_multiplier] = 0.0283495

If I have product weights in lbs the multiplier should be 16. 1 lbs is equal to 16 oz. According to the previous sentence if my weights are in kilos then the multiplier should be 35.274 since 1 kg is equal to 35.274 oz. However the example in the documentation uses a multiplier of 0.0283495 which is the inverse. It is actually converting from oz to kg.

Furthermore and to the actual problem decimals cannot be entered in the multiplier value due to the fact that unit_multiplier is defined as an integer property.
https://github.com/spree/spree_active_shipping/blob/master/lib/spree/active_shipping_configuration.rb#L18

In my case I store my product weights in grams so my multiplier should be 0.035274.

@mrpollo
Copy link
Contributor

mrpollo commented May 20, 2014

I can confirm the unit_multiplier should allow decimals to enable conversions from other units other than pounds, would you be able to send a PR to fix this preference and the README?

@traboukos
Copy link
Contributor Author

I seem to have fixed it locally by overriding the files in my application. I will be glad to send a pull request but there is another issue. Making the field decimal is not enough since decimal preferences in Spree are rounded to 2 places. In order for this to be able to work I had to override Spree::Preferences::Preferable and Spree::Preference classes that both convert the value to the respective type and allow room for 8 digits.

@mrpollo
Copy link
Contributor

mrpollo commented May 21, 2014

@traboukos see spree/spree#4719

@mrpollo
Copy link
Contributor

mrpollo commented May 21, 2014

BTW can you submit a PR for the README? , nice find, thanks!

@dpmccabe
Copy link

It looks like the documentation is still wrong. Still says 0.02... for the kg conversion when it should be 35. Or am I'm confused?

@jspizziri
Copy link
Member

@mrpollo, did this ever get fixed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants