Search in sources :

Example 21 with Category

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

the class CategorySiteMapGenerator method addSiteMapEntries.

@Override
public void addSiteMapEntries(SiteMapGeneratorConfiguration smgc, SiteMapBuilder siteMapBuilder) {
    if (CategorySiteMapGeneratorConfiguration.class.isAssignableFrom(smgc.getClass())) {
        CategorySiteMapGeneratorConfiguration categorySMGC = (CategorySiteMapGeneratorConfiguration) smgc;
        // Recursively construct the category SiteMap URLs
        Long rootCategoryId = categorySMGC.getRootCategory().getId();
        Category rootCategory = categoryDao.readCategoryById(rootCategoryId);
        addCategorySiteMapEntries(rootCategory, 0, categorySMGC, siteMapBuilder);
    }
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) CategorySiteMapGeneratorConfiguration(org.broadleafcommerce.core.catalog.domain.CategorySiteMapGeneratorConfiguration)

Example 22 with Category

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

the class CategoryCustomPersistenceHandler method getExistingDefaultCategory.

protected Category getExistingDefaultCategory(Category category) {
    // Make sure we get the actual field value - not something manipulated in the getter
    Category parentCategory;
    try {
        Field defaultCategory = CategoryImpl.class.getDeclaredField(DEFAULT_PARENT_CATEGORY);
        defaultCategory.setAccessible(true);
        parentCategory = (Category) defaultCategory.get(category);
    } catch (NoSuchFieldException e) {
        throw ExceptionHelper.refineException(e);
    } catch (IllegalAccessException e) {
        throw ExceptionHelper.refineException(e);
    }
    return parentCategory;
}
Also used : Field(java.lang.reflect.Field) Category(org.broadleafcommerce.core.catalog.domain.Category)

Example 23 with Category

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

the class CategoryCustomPersistenceHandler method add.

@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        entity = validateParentCategory(entity, true);
        if (entity.isValidationFailure()) {
            return entity;
        } else {
            PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
            Category adminInstance = (Category) Class.forName(entity.getType()[0]).newInstance();
            Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Category.class.getName(), persistencePerspective);
            adminInstance = (Category) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
            adminInstance = dynamicEntityDao.merge(adminInstance);
            boolean handled = false;
            if (extensionManager != null) {
                ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategoryForAdd(persistencePackage, adminInstance);
                handled = ExtensionResultStatusType.NOT_HANDLED != result;
            }
            if (!handled) {
                setupXref(adminInstance);
            }
            adminInstance = dynamicEntityDao.merge(adminInstance);
            return helper.getRecord(adminProperties, adminInstance, null, null);
        }
    } catch (Exception e) {
        throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) Category(org.broadleafcommerce.core.catalog.domain.Category) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 24 with Category

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

the class ChildCategoriesCustomPersistenceHandler method checkCategoryAncestry.

protected void checkCategoryAncestry(Category category, Set<Category> knownAncestors) {
    List<CategoryXref> parentXrefs = ListUtils.emptyIfNull(category.getAllParentCategoryXrefs());
    knownAncestors.add(category);
    for (CategoryXref parentXref : parentXrefs) {
        final Category parentCategory = parentXref.getCategory();
        if (!knownAncestors.contains(parentCategory)) {
            checkCategoryAncestry(parentCategory, knownAncestors);
        }
    }
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref)

Example 25 with Category

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

the class OrderItemServiceImpl method buildOrderItemFromDTO.

@Override
public OrderItem buildOrderItemFromDTO(Order order, OrderItemRequestDTO orderItemRequestDTO) {
    Sku sku = null;
    if (orderItemRequestDTO.getSkuId() != null) {
        sku = catalogService.findSkuById(orderItemRequestDTO.getSkuId());
    }
    Product product = null;
    if (orderItemRequestDTO.getProductId() != null) {
        product = catalogService.findProductById(orderItemRequestDTO.getProductId());
    }
    Category category = null;
    if (orderItemRequestDTO.getCategoryId() != null) {
        category = catalogService.findCategoryById(orderItemRequestDTO.getCategoryId());
    }
    if (category == null && product != null) {
        category = product.getDefaultCategory();
    }
    OrderItem item;
    if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
        NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequestDTO;
        OrderItemRequest itemRequest = new OrderItemRequest();
        itemRequest.setQuantity(ndr.getQuantity());
        itemRequest.setRetailPriceOverride(ndr.getOverrideRetailPrice());
        itemRequest.setSalePriceOverride(ndr.getOverrideSalePrice());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setItemName(ndr.getItemName());
        itemRequest.setOrder(order);
        item = createOrderItem(itemRequest);
    } else if (product == null || !(product instanceof ProductBundle)) {
        DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
        itemRequest.setCategory(category);
        itemRequest.setProduct(product);
        itemRequest.setSku(sku);
        itemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
        itemRequest.setOrder(order);
        itemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        itemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createDiscreteOrderItem(itemRequest);
    } else {
        ProductBundleOrderItemRequest bundleItemRequest = new ProductBundleOrderItemRequest();
        bundleItemRequest.setCategory(category);
        bundleItemRequest.setProductBundle((ProductBundle) product);
        bundleItemRequest.setSku(sku);
        bundleItemRequest.setQuantity(orderItemRequestDTO.getQuantity());
        bundleItemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
        bundleItemRequest.setName(product.getName());
        bundleItemRequest.setOrder(order);
        bundleItemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
        bundleItemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
        item = createBundleOrderItem(bundleItemRequest, false);
    }
    if (orderItemRequestDTO.getParentOrderItemId() != null) {
        OrderItem parent = readOrderItemById(orderItemRequestDTO.getParentOrderItemId());
        item.setParentOrderItem(parent);
    }
    if (orderItemRequestDTO.getHasConfigurationError()) {
        item.setHasValidationError(true);
    }
    if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
        ConfigurableOrderItemRequest configRequest = (ConfigurableOrderItemRequest) orderItemRequestDTO;
        if (configRequest.getHasConfigurationError()) {
            item.setHasValidationError(true);
        }
        if (!configRequest.getDiscountsAllowed()) {
            item.setDiscountingAllowed(false);
        }
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) AbstractOrderItemRequest(org.broadleafcommerce.core.order.service.call.AbstractOrderItemRequest) GiftWrapOrderItemRequest(org.broadleafcommerce.core.order.service.call.GiftWrapOrderItemRequest) OrderItemRequest(org.broadleafcommerce.core.order.service.call.OrderItemRequest) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) BundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.BundleOrderItemRequest) Category(org.broadleafcommerce.core.catalog.domain.Category) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

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