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);
}
}
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;
}
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);
}
}
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);
}
}
}
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;
}
Aggregations