Delivery cost depend on gift option

This commit is contained in:
adam.harbas@a-net.ba
2016-01-12 15:18:27 +01:00
parent 68c7a620ef
commit 54d7cdb04e
2 changed files with 11 additions and 10 deletions

View File

@@ -24,7 +24,7 @@ var CheckoutPage = React.createClass({
amount={CartStore.getAmount()}
deliveryCost={CartStore.getDeliveryCost(false)}
disabled={!this.state.isDeliveryDestinationValid}
cashOnDeliveryDisabled={!this.state.isDeliveryDestinationValid}
cashOnDeliveryDisabled={!this.state.isDeliveryDestinationValid || this.state.deliveryDestination.get('gift')}
onCashClick={this._onOrderClick}
/>
</div>
@@ -108,7 +108,7 @@ var CheckoutPage = React.createClass({
<label className="col-md-4 control-label" htmlFor="order"></label>
<div className="col-md-8">
<div> Roba: <CartTotal items={this.state.items} itemCounts={this.state.itemCounts} /><br />
<span className={this.state.deliveryDestinationErrors['place'] ? 'hidden' : 'shown'}>
<span className={this.state.deliveryDestinationErrors[this.state.deliveryCostsTarget] ? 'hidden' : 'shown'}>
Dostava: <CartTotal deliveryCosts={this.state.deliveryCosts} /><br />
Ukupno: <CartTotal items={this.state.items} itemCounts={this.state.itemCounts} deliveryCosts={this.state.deliveryCosts} />
</span>

View File

@@ -2603,9 +2603,8 @@ var collapseAddressIfNeeded = function() {
}
}
var fetchPlace = function(gift) {
gift = gift === true;
postalCode = gift ? _deliveryDestination.get('recipient_place') : _deliveryDestination.get('place')
var fetchPlace = function() {
postalCode = _deliveryDestination.get('gift') ? _deliveryDestination.get('recipient_place') : _deliveryDestination.get('place');
_deliveryCosts = new Place({
postalCode: postalCode
@@ -2697,12 +2696,9 @@ var addNItems = function(item, count) {
var changeDeliveryDestinationProperty = function(property, value) {
_deliveryDestination.set(property, value);
if (property === 'place') {
if (property === 'place' || property === 'recipient_place' || property === 'gift') {
fetchPlace();
}
if (property === 'recipient_place') {
fetchPlace(true);
}
validateDeliveryDestinationForm();
};
@@ -2809,6 +2805,10 @@ var isDeliveryDestinationValid = function() {
return Object.getOwnPropertyNames(_deliveryDestinationErrors).length === 0;
}
var getDeliveryCostTarget = function() {
return _deliveryDestination.get("gift") ? "recipient_place" : "place";
}
// Extend CartStore with EventEmitter to add eventing capabilities
var CartStore = _.extend({}, EventEmitter.prototype, {
@@ -2874,7 +2874,8 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
isDeliveryDestinationValid: isDeliveryDestinationValid(),
deliveryCosts: _deliveryCosts,
destinationValid: isDeliveryDestinationValid(),
address_colapsed: _addressColapsed
address_colapsed: _addressColapsed,
deliveryCostsTarget: getDeliveryCostTarget()
};
return state;
},