Skip to content

Instantly share code, notes, and snippets.

@pranny
Created May 4, 2016 06:17
Show Gist options
  • Save pranny/691e7931e615d839492d442ef1ed85a2 to your computer and use it in GitHub Desktop.
Save pranny/691e7931e615d839492d442ef1ed85a2 to your computer and use it in GitHub Desktop.
Get variants weight in Spree
# Get all products in Spree
Spree::Product.all
# Get all variants of a single product
prod = Spree::Product.first
prod.variants
# Get the weight of a variant
v = prod.variants.first
v.weight
v.weight.class # BigDecimal
v.weight.to_i # 50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment