| 1 package com.dotmarketing.portlets.product.model; 2 3 import java.util.ArrayList ; 4 import java.util.List ; 5 6 import com.dotmarketing.beans.Inode; 7 import com.dotmarketing.factories.InodeFactory; 8 import com.dotmarketing.util.Logger; 9 import com.dotmarketing.cms.product.model.Holder; 10 import com.dotmarketing.portlets.discountcode.factories.DiscountCodeFactory; 11 import com.dotmarketing.portlets.discountcode.model.DiscountCode; 12 import com.dotmarketing.portlets.product.factories.ProductPriceFactory; 13 14 19 public class ProductFormat extends Inode { 20 21 private static final long serialVersionUID = 1L; 22 private long productInode; private String formatName; private String itemNumber; private String format; private int inventoryQuantity; private int reorderTrigger; private float weight; private int width; private int height; private int depth; 33 public ProductFormat(long productInode, String formatName, String itemNum, String format, int inventoryQuantity, int reorderTrigger, float weight, int width, int height, int depth) { 34 this.productInode = productInode; 35 this.formatName = formatName; 36 this.itemNumber = itemNum; 37 this.format = format; 38 this.inventoryQuantity = inventoryQuantity; 39 this.reorderTrigger = reorderTrigger; 40 this.weight = weight; 41 this.width = width; 42 this.height = height; 43 this.depth = depth; 44 } 45 46 public ProductFormat() { 47 setType("ecom_product_format"); 48 } 49 50 public ProductFormat(long productInode, String formatName, String format) { 51 this.productInode = productInode; 52 this.formatName = formatName; 53 this.format = format; 54 } 55 56 public long getProductInode() { 57 return this.productInode; 58 } 59 60 public void setProductInode(long productInode) { 61 this.productInode = productInode; 62 } 63 public String getFormatName() { 64 return this.formatName; 65 } 66 67 public void setFormatName(String formatName) { 68 this.formatName = formatName; 69 } 70 public String getItemNum() { 71 return this.itemNumber; 72 } 73 74 public void setItemNum(String itemNum) { 75 this.itemNumber = itemNum; 76 } 77 public String getFormat() { 78 return this.format; 79 } 80 81 public void setFormat(String format) { 82 this.format = format; 83 } 84 public int getInventoryQuantity() { 85 return this.inventoryQuantity; 86 } 87 88 public void setInventoryQuantity(int inventoryQuantity) { 89 this.inventoryQuantity = inventoryQuantity; 90 } 91 public int getReorderTrigger() { 92 return this.reorderTrigger; 93 } 94 95 public void setReorderTrigger(int reorderTrigger) { 96 this.reorderTrigger = reorderTrigger; 97 } 98 public float getWeight() { 99 return this.weight; 100 } 101 102 public void setWeight(float weight) { 103 this.weight = weight; 104 } 105 public int getWidth() { 106 return this.width; 107 } 108 109 public void setWidth(int width) { 110 this.width = width; 111 } 112 public int getHeight() { 113 return this.height; 114 } 115 116 public void setHeight(int height) { 117 this.height = height; 118 } 119 public int getDepth() { 120 return this.depth; 121 } 122 123 public void setDepth(int depth) { 124 this.depth = depth; 125 } 126 127 public Product getProduct () { 128 return (Product)InodeFactory.getInode(productInode, Product.class); 129 } 130 131 public boolean getHasBulkPrices() 132 { 133 boolean hasBulkPrice = false; 134 List <ProductPrice> bulkPrices = getBulkPrices(); 135 if (bulkPrices.size() > 1) 136 { 137 hasBulkPrice = true; 138 } 139 return hasBulkPrice; 140 } 141 142 public List <ProductPrice> getBulkPrices() 143 { 144 List <ProductPrice> bulkPrices = null; 145 bulkPrices = ProductPriceFactory.getAllBulkProductPricesByFormat(this); 146 return bulkPrices; 147 } 148 149 public ProductPrice getQuantityPrice(int quantity) 150 { 151 List <DiscountCode> discounts = new ArrayList <DiscountCode>(); 152 return getQuantityPrice(quantity,discounts); 153 } 154 155 public ProductPrice getQuantityPrice(int quantity,List <DiscountCode> discounts) 156 { 157 float totalDiscountPartner = 0; 158 float totalDiscountRetail = 0; 159 List <ProductPrice> prices = null; 160 ProductPrice productPrice; 161 for(DiscountCode discount : discounts) 162 { 163 Holder holder = new Holder(); 164 holder.setQuantity(quantity); 165 holder.setFormat(this); 166 if (DiscountCodeFactory._potentialDiscount(holder,discount) && 167 discount.getNoBulkDisc() == true) 168 { 169 quantity = 1; 170 break; 171 } 172 } 173 174 prices = ProductPriceFactory.getQuantityPricePricesByFormat(this,quantity); 175 if (prices.size() == 0) 176 { 177 prices = ProductPriceFactory.getMinorQuantityPricePricesByFormat(this,quantity); 178 if (prices.size() == 0) 179 { 180 prices = ProductPriceFactory.getAllQuantityPricePricesByFormat(this,quantity); 181 if (prices.size() == 0) 182 { 183 Logger.error(this,"There is no price for this quantity"); 185 productPrice = new ProductPrice(); 186 productPrice.setMinQty(1); 187 productPrice.setMaxQty(Integer.MAX_VALUE); 188 productPrice.setPartnerPrice(0); 189 productPrice.setRetailPrice(0); 190 return productPrice; 191 } 192 else 193 productPrice = prices.get(0); 194 } 195 else 196 productPrice = prices.get(0); 197 } 198 else{ 199 productPrice = prices.get(0); 200 for(DiscountCode discount : discounts) 201 { 202 Holder holder = new Holder(); 203 holder.setQuantity(quantity); 204 holder.setFormat(this); 205 if (DiscountCodeFactory._potentialDiscount(holder,discount)) 206 { 207 if(discount.getDiscountType() == 1) 208 { 209 totalDiscountPartner += (discount.getDiscountAmount()/100)*productPrice.getPartnerPrice(); 210 totalDiscountRetail += (discount.getDiscountAmount()/100)*productPrice.getRetailPrice(); 211 } 212 else { 213 totalDiscountPartner += discount.getDiscountAmount(); 214 totalDiscountRetail += discount.getDiscountAmount(); 215 } 216 } 217 } 218 productPrice.setPartnerPriceWithDiscount(productPrice.getPartnerPrice() - totalDiscountPartner); 219 productPrice.setRetailPriceWithDiscount(productPrice.getRetailPrice() - totalDiscountRetail); 220 } 221 return productPrice; 222 } 223 } 224 | Popular Tags |