简体   繁体   English

在Rails电子商务应用程序中添加自定义统一运费

[英]Add customized flat rate shipping in rails ecommerce app

Before I get started, I do have to say that I'm new to Rails and coding in general. 在开始之前,我必须说一下,我是Rails和编码方面的新手。 I have a question about adding a flat rate shipping fee to my rails app. 我有一个关于向我的rails应用程序添加统一运费的问题。 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. 我正在使用Tutsplus教程(这是源代码: https : //github.com/tutsplus/rails_store_with_braintree )构建一个电子商务应用程序,但他没有解决如何增加运费的问题。 I've googled this, but found answers mainly for Spree, Solidus, and ActiveShipping, but these don't work for me. 我已经用谷歌搜索了,但是找到了主要针对Spree,Solidus和ActiveShipping的答案,但是这些对我不起作用。 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? 你们任何人都可以在这方面帮助我吗?

I'd add a shipping fee there https://github.com/tutsplus/rails_store_with_braintree/blob/master/app/models/cart.rb#L50 我会在那儿加收运输费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. 添加一个可视化的ui元素,告诉用户多少运费。 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. 您也可以将运输费用放入数据库中,以便更轻松地进行更新等。祝您好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM