Skip to content

Commit

Permalink
Scope shipping rates as per display_on [Fixes solidusio#3124]
Browse files Browse the repository at this point in the history
As shipping method rates set to appear only in backend should not be
displayed in frontend as well

[Fixes solidusio#3119]
  • Loading branch information
huoxito authored and GeekOnCoffee committed May 31, 2013
1 parent ed4ddcf commit 2eaa88d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/orders/_shipment.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<div class="field alpha five columns">
<%= label_tag 'selected_shipping_rate_id', Spree.t(:shipping_method) %>
<%= select_tag :selected_shipping_rate_id,
options_for_select(shipment.shipping_rates.map {|sr| ["#{sr.name} #{sr.display_price}", sr.id] }, shipment.selected_shipping_rate_id),
options_for_select(shipment.shipping_rates.backend.map {|sr| ["#{sr.name} #{sr.display_price}", sr.id] }, shipment.selected_shipping_rate_id),
{:class => 'select2 fullwidth', :data => {'shipment-number' => shipment.number } } %>
</div>

Expand Down
7 changes: 6 additions & 1 deletion core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Spree 2.1.0 (unreleased) ##

* Scope shipping rates as per shipping method display_on #3119
e.g. Shipping methods set to back_end only should not be displayed on frontend too

*Washington Luiz*

* Add `propagate_all_variants` attribute to StockLocation. It controls
whether a stock items should be created fot the stock location every time
a variant or a stock location is created
Expand All @@ -17,4 +22,4 @@

* Improve performance of `Order#payment_required?` by not updating the totals every time. #3040 #3086

*Washington Luiz*
*Washington Luiz*
8 changes: 8 additions & 0 deletions core/app/models/spree/shipping_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,13 @@ def at_least_one_shipping_category
self.errors[:base] << "You need to select at least one shipping category"
end
end

def self.on_backend_query
"#{table_name}.display_on != 'front_end' OR #{table_name}.display_on IS NULL"
end

def self.on_frontend_query
"#{table_name}.display_on != 'back_end' OR #{table_name}.display_on IS NULL"
end
end
end
3 changes: 3 additions & 0 deletions core/app/models/spree/shipping_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class ShippingRate < ActiveRecord::Base
attr_accessible :id, :shipping_method, :shipment,
:name, :cost, :selected, :shipping_method_id

scope :frontend, -> { includes(:shipping_method).where(ShippingMethod.on_frontend_query) }
scope :backend, -> { includes(:shipping_method).where(ShippingMethod.on_backend_query) }

delegate :order, :currency, to: :shipment
delegate :name, to: :shipping_method

Expand Down
2 changes: 1 addition & 1 deletion frontend/app/views/spree/checkout/_delivery.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<h5 class="stock-shipping-method-title"><%= Spree.t(:shipping_method) %></h5>
<ul class="field radios shipping-methods">
<% ship_form.object.shipping_rates.each do |rate| %>
<% ship_form.object.shipping_rates.frontend.each do |rate| %>
<li class="shipping-method">
<label>
<%= ship_form.radio_button :selected_shipping_rate_id, rate.id %>
Expand Down

0 comments on commit 2eaa88d

Please sign in to comment.