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