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.discountcode.model.DiscountCode; 9 import com.dotmarketing.portlets.product.model.Product; 10 import com.dotmarketing.portlets.product.model.ProductFormat; 11 import com.dotmarketing.portlets.product.model.ProductPrice; 12 16 public class ProductFormatFactory { 17 18 @SuppressWarnings ("unchecked") 19 public static List <ProductFormat> getAllFormatsByProduct (Product prod) { 20 return InodeFactory.getInodesOfClassByCondition(ProductFormat.class, "product_inode = " + prod.getInode()); 21 } 22 23 24 public static java.util.List getAllProductFormats() { 25 DotHibernate dh = new DotHibernate(ProductFormat.class); 26 dh.setQuery( 27 "from inode in class com.dotmarketing.portlets.product.model.ProductFormat order by product_inode, format_name"); 28 return dh.list(); 29 } 30 public static java.util.List getAllProductFormats(String orderby) { 31 DotHibernate dh = new DotHibernate(ProductFormat.class); 32 dh.setQuery( 33 "from inode in class com.dotmarketing.portlets.product.model.ProductFormat order by product_inode, format_name"); 34 return dh.list(); 35 } 36 37 38 public static ProductFormat newInstance() { 39 ProductFormat format = new ProductFormat(); 40 return format; 41 } 42 43 public static void saveProductFormat(ProductFormat format) { 44 InodeFactory.saveInode(format); 45 } 46 47 public static void deleteProductFormat(ProductFormat format) { 48 List <ProductPrice> prices = ProductPriceFactory.getAllProductPricesByFormat(format); 49 for (ProductPrice price : prices) { 50 ProductPriceFactory.deleteProductPrice(price); 51 } 52 InodeFactory.deleteInode(format); 53 } 54 public static void copyProductFormat(ProductFormat format) 55 { 56 long productInode = format.getProductInode(); 57 Product product = ProductFactory.getProduct(productInode); 58 copyProductFormat(product,format); 59 } 60 61 public static void copyProductFormat(Product product,ProductFormat format) 62 { 63 ProductFormat copyFormat = new ProductFormat(); 65 try 66 { 67 copyFormat.setFormatName(format.getFormatName()); 69 copyFormat.setItemNum(format.getItemNum()); 70 copyFormat.setFormat(format.getFormat()); 71 copyFormat.setInventoryQuantity(format.getInventoryQuantity()); 72 copyFormat.setReorderTrigger(format.getReorderTrigger()); 73 copyFormat.setWeight(format.getWeight()); 74 copyFormat.setHeight(format.getHeight()); 75 copyFormat.setWidth(format.getWidth()); 76 copyFormat.setDepth(format.getDepth()); 77 copyFormat.setProductInode(product.getInode()); 78 } 79 catch(Exception ex) 80 { 81 Logger.debug(ProductFormatFactory.class,ex.toString()); 82 } 83 copyFormat.setInode(0); 84 String formatName = copyFormat.getFormatName(); 85 formatName += " COPY"; 86 copyFormat.setFormatName(formatName); 87 ProductFormatFactory.saveProductFormat(copyFormat); 88 89 List <ProductPrice> prices = ProductPriceFactory.getAllProductPricesByFormat(format); 91 for (ProductPrice price : prices) { 92 ProductPriceFactory.copyProductPrice(copyFormat,price); 93 } 94 } 95 96 public static ProductFormat getProductFormat(String inode) { 97 return (ProductFormat) InodeFactory.getInode(inode,ProductFormat.class); 98 } 99 100 public static ProductFormat getProductFormat(long inode) { 101 return (ProductFormat) InodeFactory.getInode(inode,ProductFormat.class); 102 } 103 104 public static ProductFormat getProductFormatByItemNumber(String number) { 105 return (ProductFormat) InodeFactory.getInodeOfClassByCondition(DiscountCode.class, "item_num = " + number); 106 } 107 108 109 } 110 | Popular Tags |