var React = require('react'),
CartStore = require('../../stores/cartStore'),
AddToCart = require('../cart/addToCart'),
CartActions = require('../../actions/cartActions'),
NavigationActions = require('../../actions/navigationActions'),
SingleItem = require('../items/singleItem'),
Globals = require('../../globals'),
LinkBanner = require('../linkBanner/linkBanner'),
CartTotal = require('./cartTotal');
AllItemsInGroup = require('../items/allItemsInGroup');
var Router = require('react-router');
var CartPage = React.createClass({
_onTakeItemOut: function(itemId) {
CartActions.takeItemOut(itemId);
},
_goToStartPage: function() {
NavigationActions.goToHome();
},
render: function() {
var counts = this.state.itemCounts;
var self = this;
var displayedItems = this.state.items.filter(function(i) {
if(!counts) return false;
var count = counts[i.get('id')].get('count');
return count > 0 || count === "";
}); // tableDetails
var displayedItemsDesktop = displayedItems.map( this.desktopDetails );
var displayedItemsMobile = displayedItems.map( this.mobileDetails );
var deliveryDestination = ();
if (this.state.destinationValid) {
deliveryDestination = (
Na adresu {this.state.deliveryDestination.name},
)
}
var cartTotal = (
ili
);
var instantDelivery = (
{" Hitna dostava (ako naručite toku radnog dana do 16h) ili ujutru (ako naručite poslije 16h)"}
);
var buySomethingMessage = ();
var content;
if (displayedItems.length <= 0) {
cartTotal = ()
buySomethingMessage = (
Nemate ni jedan artikal u vašoj korpi. Kada vidite nešto što vam se sviđa - pritisnite dugme UBACI U KORPU pored artikla kako biste ga dodali u korpu.
Evo nekoliko artikala koje vam možemo preporučiti:
)
content = buySomethingMessage;
} else {
content = (
|
Proizvod |
Cijena |
Količina |
Ukupna cijena |
|
{displayedItemsMobile}
{displayedItemsDesktop}
{buySomethingMessage}
{cartTotal}
)
}
return (
);
},
desktopDetails: function (i) {
var self = this;
var counts = this.state.itemCounts;
var count = counts[i.get('id')].get('count');
var commission = counts[i.get('id')].get('commission');
var price = i.get('list_price');
var firstImage = i.get('multi_media_descriptions')[0];
firstImage = firstImage || { resized_url: "https://res.cloudinary.com/lfvt7ps2n/image/upload/c_fit,h_172,w_226/v1421732950/http_www.asms.ru_bitrix_templates_main_images_nophoto_irnofq.png" } ;
return (
|
{i.get('brand').name}
{i.get('name')}
|
{ Globals.FormatCurrency(price) }
|
|
{ Globals.FormatCurrency(count * price) }
|
|
)
},
mobileDetails: function (i) {
var self = this;
var counts = this.state.itemCounts;
var count = counts[i.get('id')].get('count');
var commission = counts[i.get('id')].get('commission');
var price = i.get('list_price');
var firstImage = i.get('multi_media_descriptions')[0];
firstImage = firstImage || { resized_url: "https://res.cloudinary.com/lfvt7ps2n/image/upload/c_fit,h_172,w_226/v1421732950/http_www.asms.ru_bitrix_templates_main_images_nophoto_irnofq.png" } ;
return (
|
{i.get('brand').name}
{i.get('name')}
{ Globals.FormatCurrency(price) }
{ Globals.FormatPercentage(commission) } RUC
|
|
|
)
},
// Add change listeners to stores
componentDidMount: function() {
CartStore.addChangeListener(this._onChange);
CartActions.load();
},
componentWillUnmount: function () {
CartStore.removeChangeListener(this._onChange);
},
_onChange: function () {
if (this.isMounted()) {
this.setState(CartStore.getWholeCartState());
}
},
_onInstantDeliveryChange: function () {
CartActions.changeDeliveryDestinationProperty("instant_delivery", !this.state.deliveryDestination.get('instant_delivery'));
},
_onOrderClick: function () {
NavigationActions.goToCheckout();
},
_onQuantityChange: function(itemId, e) {
CartActions.setItemCount(itemId, e.target.value);
},
getInitialState: function () {
return CartStore.getWholeCartState();
}
});
module.exports = CartPage;