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

Package weight set to zero when Product and LineItem have weight #6275

Closed
brchristian opened this issue Apr 10, 2015 · 3 comments
Closed

Package weight set to zero when Product and LineItem have weight #6275

brchristian opened this issue Apr 10, 2015 · 3 comments

Comments

@brchristian
Copy link
Contributor

In the latest 2-3-master, if I open a Rails console, I can produce the following unexpected behavior:

product = Spree::Product.new(weight: 5)
line_item = Spree::LineItem.new(product: product, quantity: 1)
stock_location = Spree::StockLocation.new
order = Spree::Order.new
package = Spree::Stock::Package.new(stock_location, order)
package.add(line_item, 1)

Here's where things appear to get strange:

product.weight.to_s
=> "5.0"
product.master.weight.to_s
=> "5.0"

package.weight.to_s
=> "0.0"
package.contents[0].variant.weight.to_s
=> "0.0"

Am I missing something here? I am expecting package.contents[0].variant.weight to equal product.master.weight . . .

@JDutil
Copy link
Member

JDutil commented Apr 10, 2015

This:
https://github.com/spree/spree/blob/master/core/app/models/spree/stock/package.rb#L33

Should sum variant.weight * quantity:
https://github.com/spree/spree/blob/master/core/app/models/spree/stock/package.rb#L33

So yea that does appear to be incorrect not sure why though. My guess would be that since you haven't saved the product it's master variant isn't created yet.

@brchristian
Copy link
Contributor Author

@JDutil My hunch was also that it was coming from the fact that these records not having been persisted to the db yet. Is this worth looking into, or is it simply not designed to need to work in these cases?

@JDutil
Copy link
Member

JDutil commented Apr 10, 2015

It should work if the variant exists, which it appears to exist if you can reference the association. I have the feeling there is something funky going on with how rails is handling the association, and the record may need to be persisted for it to work properly I'm not sure.

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