001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }