1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.shopping.service.impl;
16  
17  import com.liferay.portal.kernel.exception.PortalException;
18  import com.liferay.portal.kernel.exception.SystemException;
19  import com.liferay.portlet.shopping.model.ShoppingItem;
20  import com.liferay.portlet.shopping.model.ShoppingItemPrice;
21  import com.liferay.portlet.shopping.model.ShoppingItemPriceConstants;
22  import com.liferay.portlet.shopping.service.base.ShoppingItemPriceLocalServiceBaseImpl;
23  
24  import java.util.ArrayList;
25  import java.util.List;
26  
27  /**
28   * <a href="ShoppingItemPriceLocalServiceImpl.java.html"><b><i>View Source</i>
29   * </b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class ShoppingItemPriceLocalServiceImpl
34      extends ShoppingItemPriceLocalServiceBaseImpl {
35  
36      public List<ShoppingItemPrice> getItemPrices(long itemId)
37          throws PortalException, SystemException {
38  
39          ShoppingItem item = shoppingItemPersistence.findByPrimaryKey(itemId);
40  
41          List<ShoppingItemPrice> itemPrices =
42              shoppingItemPricePersistence.findByItemId(itemId);
43  
44          if (itemPrices.isEmpty()) {
45              itemPrices = new ArrayList<ShoppingItemPrice>();
46  
47              ShoppingItemPrice itemPrice = shoppingItemPricePersistence.create(
48                  0);
49  
50              itemPrice.setItemId(itemId);
51              itemPrice.setMinQuantity(item.getMinQuantity());
52              itemPrice.setMaxQuantity(item.getMaxQuantity());
53              itemPrice.setPrice(item.getPrice());
54              itemPrice.setDiscount(item.getDiscount());
55              itemPrice.setTaxable(item.isTaxable());
56              itemPrice.setShipping(item.getShipping());
57              itemPrice.setUseShippingFormula(item.isUseShippingFormula());
58              itemPrice.setStatus(
59                  ShoppingItemPriceConstants.STATUS_ACTIVE_DEFAULT);
60  
61              itemPrices.add(itemPrice);
62          }
63  
64          return itemPrices;
65      }
66  
67  }