001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.shopping.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portlet.shopping.model.ShoppingItem;
020    import com.liferay.portlet.shopping.model.ShoppingItemPrice;
021    import com.liferay.portlet.shopping.model.ShoppingItemPriceConstants;
022    import com.liferay.portlet.shopping.service.base.ShoppingItemPriceLocalServiceBaseImpl;
023    
024    import java.util.ArrayList;
025    import java.util.List;
026    
027    /**
028     * @author Brian Wing Shun Chan
029     */
030    public class ShoppingItemPriceLocalServiceImpl
031            extends ShoppingItemPriceLocalServiceBaseImpl {
032    
033            public List<ShoppingItemPrice> getItemPrices(long itemId)
034                    throws PortalException, SystemException {
035    
036                    ShoppingItem item = shoppingItemPersistence.findByPrimaryKey(itemId);
037    
038                    List<ShoppingItemPrice> itemPrices =
039                            shoppingItemPricePersistence.findByItemId(itemId);
040    
041                    if (itemPrices.isEmpty()) {
042                            itemPrices = new ArrayList<ShoppingItemPrice>();
043    
044                            ShoppingItemPrice itemPrice = shoppingItemPricePersistence.create(
045                                    0);
046    
047                            itemPrice.setItemId(itemId);
048                            itemPrice.setMinQuantity(item.getMinQuantity());
049                            itemPrice.setMaxQuantity(item.getMaxQuantity());
050                            itemPrice.setPrice(item.getPrice());
051                            itemPrice.setDiscount(item.getDiscount());
052                            itemPrice.setTaxable(item.isTaxable());
053                            itemPrice.setShipping(item.getShipping());
054                            itemPrice.setUseShippingFormula(item.isUseShippingFormula());
055                            itemPrice.setStatus(
056                                    ShoppingItemPriceConstants.STATUS_ACTIVE_DEFAULT);
057    
058                            itemPrices.add(itemPrice);
059                    }
060    
061                    return itemPrices;
062            }
063    
064    }