1 package com.dotmarketing.portlets.product.factories; 2 3 import java.util.List ; 4 5 import com.dotmarketing.db.DotHibernate; 6 import com.dotmarketing.factories.InodeFactory; 7 import com.dotmarketing.util.Logger; 8 import com.dotmarketing.portlets.product.action.EditPriceAction; 9 import com.dotmarketing.portlets.product.model.ProductFormat; 10 import com.dotmarketing.portlets.product.model.ProductPrice; 11 15 public class ProductPriceFactory { 16 17 public static java.util.List getAllProductPrices() { 18 DotHibernate dh = new DotHibernate(ProductPrice.class); 19 dh.setQuery( 20 "from inode in class com.dotmarketing.portlets.product.model.ProductPrice order by product_format_inode"); 21 return dh.list(); 22 } 23 public static java.util.List getAllProductPrices(String orderby) { 24 DotHibernate dh = new DotHibernate(ProductPrice.class); 25 dh.setQuery( 26 "from inode in class com.dotmarketing.portlets.product.model.ProductPrice order by " + orderby); 27 return dh.list(); 28 } 29 30 @SuppressWarnings ("unchecked") 31 public static List <ProductPrice> getAllProductPricesByFormat (ProductFormat format) { 32 return InodeFactory.getInodesOfClassByCondition(ProductPrice.class, "product_format_inode = " + format.getInode()); 33 } 34 35 public static List <ProductPrice> getAllBulkProductPricesByFormat(ProductFormat format) { 36 return InodeFactory.getInodesOfClassByConditionAndOrderBy(ProductPrice.class, "product_format_inode = " + format.getInode(),"min_qty asc, max_qty asc"); 37 } 38 39 public static List <ProductPrice> getQuantityPricePricesByFormat(ProductFormat format,int quantity) { 40 String filter = "product_format_inode = " + format.getInode() + " and min_qty <= " + quantity + " and " + quantity + " <= max_qty "; 41 return InodeFactory.getInodesOfClassByConditionAndOrderBy(ProductPrice.class,filter,"retail_price"); 42 } 43 44 public static List <ProductPrice> getMinorQuantityPricePricesByFormat(ProductFormat format,int quantity) { 45 String filter = "product_format_inode = " + format.getInode() + " and min_qty <= " + quantity + " and max_qty <= " + quantity; 46 return InodeFactory.getInodesOfClassByConditionAndOrderBy(ProductPrice.class,filter,"retail_price"); 47 } 48 49 public static List <ProductPrice> getAllQuantityPricePricesByFormat(ProductFormat format,int quantity) { 50 String filter = "product_format_inode = " + format.getInode(); 51 return InodeFactory.getInodesOfClassByConditionAndOrderBy(ProductPrice.class,filter,"retail_price"); 52 } 53 54 55 public static ProductPrice newInstance() { 56 ProductPrice price = new ProductPrice(); 57 return price; 58 } 59 60 public static void saveProductPrice(ProductPrice price) { 61 InodeFactory.saveInode(price); 62 } 63 64 public static void deleteProductPrice(ProductPrice price) { 65 InodeFactory.deleteInode(price); 66 } 67 68 public static void copyProductPrice(ProductPrice price) 69 { 70 long formatInode = price.getProductFormatInode(); 72 ProductFormat format = ProductFormatFactory.getProductFormat(formatInode); 73 copyProductPrice(format,price); 74 } 75 76 public static void copyProductPrice(ProductFormat format,ProductPrice price) 77 { 78 ProductPrice copyPrice = new ProductPrice(); 80 try 81 { 82 copyPrice.setMinQty(price.getMinQty()); 84 copyPrice.setMaxQty(price.getMaxQty()); 85 copyPrice.setRetailPrice(price.getRetailPrice()); 86 copyPrice.setPartnerPrice(price.getPartnerPrice()); 87 copyPrice.setProductFormatInode(format.getInode()); 88 } 89 catch(Exception ex) 90 { 91 Logger.debug(EditPriceAction.class,ex.toString()); 92 } 93 copyPrice.setInode(0); 94 ProductPriceFactory.saveProductPrice(copyPrice); 95 } 96 97 public static ProductPrice getProductPrice(String inode) { 98 return (ProductPrice) InodeFactory.getInode(inode,ProductPrice.class); 99 } 100 101 public static ProductPrice getProductCode(long inode) { 102 return (ProductPrice) InodeFactory.getInode(inode,ProductPrice.class); 103 } 104 105 106 } 107 | Popular Tags |