19 package org.turro.financials.cart;
21 import java.util.Date;
22 import org.turro.string.ObjectString;
23 import org.turro.string.Strings;
24 import org.turro.action.Actions;
25 import org.turro.action.IRegisterCallback;
26 import org.turro.auth.Authentication;
27 import org.turro.collections.KeyValueMap;
28 import org.turro.elephant.context.ElephantContext;
29 import org.turro.elephant.context.IConstructor;
30 import org.turro.financials.db.FinancialsPU;
31 import org.turro.financials.entity.Product;
32 import org.turro.marker.ElephantMarker;
33 import org.turro.plugin.contacts.IContact;
44 private final String shopping,
template;
47 this.constructor = constructor;
48 this.shopping = shopping;
49 this.
template =
template;
55 marker.
put(
"shoppingCart",
this);
56 marker.
put(
"cart", cart);
57 marker.
process(
"cart", getTemplate());
75 if(contact ==
null || !contact.
isWebUser()) {
82 private void checkCart() {
86 Long product = (Long) ObjectString.parseString(values.get(
"addToCart"), Long.class,
true);
88 Double quantity = (Double) ObjectString.parseString(values.get(
"quantity"), Double.class,
true);
89 Double price = (Double) ObjectString.parseString(values.get(
"price"), Double.class,
true);
91 Double stock = getStock(cart, product);
92 if((stock ==
null) || ((stock - quantity) >= 0.0)) {
93 cart.
addItem(product, quantity, 0, price);
97 int order = (Integer) ObjectString.parseString(values.get(
"delFromCart"), Integer.class,
true);
101 order = (Integer) ObjectString.parseString(values.get(
"changeFromCart"), Integer.class,
true);
103 Double quantity = (Double) ObjectString.parseString(constructor.
getParameter(
"q"), Double.class,
true);
104 if(quantity != 0.0) {
105 CartItem ci = cart.
getItem(order);
107 Double stock = getStock(cart, ci.getProduct());
108 if((stock ==
null) || ((stock - quantity + ci.getQuantity()) >= 0.0)) {
114 if(!Strings.isBlank(concept)) {
121 private String getTemplate() {
122 return Strings.isBlank(
template) ?
"cart" :
template;
131 if(contact ==
null) {
135 if(contact !=
null && cart.
getItems().isEmpty()) {
137 if(serCart !=
null) {
150 public static String
getAddToCart(String product, String quantity, String price) {
152 "addToCart=" + product +
153 ";quantity=" + quantity +
159 return getStock(cart,
id);
164 return getStock(cart, product);
167 private static Double getStock(
Cart cart, Long
id) {
171 private static Double getStock(Cart cart, Product product) {
172 if(product !=
null && !product.isService()) {
174 for(CartItem ci : cart.getProducts(product.getId())) {
175 stock -= ci.getQuantity();
177 stock += product.getProductStock(
new Date(), ShopContext.getInstance().getContractStore());
static String createRightNowParameter(String values)
static KeyValueMap getRightNowAction(IConstructor constructor)
static IContact getIContact()
static String getRootWebPath()
void changeItem(Integer order, double quantity)
static void removeFor(IContact contact)
boolean addItem(long productId, double quantity, double tax, double price)
void removeItem(Integer order)
static Cart deserializeFor(IContact contact)
CartItem getItem(Integer order)
static ShopContext getInstance()
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
static final String REGISTER_CALLBACK_KEY
String getParameter(String param)
void setSessionAttribute(String key, Object value)
void removeSessionAttribute(String key)
Object getSessionAttribute(String key)