Gift interface added
This commit is contained in:
@@ -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!
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddRecipientAddressToCart < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :carts, :recipient_destination_id, :integer
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddGiftToDeliveryDestination < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :delivery_destinations, :gift, :boolean, default: false
|
||||
end
|
||||
end
|
||||
@@ -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|
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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}
|
||||
/>
|
||||
</div>
|
||||
@@ -35,10 +36,10 @@ var CheckoutPage = React.createClass({
|
||||
<PaypalButton disabled={!this.state.isDeliveryDestinationValid} onSubmitPaypal={this._handleOnSubmitPaypal} deliveryDestination={this.state.deliveryDestination} amount={CartStore.getAmount()} deliveryCost={CartStore.getDeliveryCost(false)} />
|
||||
);
|
||||
} else if(this.state.deliveryDestination.get('payment_method') == 'pikpay') {
|
||||
<PikpaylButton amount={CartStore.getAmount()} deliveryCost={CartStore.getDeliveryCost(false)} disabled={!this.state.isDeliveryDestinationValid} deliveryDestination={this.state.deliveryDestination}/>
|
||||
<PikpayButton amount={CartStore.getAmount()} deliveryCost={CartStore.getDeliveryCost(false)} disabled={!this.state.isDeliveryDestinationValid} deliveryDestination={this.state.deliveryDestination}/>
|
||||
} else {
|
||||
last_used_payment = (
|
||||
<CashOnDeliveryButton onCashClick={this._onOrderClick} disabled={!this.state.isDeliveryDestinationValid}/>
|
||||
<CashOnDeliveryButton onCashClick={this._onOrderClick} disabled={!this.state.isDeliveryDestinationValid || this.state.deliveryDestination.get('gift')}/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ var CheckoutPage = React.createClass({
|
||||
<div className="checkout-page center">
|
||||
<div className="form-horizontal checkout_form_margin">
|
||||
<fieldset>
|
||||
<legend>Dostava</legend>
|
||||
<legend>Podaci o naručiocu</legend>
|
||||
<div className="form-group ">
|
||||
|
||||
<label className="col-md-4 control-label" htmlFor="name">Prezime i Ime</label>
|
||||
@@ -112,17 +113,73 @@ var CheckoutPage = React.createClass({
|
||||
Ukupno: <CartTotal items={this.state.items} itemCounts={this.state.itemCounts} deliveryCosts={this.state.deliveryCosts} />
|
||||
</span>
|
||||
</div>
|
||||
<br />
|
||||
<div className="checkbox">
|
||||
<label><input type="checkbox" name="gift" value={this.state.deliveryDestination.get('gift')} onChange={this._onFieldChange} />Poklon</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="payment-select-container">
|
||||
{choosePayment}
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
<fieldset className={this.state.deliveryDestination.get('gift') ? 'shown' : 'hidden'}>
|
||||
<legend>Podaci o dostavi</legend>
|
||||
<div className="form-group ">
|
||||
|
||||
</div>
|
||||
<label className="col-md-4 control-label" htmlFor="name">Prezime i Ime</label>
|
||||
<div className="col-md-4">
|
||||
<RibicaFormError componentName="name" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||
<input id="name" name="name" type="text" placeholder="Prezime Ime" className="form-control input-md" required="" value="" onChange={this._onFieldChange} />
|
||||
<span className="help-block">ime osobe koja prima pošiljku</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-group ">
|
||||
<label className="col-md-4 control-label" htmlFor="name">Adresa</label>
|
||||
<div className="col-md-4">
|
||||
<RibicaFormError componentName="address" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||
<input id="address" name="address" type="text" placeholder="Ulica i broj" className="form-control input-md" required="" value="" onChange={this._onFieldChange} />
|
||||
<span className="help-block">adresa na koju će roba biti isporučena</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="form-group ">
|
||||
<label className="col-md-4 control-label" htmlFor="place">Mjesto</label>
|
||||
<div className="col-md-4">
|
||||
<RibicaFormError componentName="place" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||
<select id="place" name="place" className="form-control" value={this.state.deliveryDestination.get('place')} onChange={this._onFieldChange} >
|
||||
|
||||
{supportedPlaceOptions}
|
||||
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-group ">
|
||||
<label className="col-md-4 control-label" htmlFor="phone">Telefon</label>
|
||||
<div className="col-md-4">
|
||||
<RibicaFormError componentName="phone" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||
<div className="input-group">
|
||||
<span className="input-group-addon">+387 </span>
|
||||
<input id="phone" name="phone" className="form-control" placeholder="061 222 333" type="text" required="" value="" onChange={this._onFieldChange} />
|
||||
</div>
|
||||
<p className="help-block">broj mobitela - mora biti sa jedne od mreža u BiH</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="form-group ">
|
||||
<label className="col-md-4 control-label" htmlFor="email">E - mail</label>
|
||||
<div className="col-md-4">
|
||||
<RibicaFormError componentName="email" errorMessagesObject={this.state.deliveryDestinationErrors} />
|
||||
<input id="email" name="email" type="text" placeholder="ime@nekimail.com" className="form-control input-md" required="" value="" onChange={this._onFieldChange} />
|
||||
<span className="help-block">E - mail adresa na koju će vam biti poslano obavještenje o narudžbi</span>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div className="payment-select-container">
|
||||
{choosePayment}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
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) {
|
||||
|
||||
@@ -11,7 +11,7 @@ var CashOnDeliveryButton = require('./cashOnDeliveryButton');
|
||||
|
||||
var PaymentSelect = React.createClass({
|
||||
render: function() {
|
||||
var cashOnDeliveryBtn = ( <CashOnDeliveryButton onCashClick={this.props.onCashClick} disabled={this.props.disabled}/> );
|
||||
var cashOnDeliveryBtn = ( <CashOnDeliveryButton onCashClick={this.props.onCashClick} disabled={this.props.cashOnDeliveryDisabled}/> );
|
||||
var pikpayBtn = ( <PikpaylButton amount={this.props.amount} deliveryCost={this.props.deliveryCost} disabled={this.props.disabled} deliveryDestination={this.props.deliveryDestination}/> );
|
||||
var paypalBtn = ( <PaypalButton disabled={this.props.disabled} deliveryDestination={this.props.deliveryDestination} amount={this.props.amount} deliveryCost={this.props.deliveryCost} /> );
|
||||
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user