Search in sources :

Example 1 with CategoryXrefImpl

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

the class CategoryCustomPersistenceHandler method setupXref.

protected void setupXref(Category adminInstance) {
    if (isDefaultCategoryLegacyMode()) {
        CategoryXref categoryXref = new CategoryXrefImpl();
        categoryXref.setCategory(getExistingDefaultCategory(adminInstance));
        categoryXref.setSubCategory(adminInstance);
        if (!adminInstance.getAllParentCategoryXrefs().contains(categoryXref) && categoryXref.getCategory() != null) {
            adminInstance.getAllParentCategoryXrefs().add(categoryXref);
        }
    }
}
Also used : CategoryXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref)

Example 2 with CategoryXrefImpl

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

the class ChildCategoriesCustomPersistenceHandler method createXref.

protected CategoryXref createXref(Tuple<Category, Category> parentAndChild) {
    CategoryXref xref = new CategoryXrefImpl();
    xref.setCategory(parentAndChild.getFirst());
    xref.setSubCategory(parentAndChild.getSecond());
    return xref;
}
Also used : CategoryXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref)

Example 3 with CategoryXrefImpl

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

the class CatalogTest method testCatalog.

@Test(groups = { "testCatalog" })
@Transactional
public void testCatalog() throws Exception {
    Category category = new CategoryImpl();
    category.setName("Soaps");
    category = catalogService.saveCategory(category);
    Category category2 = new CategoryImpl();
    category2.setName("Towels");
    category2 = catalogService.saveCategory(category2);
    Category category3 = new CategoryImpl();
    category3.setName("SuperCategory");
    category3 = catalogService.saveCategory(category3);
    CategoryXref temp = new CategoryXrefImpl();
    temp.setCategory(category);
    temp.setSubCategory(category3);
    category3.getAllParentCategoryXrefs().add(temp);
    category3 = catalogService.saveCategory(category3);
    // Test category hierarchy
    Long cat3Id = category3.getId();
    category3 = null;
    category3 = catalogService.findCategoryById(cat3Id);
    category3.getAllParentCategoryXrefs().clear();
    CategoryXref temp2 = new CategoryXrefImpl();
    temp2.setCategory(category);
    temp2.setSubCategory(category3);
    category3.getAllParentCategoryXrefs().add(temp2);
    CategoryXref temp3 = new CategoryXrefImpl();
    temp3.setCategory(category2);
    temp3.setSubCategory(category3);
    category3.getAllParentCategoryXrefs().add(temp3);
    category3 = catalogService.saveCategory(category3);
    assert category3.getAllParentCategoryXrefs().size() == 2;
    Product newProduct = new ProductImpl();
    Sku newDefaultSku = new SkuImpl();
    newDefaultSku = catalogService.saveSku(newDefaultSku);
    newProduct.setDefaultSku(newDefaultSku);
    newProduct.setName("Lavender Soap");
    Calendar activeStartCal = Calendar.getInstance();
    activeStartCal.add(Calendar.DAY_OF_YEAR, -2);
    newProduct.setActiveStartDate(activeStartCal.getTime());
    // newProduct.setAllParentCategories(allParentCategories);
    newProduct.setDefaultCategory(category);
    newProduct.getAllParentCategoryXrefs().clear();
    newProduct = catalogService.saveProduct(newProduct);
    CategoryProductXref categoryXref = new CategoryProductXrefImpl();
    categoryXref.setProduct(newProduct);
    categoryXref.setCategory(category);
    newProduct.getAllParentCategoryXrefs().add(categoryXref);
    CategoryProductXref categoryXref2 = new CategoryProductXrefImpl();
    categoryXref2.setProduct(newProduct);
    categoryXref2.setCategory(category2);
    newProduct.getAllParentCategoryXrefs().add(categoryXref2);
    newProduct = catalogService.saveProduct(newProduct);
    Long newProductId = newProduct.getId();
    Product testProduct = catalogService.findProductById(newProductId);
    assert testProduct.getId().equals(testProduct.getId());
    Category testCategory = catalogService.findCategoryByName("Soaps");
    assert testCategory.getId().equals(category.getId());
    testCategory = catalogService.findCategoryById(category.getId());
    assert testCategory.getId().equals(category.getId());
    Media media = new MediaImpl();
    media.setAltText("test");
    media.setTitle("large");
    media.setUrl("http://myUrl");
    category.getCategoryMediaXref().put("large", new CategoryMediaXrefImpl(category, media, "large"));
    catalogService.saveCategory(testCategory);
    testCategory = catalogService.findCategoryById(category.getId());
    assert (testCategory.getCategoryMediaXref().get("large") != null);
    List<Category> categories = catalogService.findAllCategories();
    assert categories != null && categories.size() == 3;
    List<Product> products = catalogService.findAllProducts();
    boolean foundProduct = false;
    for (Product product : products) {
        if (product.getId().equals(newProductId)) {
            foundProduct = true;
        }
    }
    assert foundProduct == true;
    products = catalogService.findProductsByName(newProduct.getName());
    foundProduct = false;
    for (Product product : products) {
        if (product.getId().equals(newProductId)) {
            foundProduct = true;
        }
    }
    assert foundProduct == true;
    Sku newSku = new SkuImpl();
    newSku.setName("Under Armor T-Shirt -- Red");
    newSku.setRetailPrice(new Money(14.99));
    newSku.setActiveStartDate(activeStartCal.getTime());
    newSku = catalogService.saveSku(newSku);
    List<Sku> allSkus = new ArrayList<>();
    allSkus.add(newSku);
    newProduct.setAdditionalSkus(allSkus);
    newProduct = catalogService.saveProduct(newProduct);
    Long skuId = newProduct.getSkus().get(0).getId();
    Sku testSku = catalogService.findSkuById(skuId);
    assert testSku.getId().equals(skuId);
    List<Sku> testSkus = catalogService.findAllSkus();
    boolean foundSku = false;
    for (Sku sku : testSkus) {
        if (sku.getId().equals(skuId)) {
            foundSku = true;
        }
    }
    assert foundSku == true;
    List<Long> skuIds = new ArrayList<>();
    skuIds.add(skuId);
    testSkus = catalogService.findSkusByIds(skuIds);
    foundSku = false;
    for (Sku sku : testSkus) {
        if (sku.getId().equals(skuId)) {
            foundSku = true;
        }
    }
    assert foundSku == true;
}
Also used : CategoryXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl) Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) MediaImpl(org.broadleafcommerce.common.media.domain.MediaImpl) Calendar(java.util.Calendar) Media(org.broadleafcommerce.common.media.domain.Media) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) CategoryMediaXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryMediaXrefImpl) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CategoryXref (org.broadleafcommerce.core.catalog.domain.CategoryXref)3 CategoryXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryXrefImpl)3 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 Media (org.broadleafcommerce.common.media.domain.Media)1 MediaImpl (org.broadleafcommerce.common.media.domain.MediaImpl)1 Money (org.broadleafcommerce.common.money.Money)1 Category (org.broadleafcommerce.core.catalog.domain.Category)1 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)1 CategoryMediaXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryMediaXrefImpl)1 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)1 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)1 Sku (org.broadleafcommerce.core.catalog.domain.Sku)1 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)1 Transactional (org.springframework.transaction.annotation.Transactional)1 Test (org.testng.annotations.Test)1