Merge branch 'develop'

paypal, pikpay and gift support
This commit is contained in:
Senad Uka
2016-02-07 19:54:08 +01:00
416 changed files with 1191 additions and 135926 deletions

View File

@@ -10,6 +10,7 @@ var DeliveryDestination = require('../models/deliveryDestination');
var OrderConfirmation = require('../models/orderConfirmation');
var Place = require('../models/place');
var Validation = require('../utils/validation');
var Cart = require('../models/cart');
var _ = require('underscore');
@@ -23,11 +24,12 @@ var _deliveryDestination = new DeliveryDestination();
var _deliveryDestinationErrors = {};
var _deliveryCosts = new Place({
postalCode: _deliveryDestination.get('place')
})
});
var _cart = new Cart();
var _addressColapsed = false;
var supportedPlaces = [{
"code": "-12",
"placeLabel": "Izaberite mjesto"
@@ -37,7 +39,7 @@ var supportedPlaces = [{
}, {
"code": " 71000",
"placeLabel": "Sarajevo"
},
},
{
"code": " 78000",
"placeLabel": "Banja Luka"
@@ -50,7 +52,7 @@ var supportedPlaces = [{
{
"code": " 88000",
"placeLabel": "Mostar"
},
},
{
"code": " 72000",
@@ -2569,30 +2571,31 @@ var nameOfThePlace = function(code) {
}
var loadCart = function() {
_cart.fetch({success: function() {
_itemsInCart.fetch({
success: function() {
states = {}
for (var i = 0; i < _itemsInCart.models.length; i++) {
var itemInCart = _itemsInCart.models[i];
states[itemInCart.get('item_id')] = itemInCart;
}
_itemsForDisplay.fetch({
success: function() {
CartActions.dataLoaded();
_itemsInCart.fetch({
success: function() {
states = {}
for (var i = 0; i < _itemsInCart.models.length; i++) {
var itemInCart = _itemsInCart.models[i];
states[itemInCart.get('item_id')] = itemInCart;
}
_itemsForDisplay.fetch({
success: function() {
CartActions.dataLoaded();
_deliveryDestination.fetch({
success: function() {
validateDeliveryDestinationForm();
collapseAddressIfNeeded();
fetchPlace();
CartActions.dataLoaded();
}
});
}
});
}
});
_deliveryDestination.fetch({
success: function() {
validateDeliveryDestinationForm();
collapseAddressIfNeeded();
fetchPlace();
CartActions.dataLoaded();
}
});
}
});
}
});
}});
_cartDataLoadCalled = true;
};
@@ -2606,8 +2609,10 @@ var collapseAddressIfNeeded = function() {
}
var fetchPlace = function() {
postalCode = _deliveryDestination.get('gift') ? _deliveryDestination.get('recipient_place') : _deliveryDestination.get('place');
_deliveryCosts = new Place({
postalCode: _deliveryDestination.get('place')
postalCode: postalCode
})
_deliveryCosts.fetch({
success: function() {
@@ -2696,13 +2701,13 @@ 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();
}
validateDeliveryDestinationForm();
};
var confirmOrder = function() {
var oc = new OrderConfirmation({
@@ -2719,14 +2724,20 @@ var confirmOrder = function() {
});
};
var saveDeliveryDestinationAnd = function(successCallback) {
_deliveryDestination.save(null, {
success: function() {
successCallback();
}
})
};
var saveDeliveryDestination = function() {
_deliveryDestination.save(null, {
success: function() {
confirmOrder();
}
})
success: function() {
confirmOrder();
}
});
};
var validateDeliveryDestinationForm = function() {
@@ -2757,7 +2768,34 @@ var validateDeliveryDestinationForm = function() {
_deliveryDestinationErrors['place'] = "Mjesto mora biti izabrano";
}
if(_deliveryDestination.get('gift')) {
if (Validation.safeString(_deliveryDestination.get('recipient_name')).search(nameRegex) < 0) {
_deliveryDestinationErrors['recipient_name'] = "I prezime i ime su obavezni";
}
if (Validation.safeString(_deliveryDestination.get('recipient_address')).search(addressRegex) < 0) {
_deliveryDestinationErrors['recipient_address'] = "Adresa mora biti ispravna";
}
if (_deliveryDestination.get('recipient_email') && Validation.safeString(_deliveryDestination.get('recipient_email')).search(emailRegex) < 0) {
_deliveryDestinationErrors['recipient_email'] = "Email mora biti ispravno upisan";
}
if (Validation.safeString(_deliveryDestination.get('recipient_phone')).search(phoneRegex) < 0) {
_deliveryDestinationErrors['recipient_phone'] = "Telefon mora biti ispravan";
}
if (Validation.safeString(_deliveryDestination.get('recipient_place')).search(placeRegex) < 0) {
_deliveryDestinationErrors['recipient_place'] = "Mjesto mora biti izabrano";
}
}
var requiredFields = ["name", "email", "place", 'address', 'phone'];
if(_deliveryDestination.get('gift')) {
requiredFields = requiredFields.concat(["recipient_name", "recipient_place", 'recipient_address', 'recipient_phone']);
}
for (var i in requiredFields) {
var value = _deliveryDestination.get(requiredFields[i]);
if (value === undefined || value === null || value === "") {
@@ -2768,10 +2806,14 @@ var validateDeliveryDestinationForm = function() {
}
var isDeliveryDestinationValid = function() {
return Object.getOwnPropertyNames(_deliveryDestinationErrors).length === 0;
}
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, {
@@ -2792,6 +2834,29 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
return supportedPlaces;
},
getAmount: function() {
var counts = states;
var total = 0;
if (counts && _itemsForDisplay) {
var items = _itemsForDisplay.models;
for (var i = 0; i < items.length; i++) {
var item = items[i];
var count = counts[item.get('id')].get('count');
var price = item.get('list_price');
total += (price * count)
};
}
return total;
},
getDeliveryCost: function(instantDelivery) {
return instantDelivery ? Number(_deliveryCosts.get('instant_delivery_price'))
: Number(_deliveryCosts.get('delivery_price'));
},
getWholeCartState: function() {
var numberOfItems = 0;
@@ -2813,7 +2878,10 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
deliveryDestinationErrors: _deliveryDestinationErrors,
isDeliveryDestinationValid: isDeliveryDestinationValid(),
deliveryCosts: _deliveryCosts,
destinationValid: isDeliveryDestinationValid()
destinationValid: isDeliveryDestinationValid(),
address_colapsed: _addressColapsed,
deliveryCostsTarget: getDeliveryCostTarget(),
cart: _cart
};
return state;
},
@@ -2850,6 +2918,14 @@ var CartStore = _.extend({}, EventEmitter.prototype, {
address.push(_deliveryDestination.get('email'))
return address;
},
getNameOfThePlace: function(code) {
return nameOfThePlace(code);
},
saveDeliveryDestinationAnd: function(successCallback) {
saveDeliveryDestinationAnd(successCallback);
}
});