Search in sources :

Example 66 with Property

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;
}
Also used : Property(org.broadleafcommerce.openadmin.dto.Property)

Example 67 with 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;
}
Also used : Locale(org.broadleafcommerce.common.locale.domain.Locale) Entity(org.broadleafcommerce.openadmin.dto.Entity) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet) Property(org.broadleafcommerce.openadmin.dto.Property) BigDecimal(java.math.BigDecimal) NumberFormat(java.text.NumberFormat)

Example 68 with Property

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;
}
Also used : Property(org.broadleafcommerce.openadmin.dto.Property)

Example 69 with Property

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;
}
Also used : Property(org.broadleafcommerce.openadmin.dto.Property)

Example 70 with Property

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;
}
Also used : Transformer(org.apache.commons.collections.Transformer) TypedTransformer(org.broadleafcommerce.common.util.TypedTransformer) ArrayList(java.util.ArrayList) CriteriaTransferObject(org.broadleafcommerce.openadmin.dto.CriteriaTransferObject) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

Property (org.broadleafcommerce.openadmin.dto.Property)120 Entity (org.broadleafcommerce.openadmin.dto.Entity)62 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)45 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)38 ArrayList (java.util.ArrayList)28 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)26 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)25 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)21 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 HashMap (java.util.HashMap)18 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 Map (java.util.Map)15 ServiceException (org.broadleafcommerce.common.exception.ServiceException)15 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)12 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)12