use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method buildOfferItemQualifierRuleTypeProperty.
protected Property buildOfferItemQualifierRuleTypeProperty(Property qualifiersCanBeQualifiers, Property qualifiersCanBeTargets) {
String offerItemQualifierRuleType;
boolean canBeQualifiers = qualifiersCanBeQualifiers == null ? false : Boolean.parseBoolean(qualifiersCanBeQualifiers.getValue());
boolean canBeTargets = qualifiersCanBeTargets == null ? false : Boolean.parseBoolean(qualifiersCanBeTargets.getValue());
if (canBeTargets && canBeQualifiers) {
offerItemQualifierRuleType = OfferItemRestrictionRuleType.QUALIFIER_TARGET.getType();
} else if (canBeTargets) {
offerItemQualifierRuleType = OfferItemRestrictionRuleType.TARGET.getType();
} else if (canBeQualifiers) {
offerItemQualifierRuleType = OfferItemRestrictionRuleType.QUALIFIER.getType();
} else {
offerItemQualifierRuleType = OfferItemRestrictionRuleType.NONE.getType();
}
Property property = new Property();
property.setName(OFFER_ITEM_QUALIFIER_RULE_TYPE);
property.setValue(offerItemQualifierRuleType);
return property;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
addIsActiveFiltering(cto);
DynamicResultSet resultSet = helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
String customCriteria = "";
if (persistencePackage.getCustomCriteria().length > 0) {
customCriteria = persistencePackage.getCustomCriteria()[0];
}
for (Entity entity : resultSet.getRecords()) {
Property discountType = entity.findProperty("discountType");
Property discountValue = entity.findProperty("value");
String value = discountValue.getValue();
if (discountType == null || StringUtils.isBlank(discountType.getValue())) {
discountValue.setValue("");
} else if (discountType.getValue().equals("PERCENT_OFF")) {
value = !value.contains(".") ? value : value.replaceAll("0*$", "").replaceAll("\\.$", "");
discountValue.setValue(value + "%");
} else if (discountType.getValue().equals("AMOUNT_OFF")) {
Locale locale = BroadleafRequestContext.getBroadleafRequestContext().getLocale();
BroadleafCurrency currency = BroadleafRequestContext.getBroadleafRequestContext().getBroadleafCurrency();
NumberFormat nf = BroadleafCurrencyUtils.getNumberFormatFromCache(locale.getJavaLocale(), currency.getJavaCurrency());
discountValue.setValue(nf.format(new BigDecimal(value)));
}
Property timeRule = entity.findProperty("offerMatchRules---TIME");
entity.addProperty(buildAdvancedVisibilityOptionsProperty(timeRule));
Property offerItemQualifierRuleType = entity.findProperty(OFFER_ITEM_QUALIFIER_RULE_TYPE);
entity.addProperty(buildQualifiersCanBeQualifiersProperty(offerItemQualifierRuleType));
entity.addProperty(buildQualifiersCanBeTargetsProperty(offerItemQualifierRuleType));
Property offerItemTargetRuleType = entity.findProperty(OFFER_ITEM_TARGET_RULE_TYPE);
entity.addProperty(buildStackableProperty(offerItemTargetRuleType));
if (!"listGridView".equals(customCriteria)) {
String setValue = discountValue.getValue();
setValue = setValue.replaceAll("\\%", "").replaceAll("\\$", "");
discountValue.setValue(setValue);
}
addIsActiveStatus(helper, entity);
}
return resultSet;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method buildAdvancedVisibilityOptionsProperty.
protected Property buildAdvancedVisibilityOptionsProperty(Property timeRule) {
Property advancedLabel = new Property();
advancedLabel.setName(SHOW_ADVANCED_VISIBILITY_OPTIONS);
advancedLabel.setValue((timeRule.getValue() == null) ? "true" : "false");
return advancedLabel;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method getBlankConsolidatedOptionProperty.
/**
* @return a blank {@link Property} corresponding to the CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME
*/
public Property getBlankConsolidatedOptionProperty() {
Property optionValueProperty = new Property();
optionValueProperty.setName(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME);
optionValueProperty.setValue("");
return optionValueProperty;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method getConsolidatedOptionProperty.
/**
* Returns a {@link Property} filled out with a delimited list of the <b>values</b> that are passed in. This should be
* invoked on a fetch and the returned property should be added to the fetched {@link Entity} dto.
*
* @param values
* @return
* @see {@link #createConsolidatedOptionField(Class)};
*/
public Property getConsolidatedOptionProperty(Collection<ProductOptionValue> values) {
Property optionValueProperty = new Property();
optionValueProperty.setName(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME);
// order the values by the display order of their correspond product option
// Collections.sort(values, new Comparator<ProductOptionValue>() {
//
// @Override
// public int compare(ProductOptionValue value1, ProductOptionValue value2) {
// return new CompareToBuilder().append(value1.getProductOption().getDisplayOrder(),
// value2.getProductOption().getDisplayOrder()).toComparison();
// }
// });
ArrayList<String> stringValues = new ArrayList<>();
CollectionUtils.collect(values, new Transformer() {
@Override
public Object transform(Object input) {
return ((ProductOptionValue) input).getAttributeValue();
}
}, stringValues);
optionValueProperty.setValue(StringUtils.join(stringValues, CONSOLIDATED_PRODUCT_OPTIONS_DELIMETER));
return optionValueProperty;
}
Aggregations