19 package org.turro.financials.content;
21 import java.io.Writer;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.Collection;
25 import java.util.List;
26 import org.turro.string.Strings;
27 import org.turro.attach.www.AttachCtrl;
28 import org.turro.describeit.DescribeItUtil;
29 import org.turro.elephant.context.ElephantContext;
30 import org.turro.elephant.context.IConstructor;
31 import org.turro.elephant.db.WhereClause;
32 import org.turro.elephant.impl.repository.Repository;
33 import org.turro.elephant.impl.repository.RepositoryFile;
34 import org.turro.elephant.web.SocialImageMap;
35 import org.turro.elephant.web.SocialNet;
36 import org.turro.entities.Entities;
37 import org.turro.file.util.FileAttach;
38 import org.turro.financials.cart.ShopContext;
39 import org.turro.financials.cart.ShoppingCart;
40 import org.turro.financials.db.FinancialsPU;
41 import org.turro.financials.entity.Product;
42 import org.turro.groupit.GroupItUtil;
43 import org.turro.jpa.DaoUtil;
44 import org.turro.jpa.content.EntityDaoContentIterator;
45 import org.turro.jpa.search.DaoHtmlSearch;
46 import org.turro.jpa.search.DaoSearchKey;
47 import org.turro.marker.ElephantMarker;
48 import org.turro.plugin.contacts.IContact;
49 import org.turro.polls.PollsCtrl;
50 import org.turro.www.commentit.CommentItCtrl;
51 import org.turro.www.describeit.DescribeItCtrl;
52 import org.turro.www.starit.StarItCtrl;
53 import org.turro.www.voteit.VoteItCtrl;
61 private boolean exact, allowGroups, onlyPromoted, publishable, fullSearch;
76 this.allowGroups = allowGroups;
84 this.onlyPromoted = onlyPromoted;
92 this.publishable = publishable;
100 this.fullSearch = fullSearch;
106 wc.
addClause(
"select distinct {p} from Product as p");
116 wc.
addClause(
"select count({distinct p}) from Product as p");
125 prepareValues(e, page);
133 prepareValues(e, page);
149 return super.isValid(e);
153 boolean searching =
false;
154 wc.
addClause(
"where p.publishable = :publishable");
165 searching = dsk.
applyToQuery(wc, Arrays.asList(
"p.description",
"p.keywords"),
true);
174 if(!Strings.isBlank(selectedGroup)) {
175 List<String> list = (List<String>) GroupItUtil.getPathsFromGroup(
"/product", selectedGroup, selectedCategory, exact);
176 if(list !=
null && !list.isEmpty()) {
178 wc.
addClause(
"and p.identifier in (" + DaoUtil.getInClauseFromPaths(list,
false) +
")");
180 wc.
addClause(
"and p.id in (" + DaoUtil.getInClauseFromPaths(list,
false) +
")");
188 if(!Strings.isBlank(selectedCategory)) {
189 List<String> list = (List<String>) GroupItUtil.getPathsFromCategory(
"/product", selectedCategory);
190 if(list !=
null && !list.isEmpty()) {
192 wc.
addClause(
"and p.identifier in (" + DaoUtil.getInClauseFromPaths(list,
false) +
")");
194 wc.
addClause(
"and p.id in (" + DaoUtil.getInClauseFromPaths(list,
false) +
")");
203 wc.
addClause(
"and p.promoted = :promoted");
208 private void prepareValues(Product product,
int page) {
211 if(product ==
null)
return;
215 if(ShopContext.getInstance().isValid()) {
216 marker.
put(
"cart", getCartExacton(product));
217 marker.
put(
"stock", getCartStock(product));
218 marker.
put(
"action", ElephantContext.getRootWebPath() + ShopContext.getInstance().getCartPath());
222 marker.
put(
"description", product.getDescription());
230 private String getCartExacton(Product product) {
231 return ShoppingCart.getAddToCart(product.getId() +
"",
"1", product.getProductPrice() +
"");
234 private Double getCartStock(Product product) {
235 if(product.isService()) {
238 return ShoppingCart.getStockForProduct(
constructor, product);
248 ArrayList<RepositoryFile> files =
new ArrayList<>();
264 return isMail() ?
"content/newsletter/sections/products" :
"product";
317 if(Strings.isBlank(path)) {
325 return "/user/products";
static String descriptionString(String id, Object entity)
static final String DEFAULT_ID
static String getContextVariable(IConstructor constructor)
void setUseNative(boolean useNative)
void addClause(String clause)
void addNamedValue(String name, Object value)
void setResultClass(Class resultClass)
Set< RepositoryFile > getRepositoryFiles(String pattern)
static boolean hasImage(String url)
List< String > getMetas()
static IElephantEntity getController(String path)
Repository getPublishableRepository(IConstructor constructor)
Object doAttachmentsCtrl(Product e)
Object doVotesCtrl(Product e)
void renderItem(ElephantMarker marker, Product e, int page)
void setFullSearch(boolean fullSearch)
Object doCommentsCtrl(Product e)
Product entity(Long value)
String getItemLink(Product e)
Object doDescriptionsCtrl(Product e)
void setAllowGroups(boolean allowGroups)
Object doFilesCtrl(Product e)
WhereClause getCountClause()
String getRestrictedLink()
void setOnlyPromoted(boolean onlyPromoted)
ProductContentIterator(IConstructor constructor, Writer writer, IContact contact, boolean mail, String pubPath)
boolean isValid(Product e)
void setExact(boolean exact)
Object doPollsCtrl(Product e)
void renderSummary(ElephantMarker marker, Product e, int page)
Object doInterestCtrl(Product e)
void setPublishable(boolean publishable)
WhereClause getWhereClause()
Collection< String > metas(Product e)
static String getObjectPath(Object object)
void prepareControls(E entity, int page)
String doItemLink(E entity, ID id, boolean obfuscated)
String getSummaryTemplate()
static DaoHtmlSearch getInstance(IConstructor constructor, String context)
boolean applyToQueryFull(WhereClause wc, String fields, boolean withSynonyms)
boolean applyToQuery(WhereClause wc, List< String > fields, boolean withSynonyms)
void process(String rootTmpl, String tmpl)
Object put(Object key, Object value)
Object configureCtrl(Object ctrl, IContact contact)