Search in sources :

Example 1 with SkuBundleItemImpl

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

the class CommonSetupBaseTest method addProductBundle.

public ProductBundle addProductBundle() {
    // Create the product
    Product p = addTestProduct("bundleproduct1", "bundlecat1");
    // Create the sku for the ProductBundle object
    Sku bundleSku = catalogService.createSku();
    bundleSku.setName(p.getName());
    bundleSku.setRetailPrice(new Money(44.99));
    bundleSku.setActiveStartDate(p.getActiveStartDate());
    bundleSku.setActiveEndDate(p.getActiveEndDate());
    bundleSku.setDiscountable(true);
    // Create the ProductBundle and associate the sku
    ProductBundle bundle = (ProductBundle) catalogService.createProduct(ProductType.BUNDLE);
    bundle.setDefaultCategory(p.getDefaultCategory());
    bundle.setDefaultSku(bundleSku);
    bundle = (ProductBundle) catalogService.saveProduct(bundle);
    // Reverse-associate the ProductBundle to the sku (Must be done this way because it's a
    // bidirectional OneToOne relationship
    // bundleSku.setDefaultProduct(bundle);
    // catalogService.saveSku(bundleSku);
    // Wrap the product/sku that is part of the bundle in a SkuBundleItem
    SkuBundleItem skuBundleItem = new SkuBundleItemImpl();
    skuBundleItem.setBundle(bundle);
    skuBundleItem.setQuantity(1);
    skuBundleItem.setSku(p.getDefaultSku());
    // Add the SkuBundleItem to the ProductBundle
    bundle.getSkuBundleItems().add(skuBundleItem);
    bundle = (ProductBundle) catalogService.saveProduct(bundle);
    return bundle;
}
Also used : Money(org.broadleafcommerce.common.money.Money) SkuBundleItem(org.broadleafcommerce.core.catalog.domain.SkuBundleItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SkuBundleItemImpl(org.broadleafcommerce.core.catalog.domain.SkuBundleItemImpl)

Aggregations

Money (org.broadleafcommerce.common.money.Money)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)1 Sku (org.broadleafcommerce.core.catalog.domain.Sku)1 SkuBundleItem (org.broadleafcommerce.core.catalog.domain.SkuBundleItem)1 SkuBundleItemImpl (org.broadleafcommerce.core.catalog.domain.SkuBundleItemImpl)1