Skip to content

Commit

Permalink
Enables: Coupon code entering within cart screen
Browse files Browse the repository at this point in the history
* Coupon code entering within cart screen.
* Coupon code success message.
* Fix: order completion without shipping costs.
  • Loading branch information
buddhi-desilva committed Feb 13, 2012
1 parent f71e91b commit ffe9f96
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions promo/app/controllers/spree/checkout_controller_decorator.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ def update
end end
end end


# In an instance the coupon code is entered from the cart, if the adjustment is higher than
# the order total before shipping (e.g: order total: 10 and adjustment is 10.01), order gets
# completed without shipping cost calculations, thus skipping the payment screen. Checks for
# such instances and updates the adjustment totals after creating shipment. May not be the
# best solution and might need a different approach. Yet, this takes care of the issue.
if params[:order][:shipping_method_id] && @order.payment_state == 'paid' && @order.state == 'delivery'
@order.create_shipment!
@order.update!
end

if @order.next if @order.next
state_callback(:after) state_callback(:after)
else else
Expand Down
25 changes: 25 additions & 0 deletions promo/app/controllers/spree/orders_controller_decorator.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,25 @@
Spree::OrdersController.class_eval do
def update
@order = current_order
if @order.update_attributes(params[:order])

if @order.coupon_code.present?
if Spree::Promotion.exists?(:code => @order.coupon_code)
fire_event('spree.checkout.coupon_code_added', :coupon_code => @order.coupon_code)
flash[:notice] = t(:coupon_code_added)
# If it doesn't exist, raise an error!
# Giving them another chance to enter a valid coupon code
else
flash[:error] = t(:promotion_not_found)
render :edit and return
end
end

@order.line_items = @order.line_items.select {|li| li.quantity > 0 }
fire_event('spree.order.contents_changed')
respond_with(@order) { |format| format.html { redirect_to cart_path } }
else
respond_with(@order)
end
end
end
1 change: 1 addition & 0 deletions promo/config/locales/en.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ en:
advertise: Advertise advertise: Advertise
coupon: Coupon coupon: Coupon
coupon_code: Coupon code coupon_code: Coupon code
coupon_code_added: Coupon code added
editing_promotion: Editing Promotion editing_promotion: Editing Promotion
events: events:
spree: spree:
Expand Down

0 comments on commit ffe9f96

Please sign in to comment.