vendredi 24 juillet 2015

How to give condition for discount coupon for maximun usage limit to 2

I want to apply discount only two times(ie; i had a columun in my database with max_discount_usages =2)how to apply in code?if a user uses more than two times it should show already applied error

now a user can apply as much times for discount it sould be limited to 2 times.

Please help

cart_controller.rb

def apply_discount if DiscountCoupon.find_by_code params[:coupon_code] response = @cart.apply_discount params[:coupon_code] redirect_to :back, notice: response else response = @cart.apply_gift_card params[:coupon_code] if response redirect_to :back, notice: 'Discount applied.' else redirect_to :back, alert: 'Invalid discount code!' end end end

this is my show.html.erb

.col-sm-8 = form_tag cart_discount_path, method: 'patch', class: 'form-inline' do .coupon input#coupon_code.form-control[type="text" name="coupon_code" placeholder="Discount or Gift code"] input#validateForm.btn.btn-primary[type="submit" name="apply_coupon" value="Apply Coupon"] #coupon_code_err_message

Aucun commentaire:

Enregistrer un commentaire