From ba1717132921729564633fbe93e269cef2da5a19 Mon Sep 17 00:00:00 2001 From: Daniele Palombo Date: Thu, 10 Dec 2015 12:28:03 +0100 Subject: [PATCH 1/3] add it language --- config/locale/it.yml | 126 +++++++++++++++++++++++++++++++++++ lib/coupons/models/coupon.rb | 2 +- 2 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 config/locale/it.yml diff --git a/config/locale/it.yml b/config/locale/it.yml new file mode 100644 index 00000000..1280d40a --- /dev/null +++ b/config/locale/it.yml @@ -0,0 +1,126 @@ +it: + date: + formats: + coupon: '%b %d, %Y' + + page_meta: + titles: + base: "%{value}" + coupons: + coupons: + index: Coupons + new: Nuovo Coupon + edit: Modifica Coupon + remove: Elimina Coupon + duplicate: Duplica Coupon + + views: + pagination: + first: "« Primo" + last: "Ultimo »" + previous: "‹ Precedente" + next: "Successivo ›" + truncate: "…" + + paginate: + previous: 'Pagina precedente' + next: 'Pagina Successiva' + page: 'Pagina %{page}' + + coupons: + new_coupon_button: 'Crea Coupon' + are_you_sure_you_want_to_remove_html: > + Sei sicuro di voler rimuovere questo coupon? + you_cant_undo_removal_html: > + All redemption trackings will be removed as well. + You won't be able to undo this action. + + blank_slate: + no_coupons: Nessun Coupons + no_coupons_description: Non hai ancora creato nessun coupon. Qui é dove appariranno. + + selected_rules: + one: '${count} coupon selezionato' + other: '${count} coupons selezionati' + + 'off': + amount_html: '$%{amount} OFF' + percentage_html: '%{amount}% OFF' + + redeemed_html: + zero: Non ancora + one: '%{count}/%{limit}' + other: '%{count}/%{limit}' + + limit_html: + zero: '' + one: '%{count}' + other: '%{count}' + + columns: + description: 'Descrizione' + discount: 'Sconto' + redeemed: 'Riscattato' + expiration: 'Scadenza' + + actions: + edit: 'Modifica' + remove: 'Elimina' + confirm: "Sì, sono sicuro!" + cancel: 'No' + go_back: 'Indietro' + duplicate: 'Duplica' + + flash: + coupons: + create: + notice: Il coupon è stato creato! + update: + notice: Il coupon è stato aggiornato! + destroy: + notice: Il coupon è stato rimosso! + batch: + invalid_action: 'Questa azione non è valida!' + removal: + notice: 'I coupon sono stati rimossi' + + labels: + coupon: + description: 'Descrizione' + redemption_limit: 'Limite riscatti' + type: 'Tipo' + amount: 'Prezzo' + code: 'Codice sconto' + valid_from: 'Valido dal' + valid_until: 'Valido fino al' + + hints: + coupon: + type: 'Seleziona come dovrà funzionare lo sconto.' + code: 'Il cliente dovrà fornire questo codice.' + description: 'Descrivi questo coupon così ricorderai a cosa serve' + redemption_limit: 'Setta quante volte il coupon può essere usato. Inserisci zero per infinito' + amount: 'Questo é lo sconto. 0-100 per lo sconto percentuale, zero o numero positivo per sconto fisso.' + valid_from: 'Da quando il coupon sará disponibile.' + valid_until: 'Data di scadenza coupon. Per default senza scadenza.' + + form_error_description: 'Ci sono errori nel form:' + + coupon: + type: + amount: 'Prezzo ($)' + percentage: 'Percentuale (%)' + + buttons: + create: 'Crea Coupon' + edit: 'Aggiorna Coupon' + remove_selected: 'Rimuovi Coupons' + + no_description: 'Nessuna descrizione' + dont_expire: Mai + + activerecord: + errors: + messages: + coupon_already_expired: Deve essere uguale o maggiore di oggi + coupon_valid_until: Deve essere maggiore o uguale alla data di inizio validità. diff --git a/lib/coupons/models/coupon.rb b/lib/coupons/models/coupon.rb index 652e7366..0f2c34bb 100644 --- a/lib/coupons/models/coupon.rb +++ b/lib/coupons/models/coupon.rb @@ -62,7 +62,7 @@ def expired? end def has_available_redemptions? - redemptions_count.zero? || redemptions_count < redemption_limit + redemption_limit.zero? || redemptions_count < redemption_limit end def started? From ab0891fe743bac3aa803142723a039d49e53e305 Mon Sep 17 00:00:00 2001 From: Daniele Palombo Date: Thu, 10 Dec 2015 12:29:39 +0100 Subject: [PATCH 2/3] solved bug with redemption limi --- lib/coupons/models/coupon.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/coupons/models/coupon.rb b/lib/coupons/models/coupon.rb index 0f2c34bb..42e1663e 100644 --- a/lib/coupons/models/coupon.rb +++ b/lib/coupons/models/coupon.rb @@ -61,6 +61,7 @@ def expired? valid_until && valid_until <= Date.current end + # without redemption limit OR redeemed count less than redemption limit def has_available_redemptions? redemption_limit.zero? || redemptions_count < redemption_limit end From 8a53a4994df11539068fa8b337fcc00049771abf Mon Sep 17 00:00:00 2001 From: Daniele Palombo Date: Tue, 3 May 2016 17:57:40 +0200 Subject: [PATCH 3/3] add redemption_info after redeem --- README.md | 7 ++++--- lib/coupons/helpers.rb | 3 ++- spec/coupons/helpers_spec.rb | 6 ++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3031ee3b..dfda1010 100644 --- a/README.md +++ b/README.md @@ -83,10 +83,11 @@ Coupons.apply('invalid', amount: 100.00) To redeem the coupon you can use `Coupon.redeem`. ```ruby -Coupons.redeem('RAILSCONF15', amount: 600.00) -#=> {:amount => 600.0, :discount => 100.0, :total => 500.0} +options = Coupons.redeem('RAILSCONF15', amount: 600.00) +#=> {:amount => 600.0, :discount => 100.0, :total => 500.0, :redempted_id => 1234} -coupon = Coupons::Models::Coupon.last +Coupons::Models::CouponRedemption.find options[:redempted_id] +# => # coupon.redemptions_count #=> 1 diff --git a/lib/coupons/helpers.rb b/lib/coupons/helpers.rb index 1f52c089..6a375068 100644 --- a/lib/coupons/helpers.rb +++ b/lib/coupons/helpers.rb @@ -32,7 +32,8 @@ def redeem(code, options) coupon = find(code, options) return options unless coupon - coupon.redemptions.create!(options.slice(:user_id, :order_id)) + redempted = coupon.redemptions.create!(options.slice(:user_id, :order_id)) + options.merge!(redempted_id: redempted.id) coupon.apply(options) end diff --git a/spec/coupons/helpers_spec.rb b/spec/coupons/helpers_spec.rb index a4bddfa2..f2b2bb28 100644 --- a/spec/coupons/helpers_spec.rb +++ b/spec/coupons/helpers_spec.rb @@ -67,4 +67,10 @@ maker.redeem(coupon.code, order_id: 1234) expect(coupon.redemptions.last.order_id).to eq('1234') end + + it 'return coupon redemption id' do + coupon = maker.create(amount: 10, type: 'amount') + options = maker.redeem(coupon.code, order_id: 1234) + expect(coupon.redemptions.last.id).to eq(options[:redempted_id]) + end end