1

Before I get started, I do have to say that I'm new to Rails and coding in general. I have a question about adding a flat rate shipping fee to my rails app. I'm building an ecommerce app with the Tutsplus tutorial (here's the source code: https://github.com/tutsplus/rails_store_with_braintree), but he didn't go over how to add a shipping fee. I've googled this, but found answers mainly for Spree, Solidus, and ActiveShipping, but these don't work for me. I don't want to calculate shipping because I'm charging a flat rate regardless of location or the amount of products in the cart. Can any of you help me in this area?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
TheoNov18
  • 13
  • 3

1 Answers1

0

I'd add a shipping fee there https://github.com/tutsplus/rails_store_with_braintree/blob/master/app/models/cart.rb#L50

something like this

def shipping_fee
  5.00
end

def total_price
  total = @items.inject(0) { |sum, item| sum + item.total_price }
  total + shipping_fee
end

Add a visual ui element that tells the user how much shipping will be. I could go on about tests and about not using floats for money but that isn't really the primary goal of this project. Also you could put shipping fee in the database to make more easily updatable etc. Good luck.

Gregory Ostermayr
  • 1,123
  • 10
  • 17