From 794cc2ec69e3379d290d3436fb51393d48756b49 Mon Sep 17 00:00:00 2001 From: "adam.harbas@a-net.ba" Date: Mon, 11 Jan 2016 16:03:53 +0100 Subject: [PATCH] Gift interface added --- front-api/controllers/cart.rb | 2 +- ...111104754_add_recipient_address_to_cart.rb | 5 ++ ...105607_add_gift_to_delivery_destination.rb | 5 ++ front-api/db/schema.rb | 20 +++-- front-api/models/cart.rb | 6 +- front-api/models/delivery_destination.rb | 2 +- front-ui/app/components/cart/checkoutPage.js | 83 +++++++++++++++++-- .../app/components/payment/paymentSelect.js | 2 +- front-ui/app/stores/cartStore.js | 5 +- 9 files changed, 103 insertions(+), 27 deletions(-) create mode 100644 front-api/db/migrate/20160111104754_add_recipient_address_to_cart.rb create mode 100644 front-api/db/migrate/20160111105607_add_gift_to_delivery_destination.rb diff --git a/front-api/controllers/cart.rb b/front-api/controllers/cart.rb index 0883f55..88d0af2 100644 --- a/front-api/controllers/cart.rb +++ b/front-api/controllers/cart.rb @@ -44,7 +44,7 @@ end update_delivery_destination = ->() { cart = Cart.just_find(anonymous_id, logged_in_user_id) - allowed_keys = ["name", "address", "place", "postal_code", "phone", "email", "note", "payment_method"] + allowed_keys = ["name", "address", "place", "postal_code", "phone", "email", "note", "payment_method", "gift"] params = @json_params.reject { |key,_| !allowed_keys.include?(key) } cart.delivery_destination.update_attributes(params) cart.delivery_destination.save! diff --git a/front-api/db/migrate/20160111104754_add_recipient_address_to_cart.rb b/front-api/db/migrate/20160111104754_add_recipient_address_to_cart.rb new file mode 100644 index 0000000..5a08cf7 --- /dev/null +++ b/front-api/db/migrate/20160111104754_add_recipient_address_to_cart.rb @@ -0,0 +1,5 @@ +class AddRecipientAddressToCart < ActiveRecord::Migration + def change + add_column :carts, :recipient_destination_id, :integer + end +end diff --git a/front-api/db/migrate/20160111105607_add_gift_to_delivery_destination.rb b/front-api/db/migrate/20160111105607_add_gift_to_delivery_destination.rb new file mode 100644 index 0000000..2952bd9 --- /dev/null +++ b/front-api/db/migrate/20160111105607_add_gift_to_delivery_destination.rb @@ -0,0 +1,5 @@ +class AddGiftToDeliveryDestination < ActiveRecord::Migration + def change + add_column :delivery_destinations, :gift, :boolean, default: false + end +end diff --git a/front-api/db/schema.rb b/front-api/db/schema.rb index 0db9c5d..638d080 100644 --- a/front-api/db/schema.rb +++ b/front-api/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160111024541) do +ActiveRecord::Schema.define(version: 20160111105607) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -22,17 +22,18 @@ ActiveRecord::Schema.define(version: 20160111024541) do create_table "carts", force: :cascade do |t| t.integer "user_id" - t.boolean "ordered", default: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.boolean "ordered", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "anonymous_id_string" t.integer "delivery_destination_id" - t.boolean "confirmed", default: false - t.boolean "packed", default: false - t.boolean "canceled_on_check", default: false - t.boolean "canceled_on_delivery", default: false - t.boolean "delivered", default: false + t.boolean "confirmed", default: false + t.boolean "packed", default: false + t.boolean "canceled_on_check", default: false + t.boolean "canceled_on_delivery", default: false + t.boolean "delivered", default: false t.text "internal_note" + t.integer "recipient_destination_id" end create_table "categories", force: :cascade do |t| @@ -68,6 +69,7 @@ ActiveRecord::Schema.define(version: 20160111024541) do t.string "anonymous_id_string" t.boolean "instant_delivery", default: false t.string "payment_method" + t.boolean "gift", default: false end create_table "delivery_time_estimations", force: :cascade do |t| diff --git a/front-api/models/cart.rb b/front-api/models/cart.rb index 20b984c..31236bc 100644 --- a/front-api/models/cart.rb +++ b/front-api/models/cart.rb @@ -1,6 +1,8 @@ class Cart < ActiveRecord::Base has_many :item_in_carts, -> { order "created_at" } - belongs_to :delivery_destination + + belongs_to :delivery_destination, :class_name => 'DeliveryDestination', :foreign_key => 'delivery_destination_id' + belongs_to :delivery_destination, :class_name => 'DeliveryDestination', :foreign_key => 'recipient_destination_id' def self.find_or_create(anonymous_id, user_id) cart = nil @@ -74,7 +76,7 @@ class Cart < ActiveRecord::Base def title number = id - name = delivery_destination.name + name = delivery_destination.name value = Helper.money(total) phone = "0#{delivery_destination.phone}" "BR: #{number} za #{name} (#{phone}) - #{value}" diff --git a/front-api/models/delivery_destination.rb b/front-api/models/delivery_destination.rb index e42c60c..7e51f0d 100644 --- a/front-api/models/delivery_destination.rb +++ b/front-api/models/delivery_destination.rb @@ -1,5 +1,5 @@ class DeliveryDestination < ActiveRecord::Base - has_one :cart + has_many :carts belongs_to :user def self.create_from_last(anonymous_id, user_id) diff --git a/front-ui/app/components/cart/checkoutPage.js b/front-ui/app/components/cart/checkoutPage.js index 541fb13..4e78c0c 100644 --- a/front-ui/app/components/cart/checkoutPage.js +++ b/front-ui/app/components/cart/checkoutPage.js @@ -24,6 +24,7 @@ var CheckoutPage = React.createClass({ amount={CartStore.getAmount()} deliveryCost={CartStore.getDeliveryCost(false)} disabled={!this.state.isDeliveryDestinationValid} + cashOnDeliveryDisabled={!this.state.isDeliveryDestinationValid || this.state.deliveryDestination.get('gift')} onCashClick={this._onOrderClick} /> @@ -35,10 +36,10 @@ var CheckoutPage = React.createClass({ ); } else if(this.state.deliveryDestination.get('payment_method') == 'pikpay') { - + } else { last_used_payment = ( - + ); } @@ -48,7 +49,7 @@ var CheckoutPage = React.createClass({
- Dostava + Podaci o naručiocu
@@ -112,17 +113,73 @@ var CheckoutPage = React.createClass({ Ukupno:
+
+
+ +
-
- {choosePayment} -
+ - +
+ Podaci o dostavi +
-
+ +
+ + + ime osobe koja prima pošiljku +
+ +
+ +
+ + + adresa na koju će roba biti isporučena +
+
+ +
+ +
+ + +
+
+
+ +
+ +
+ +387 + +
+

broj mobitela - mora biti sa jedne od mreža u BiH

+
+
+
+ +
+ + + E - mail adresa na koju će vam biti poslano obavještenje o narudžbi +
+
+
+ +
+ {choosePayment} +
+ + ); if(CartStore.isAddressColapsed()) { @@ -173,7 +230,15 @@ var CheckoutPage = React.createClass({ }, _onFieldChange: function (event) { - CartActions.changeDeliveryDestinationProperty(event.target.name, event.target.value); + if(event.target.name === "gift") { + CartActions.changeDeliveryDestinationProperty(event.target.name, $(event.target).is(':checked')); + } else { + CartActions.changeDeliveryDestinationProperty(event.target.name, event.target.value); + } + }, + + _onFieldRecipientChange: function(event) { + CartActions.changeRecipientDestinationProperty(event.target.name, event.target.value); }, _onOrderClick: function (event) { diff --git a/front-ui/app/components/payment/paymentSelect.js b/front-ui/app/components/payment/paymentSelect.js index d12c978..f5a5be8 100644 --- a/front-ui/app/components/payment/paymentSelect.js +++ b/front-ui/app/components/payment/paymentSelect.js @@ -11,7 +11,7 @@ var CashOnDeliveryButton = require('./cashOnDeliveryButton'); var PaymentSelect = React.createClass({ render: function() { - var cashOnDeliveryBtn = ( ); + var cashOnDeliveryBtn = ( ); var pikpayBtn = ( ); var paypalBtn = ( ); diff --git a/front-ui/app/stores/cartStore.js b/front-ui/app/stores/cartStore.js index 6d231cf..a17e1b5 100644 --- a/front-ui/app/stores/cartStore.js +++ b/front-ui/app/stores/cartStore.js @@ -2694,14 +2694,11 @@ var addNItems = function(item, count) { var changeDeliveryDestinationProperty = function(property, value) { _deliveryDestination.set(property, value); - console.log(_deliveryDestination); - if (property === 'place') { fetchPlace(); } - validateDeliveryDestinationForm(); - console.log(_deliveryDestination); + validateDeliveryDestinationForm(); };