Search in sources :

Example 1 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class CandidateItemOfferTest method setUp.

@Override
protected void setUp() throws Exception {
    OfferDataItemProvider dataProvider = new OfferDataItemProvider();
    CandidateItemOfferImpl candidate = new CandidateItemOfferImpl();
    Category category1 = new CategoryImpl();
    category1.setName("test1");
    category1.setId(1L);
    Product product1 = new ProductImpl();
    Sku sku1 = new SkuImpl();
    sku1.setName("test1");
    sku1.setDiscountable(true);
    sku1.setRetailPrice(new Money(19.99D));
    product1.setDefaultSku(sku1);
    CategoryProductXref xref1 = new CategoryProductXrefImpl();
    xref1.setProduct(product1);
    xref1.setCategory(category1);
    category1.getAllProductXrefs().add(xref1);
    Category category2 = new CategoryImpl();
    category2.setName("test2");
    category2.setId(2L);
    Product product2 = new ProductImpl();
    Sku sku2 = new SkuImpl();
    sku2.setName("test2");
    sku2.setDiscountable(true);
    sku2.setRetailPrice(new Money(29.99D));
    product2.setDefaultSku(sku2);
    CategoryProductXref xref2 = new CategoryProductXrefImpl();
    xref2.setProduct(product2);
    xref2.setCategory(category2);
    category2.getAllProductXrefs().add(xref2);
    DiscreteOrderItemImpl orderItem1 = new DiscreteOrderItemImpl();
    orderItem1.setCategory(category1);
    orderItem1.setName("test1");
    orderItem1.setOrderItemType(OrderItemType.DISCRETE);
    orderItem1.setProduct(product1);
    orderItem1.setQuantity(2);
    orderItem1.setSku(sku1);
    Order order = new OrderImpl();
    orderItem1.setOrder(order);
    promotableOrder = new PromotableOrderImpl(order, new PromotableItemFactoryImpl(), false);
    offer = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))").get(0);
    candidateOffer = new PromotableCandidateItemOfferImpl(promotableOrder, offer);
    promotableOrderItem = new PromotableOrderItemImpl(orderItem1, null, new PromotableItemFactoryImpl(), false);
    OrderItemPriceDetail pdetail = new OrderItemPriceDetailImpl();
    pdetail.setOrderItem(orderItem1);
    pdetail.setQuantity(2);
    priceDetail = new PromotableOrderItemPriceDetailImpl(promotableOrderItem, 2);
    List<PromotableOrderItem> items = new ArrayList<PromotableOrderItem>();
    items.add(promotableOrderItem);
    promotableCandidate = new PromotableCandidateItemOfferImpl(promotableOrder, offer);
    OfferTargetCriteriaXref xref = offer.getTargetItemCriteriaXref().iterator().next();
    promotableCandidate.getCandidateTargetsMap().put(xref.getOfferItemCriteria(), items);
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) PromotableOrderImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) OrderItemPriceDetailImpl(org.broadleafcommerce.core.order.domain.OrderItemPriceDetailImpl) PromotableOrderItemPriceDetailImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailImpl) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) PromotableCandidateItemOfferImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) Money(org.broadleafcommerce.common.money.Money) PromotableItemFactoryImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableItemFactoryImpl) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) PromotableOrderItemImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemImpl) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) PromotableOrderImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) PromotableCandidateItemOfferImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl) OfferDataItemProvider(org.broadleafcommerce.core.offer.service.OfferDataItemProvider) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail) Sku(org.broadleafcommerce.core.catalog.domain.Sku) PromotableOrderItemPriceDetailImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailImpl)

Example 2 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class CategoryDaoTest method testSetFeaturedProducts.

@Test(groups = { "testSetFeaturedProducts" }, dataProvider = "basicCategory", dataProviderClass = CategoryDaoDataProvider.class)
@Transactional
public void testSetFeaturedProducts(Category category) {
    category = catalogService.saveCategory(category);
    Sku sku = new SkuImpl();
    sku.setDescription("This thing will change your life");
    sku.setName("Test Product");
    catalogService.saveSku(sku);
    Product product = new ProductImpl();
    product.setModel("KGX200");
    product.setDefaultSku(sku);
    product = catalogService.saveProduct(product);
    FeaturedProduct featuredProduct = new FeaturedProductImpl();
    featuredProduct.setCategory(category);
    featuredProduct.setProduct(product);
    featuredProduct.setPromotionMessage("BUY ME NOW!!!!");
    List<FeaturedProduct> featuredProducts = new ArrayList<>();
    featuredProducts.add(featuredProduct);
    category.setFeaturedProducts(featuredProducts);
    category = catalogService.saveCategory(category);
    Category categoryTest = categoryDao.readCategoryById(category.getId());
    FeaturedProduct featuredProductTest = categoryTest.getFeaturedProducts().get(0);
    assert (featuredProductTest.getPromotionMessage() == "BUY ME NOW!!!!");
    assert (featuredProductTest.getProduct().getModel().equals("KGX200"));
}
Also used : SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) FeaturedProductImpl(org.broadleafcommerce.core.catalog.domain.FeaturedProductImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) Category(org.broadleafcommerce.core.catalog.domain.Category) FeaturedProduct(org.broadleafcommerce.core.catalog.domain.FeaturedProduct) ArrayList(java.util.ArrayList) FeaturedProduct(org.broadleafcommerce.core.catalog.domain.FeaturedProduct) Product(org.broadleafcommerce.core.catalog.domain.Product) FeaturedProductImpl(org.broadleafcommerce.core.catalog.domain.FeaturedProductImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class MVELTest method createProduct.

private Product createProduct() {
    Category category = new CategoryImpl();
    category.setName("t-shirt");
    category = catalogService.saveCategory(category);
    Product product = new ProductImpl();
    Sku sku = new SkuImpl();
    sku = catalogService.saveSku(sku);
    product.setDefaultSku(sku);
    product.setName("Lavender Soap");
    Calendar activeStartCal = Calendar.getInstance();
    activeStartCal.add(Calendar.DAY_OF_YEAR, -2);
    product.setActiveStartDate(activeStartCal.getTime());
    product.setCategory(category);
    product.getAllParentCategoryXrefs().clear();
    product = catalogService.saveProduct(product);
    CategoryProductXref categoryXref = new CategoryProductXrefImpl();
    categoryXref.setProduct(product);
    categoryXref.setCategory(category);
    product.getAllParentCategoryXrefs().add(categoryXref);
    product = catalogService.saveProduct(product);
    return product;
}
Also used : CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) Category(org.broadleafcommerce.core.catalog.domain.Category) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) Calendar(java.util.Calendar) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 4 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class CategoryBreadcrumbServiceExtensionHandler method determineFirstCategory.

protected Category determineFirstCategory(String testUrl, Map<String, String[]> params, ExtensionResultHolder<List<BreadcrumbDTO>> holder) {
    BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
    Category returnCategory = null;
    if (brc != null && brc.getRequest() != null) {
        if (returnCategory == null) {
            returnCategory = getMatchingCategoryFromProduct(brc, testUrl, params);
        }
        if (returnCategory == null) {
            returnCategory = getCategoryFromCategoryAttribute(brc, testUrl, params);
        }
        if (returnCategory == null) {
            returnCategory = getCategoryFromUrl(brc, testUrl, params);
        }
    }
    return returnCategory;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) BroadleafRequestContext(org.broadleafcommerce.common.web.BroadleafRequestContext)

Example 5 with Category

use of org.broadleafcommerce.core.catalog.domain.Category in project BroadleafCommerce by BroadleafCommerce.

the class LegacyOrderServiceImpl method addItemToOrder.

@Override
public Order addItemToOrder(Long orderId, OrderItemRequestDTO orderItemRequestDTO, boolean priceOrder) throws PricingException {
    if (orderItemRequestDTO.getQuantity() == null || orderItemRequestDTO.getQuantity() == 0) {
        LOG.debug("Not adding item to order because quantity is zero.");
        return null;
    }
    if (orderItemRequestDTO.getQuantity() < 0) {
        throw new IllegalArgumentException("Quantity cannot be negative");
    }
    Order order = validateOrder(orderId);
    Product product = validateProduct(orderItemRequestDTO.getProductId());
    Sku sku = determineSku(product, orderItemRequestDTO.getSkuId(), orderItemRequestDTO.getItemAttributes());
    if (sku == null) {
        return null;
    }
    Category category = determineCategory(product, orderItemRequestDTO.getCategoryId());
    if (product == null || !(product instanceof ProductBundle)) {
        DiscreteOrderItem item = orderItemService.createDiscreteOrderItem(createDiscreteOrderItemRequest(order, null, sku, product, category, orderItemRequestDTO.getQuantity(), orderItemRequestDTO.getItemAttributes()));
        item.setOrder(order);
        List<OrderItem> orderItems = order.getOrderItems();
        orderItems.add(item);
        return updateOrder(order, priceOrder);
    } else {
        ProductBundle bundle = (ProductBundle) product;
        BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItemDao.create(OrderItemType.BUNDLE);
        bundleOrderItem.setQuantity(orderItemRequestDTO.getQuantity());
        bundleOrderItem.setCategory(category);
        bundleOrderItem.setSku(sku);
        bundleOrderItem.setName(product.getName());
        bundleOrderItem.setProductBundle(bundle);
        bundleOrderItem.setOrder(order);
        for (SkuBundleItem skuBundleItem : bundle.getSkuBundleItems()) {
            Product bundleProduct = skuBundleItem.getBundle();
            Sku bundleSku = skuBundleItem.getSku();
            Category bundleCategory = determineCategory(bundleProduct, orderItemRequestDTO.getCategoryId());
            DiscreteOrderItem bundleDiscreteItem = orderItemService.createDiscreteOrderItem(createDiscreteOrderItemRequest(null, bundleOrderItem, bundleSku, bundleProduct, bundleCategory, skuBundleItem.getQuantity(), orderItemRequestDTO.getItemAttributes()));
            bundleDiscreteItem.setBundleOrderItem(bundleOrderItem);
            bundleDiscreteItem.setSkuBundleItem(skuBundleItem);
            bundleOrderItem.getDiscreteOrderItems().add(bundleDiscreteItem);
        }
        List<OrderItem> orderItems = order.getOrderItems();
        orderItems.add(bundleOrderItem);
        return updateOrder(order, priceOrder);
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Category(org.broadleafcommerce.core.catalog.domain.Category) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) SkuBundleItem(org.broadleafcommerce.core.catalog.domain.SkuBundleItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Aggregations

Category (org.broadleafcommerce.core.catalog.domain.Category)49 Product (org.broadleafcommerce.core.catalog.domain.Product)18 Sku (org.broadleafcommerce.core.catalog.domain.Sku)13 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)10 Order (org.broadleafcommerce.core.order.domain.Order)8 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)7 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)7 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)7 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)7 ArrayList (java.util.ArrayList)6 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)6 CategoryXref (org.broadleafcommerce.core.catalog.domain.CategoryXref)6 Money (org.broadleafcommerce.common.money.Money)5 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)5 Customer (org.broadleafcommerce.profile.core.domain.Customer)5 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)4 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)4 Calendar (java.util.Calendar)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)3