KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > portlets > product > model > ProductFormat


1 package com.dotmarketing.portlets.product.model;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
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 /**
15  *
16  * @author David
17  *
18  */

19 public class ProductFormat extends Inode {
20     
21     private static final long serialVersionUID = 1L;
22     private long productInode; //persistent
23
private String JavaDoc formatName; //persistent
24
private String JavaDoc itemNumber; //persistent
25
private String JavaDoc format; //persistent
26
private int inventoryQuantity; //persistent
27
private int reorderTrigger; //persistent
28
private float weight; //persistent
29
private int width; //persistent
30
private int height; //persistent
31
private int depth; //persistent
32

33     public ProductFormat(long productInode, String JavaDoc formatName, String JavaDoc itemNum, String JavaDoc 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 JavaDoc formatName, String JavaDoc 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 JavaDoc getFormatName() {
64         return this.formatName;
65     }
66
67     public void setFormatName(String JavaDoc formatName) {
68         this.formatName = formatName;
69     }
70     public String JavaDoc getItemNum() {
71         return this.itemNumber;
72     }
73
74     public void setItemNum(String JavaDoc itemNum) {
75         this.itemNumber = itemNum;
76     }
77     public String JavaDoc getFormat() {
78         return this.format;
79     }
80
81     public void setFormat(String JavaDoc 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 JavaDoc<ProductPrice> bulkPrices = getBulkPrices();
135         if (bulkPrices.size() > 1)
136         {
137             hasBulkPrice = true;
138         }
139         return hasBulkPrice;
140     }
141     
142     public List JavaDoc<ProductPrice> getBulkPrices()
143     {
144         List JavaDoc<ProductPrice> bulkPrices = null;
145         bulkPrices = ProductPriceFactory.getAllBulkProductPricesByFormat(this);
146         return bulkPrices;
147     }
148       
149     public ProductPrice getQuantityPrice(int quantity)
150     {
151         List JavaDoc<DiscountCode> discounts = new ArrayList JavaDoc<DiscountCode>();
152         return getQuantityPrice(quantity,discounts);
153     }
154     
155     public ProductPrice getQuantityPrice(int quantity,List JavaDoc<DiscountCode> discounts)
156     {
157         float totalDiscountPartner = 0;
158         float totalDiscountRetail = 0;
159         List JavaDoc<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                     //throw new Exception("There is no price for this quantity");
184
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