Search in sources :

Example 11 with Category

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

the class CategoryParentCategoryFieldPersistenceProvider method populateValue.

@Override
public MetadataProviderResponse populateValue(PopulateValueRequest populateValueRequest, Serializable instance) {
    if (!canHandlePersistence(populateValueRequest, instance)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    boolean handled = false;
    if (extensionManager != null) {
        ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategory(populateValueRequest.getProperty(), (Category) instance);
        handled = ExtensionResultStatusType.NOT_HANDLED != result;
    }
    if (!handled || BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) {
        Long requestedValue = null;
        if (!StringUtils.isEmpty(populateValueRequest.getRequestedValue())) {
            requestedValue = Long.parseLong(populateValueRequest.getRequestedValue());
        }
        boolean dirty = checkDirtyState((Category) instance, requestedValue);
        if (dirty) {
            populateValueRequest.getProperty().setIsDirty(true);
            if (requestedValue != null) {
                ((Category) instance).setParentCategory((Category) populateValueRequest.getPersistenceManager().getDynamicEntityDao().find(CategoryImpl.class, requestedValue));
            } else {
                ((Category) instance).setParentCategory(null);
            }
        }
    }
    return MetadataProviderResponse.HANDLED_BREAK;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType)

Example 12 with Category

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

the class CategoryParentCategoryFieldPersistenceProvider method getDefaultCategory.

protected Category getDefaultCategory(Category category) {
    Category response = null;
    List<CategoryXref> xrefs = category.getAllParentCategoryXrefs();
    if (!CollectionUtils.isEmpty(xrefs)) {
        for (CategoryXref xref : xrefs) {
            if (xref.getCategory().isActive() && xref.getDefaultReference() != null && xref.getDefaultReference()) {
                response = xref.getCategory();
                break;
            }
        }
    }
    return response;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryXref(org.broadleafcommerce.core.catalog.domain.CategoryXref)

Example 13 with Category

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

the class ProductParentCategoryFieldPersistenceProvider method extractValue.

@Override
public MetadataProviderResponse extractValue(ExtractValueRequest extractValueRequest, Property property) {
    if (!canHandleExtraction(extractValueRequest, property)) {
        return MetadataProviderResponse.NOT_HANDLED;
    }
    Category category = getDefaultCategory((Product) extractValueRequest.getEntity());
    if (category != null) {
        property.setValue(String.valueOf(category.getId()));
        property.setDisplayValue(category.getName());
    }
    return MetadataProviderResponse.HANDLED_BREAK;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category)

Example 14 with Category

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

the class ProductParentCategoryFieldPersistenceProvider method getDefaultCategory.

protected Category getDefaultCategory(Product product) {
    Category response = null;
    List<CategoryProductXref> xrefs = product.getAllParentCategoryXrefs();
    if (!CollectionUtils.isEmpty(xrefs)) {
        for (CategoryProductXref xref : xrefs) {
            if (xref.getCategory().isActive() && xref.getDefaultReference() != null && xref.getDefaultReference()) {
                response = xref.getCategory();
                break;
            }
        }
    }
    return response;
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref)

Example 15 with Category

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

the class AdminProductController method modifyAddEntityForm.

@Override
protected void modifyAddEntityForm(EntityForm ef, Map<String, String> pathVars) {
    String defaultCategoryUrlPrefix = null;
    Field defaultCategory = ef.findField("defaultCategory");
    if (defaultCategory != null && StringUtils.isNotBlank(defaultCategory.getValue())) {
        Category cat = catalogService.findCategoryById(Long.parseLong(defaultCategory.getValue()));
        defaultCategoryUrlPrefix = cat.getUrl();
    }
    Field overrideGeneratedUrl = ef.findField("overrideGeneratedUrl");
    if (overrideGeneratedUrl != null) {
        overrideGeneratedUrl.setFieldType(SupportedFieldType.HIDDEN.toString().toLowerCase());
        boolean overriddenUrl = Boolean.parseBoolean(overrideGeneratedUrl.getValue());
        Field fullUrl = ef.findField("url");
        if (fullUrl != null) {
            fullUrl.withAttribute("overriddenUrl", overriddenUrl).withAttribute("sourceField", "defaultSku--name").withAttribute("toggleField", "overrideGeneratedUrl").withAttribute("prefix-selector", "#field-defaultCategory").withAttribute("prefix", defaultCategoryUrlPrefix).withFieldType(SupportedFieldType.GENERATED_URL.toString().toLowerCase());
        }
    }
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) Category(org.broadleafcommerce.core.catalog.domain.Category)

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