-
Notifications
You must be signed in to change notification settings - Fork 0
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
Custom calculator #12
base: monterail
Are you sure you want to change the base?
Conversation
# Conflicts: # app/models/spree/product_decorator.rb # app/views/spree/admin/vendors/_form.html.erb # db/seeds/002_spree.rb
x = distance.order.variants.all.count | ||
|
||
for b in 0...x do | ||
total_weight = distance.order.variants.map do |all| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
total += Geocoder::Calculations.distance_between(final_location, start) | ||
|
||
store_collection_charge = -0.5 | ||
vendors.map { |store_charge| store_collection_charge += 0.5 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
end | ||
|
||
total = total + store_collection_charge | ||
total_price = (total * total_load) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(base_amount + store_collection_charge) * total_weight_factor
def total_product_weight(package) | ||
total_weight = 0 | ||
|
||
total_weight = package.order.variants.map do |variant| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use inject/reduce here
|
||
total_distance += Geocoder::Calculations.distance_between(package.stock_location.to_coordinates, vendor_co[0]) | ||
|
||
vendor_co[0...-1].each_with_index do |val, index| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://til.hashrocket.com/posts/52tcyljcgl-reducing-with-an-index-in-ruby
I think you can extend vendor_coordinates array in a way you won't have to calculate, total_distance, outside this loop.
|
||
def store_collection_charge(package) | ||
vendor_co = vendors_coordinates(package) | ||
vendor_co.inject(-0.5) { |sum, number| sum + 0.5} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be a one-liner vendors_coordinates(package).inject(-0.5) { |sum, number| sum + 0.5}
end | ||
|
||
def compute_store_distance(package) | ||
binding.pry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls remove it
milage_price_band = preferred_base_amount_up_to_9_mi | ||
end | ||
|
||
scc = store_collection_charge(package) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls avoid using abbreviations
total_weight = 1.4 | ||
end | ||
|
||
total_price = (milage_price_band * total_weight) + scc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need total_price
at all.
(milage_price_band * weight_factor) + store_collection_charge(package)
total_weight = 1.2 | ||
when 36..50 | ||
total_weight = 1.4 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are not interested about total_weight
but about weight_factor
, I would move this logic to the separate method
milage_price_band = preferred_base_amount_up_to_6_mi | ||
when 6.0..9 | ||
milage_price_band = preferred_base_amount_up_to_9_mi | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here total_distance
is irrelevant, what's important is milage_price_band
, based on total_disatance you fit this value into ranges receiving what interests you the respective price for this range. When distance is out of range an error should be raised.
Description
Please, provide here a short description.
Consider including things like:
to achieve the expected result if any
Checklist
Before you move on, make sure that:
WIP
label to indicate that state