Search in sources :

Example 6 with State

use of org.broadleafcommerce.profile.core.domain.State in project BroadleafCommerce by BroadleafCommerce.

the class InitBinderServiceImpl method configAddressInitBinder.

@Override
public void configAddressInitBinder(ServletRequestDataBinder binder) {
    /**
     * @deprecated - address.setState() is deprecated in favor of ISO standardization
     * This is here for legacy compatibility
     */
    binder.registerCustomEditor(State.class, "address.state", new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) {
            if (StringUtils.isNotEmpty(text)) {
                State state = stateService.findStateByAbbreviation(text);
                setValue(state);
            } else {
                setValue(null);
            }
        }
    });
    /**
     * @deprecated - address.setCountry() is deprecated in favor of ISO standardization
     * This is here for legacy compatibility
     */
    binder.registerCustomEditor(Country.class, "address.country", new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) {
            if (StringUtils.isNotEmpty(text)) {
                Country country = countryService.findCountryByAbbreviation(text);
                setValue(country);
            } else {
                setValue(null);
            }
        }
    });
    binder.registerCustomEditor(ISOCountry.class, "address.isoCountryAlpha2", new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) {
            if (StringUtils.isNotEmpty(text)) {
                ISOCountry isoCountry = isoService.findISOCountryByAlpha2Code(text);
                setValue(isoCountry);
            } else {
                setValue(null);
            }
        }
    });
    binder.registerCustomEditor(Phone.class, "address.phonePrimary", new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) {
            Phone phone = new PhoneImpl();
            phone.setPhoneNumber(text);
            setValue(phone);
        }
    });
    binder.registerCustomEditor(Phone.class, "address.phoneSecondary", new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) {
            Phone phone = new PhoneImpl();
            phone.setPhoneNumber(text);
            setValue(phone);
        }
    });
    binder.registerCustomEditor(Phone.class, "address.phoneFax", new PropertyEditorSupport() {

        @Override
        public void setAsText(String text) {
            Phone phone = new PhoneImpl();
            phone.setPhoneNumber(text);
            setValue(phone);
        }
    });
}
Also used : State(org.broadleafcommerce.profile.core.domain.State) Phone(org.broadleafcommerce.profile.core.domain.Phone) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) PhoneImpl(org.broadleafcommerce.profile.core.domain.PhoneImpl) PropertyEditorSupport(java.beans.PropertyEditorSupport) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry)

Example 7 with State

use of org.broadleafcommerce.profile.core.domain.State in project BroadleafCommerce by BroadleafCommerce.

the class PricingTest method testPricing.

@Test(groups = { "testPricing" }, dependsOnGroups = { "testShippingInsert", "createCustomerIdGeneration" })
@Transactional
public void testPricing() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    customerService.saveCustomer(order.getCustomer());
    Country country = new CountryImpl();
    country.setAbbreviation("US");
    country.setName("United States");
    country = countryService.save(country);
    ISOCountry isoCountry = new ISOCountryImpl();
    isoCountry.setAlpha2("US");
    isoCountry.setName("UNITED STATES");
    isoCountry = isoService.save(isoCountry);
    State state = new StateImpl();
    state.setAbbreviation("TX");
    state.setName("Texas");
    state.setCountry(country);
    state = stateService.save(state);
    Address address = new AddressImpl();
    address.setAddressLine1("123 Test Rd");
    address.setCity("Dallas");
    address.setFirstName("Jeff");
    address.setLastName("Fischer");
    address.setPostalCode("75240");
    address.setPrimaryPhone("972-978-9067");
    address.setState(state);
    address.setCountry(country);
    address.setIsoCountrySubdivision("US-TX");
    address.setIsoCountryAlpha2(isoCountry);
    FulfillmentGroup group = new FulfillmentGroupImpl();
    group.setAddress(address);
    List<FulfillmentGroup> groups = new ArrayList<>();
    group.setMethod("standard");
    group.setService(ShippingServiceType.BANDED_SHIPPING.getType());
    group.setOrder(order);
    groups.add(group);
    order.setFulfillmentGroups(groups);
    Money total = new Money(8.5D);
    group.setShippingPrice(total);
    {
        DiscreteOrderItem item = new DiscreteOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test Sku");
        sku.setRetailPrice(new Money(10D));
        sku.setDiscountable(true);
        SkuFee fee = new SkuFeeImpl();
        fee.setFeeType(SkuFeeType.FULFILLMENT);
        fee.setName("fee test");
        fee.setAmount(new Money(10D));
        fee = catalogService.saveSkuFee(fee);
        List<SkuFee> fees = new ArrayList<>();
        fees.add(fee);
        sku.setFees(fees);
        sku = catalogService.saveSku(sku);
        item.setSku(sku);
        item.setQuantity(2);
        item.setOrder(order);
        item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
        order.addOrderItem(item);
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item);
        fgItem.setQuantity(2);
        // fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
    }
    {
        DiscreteOrderItem item = new DiscreteOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test Product 2");
        sku.setRetailPrice(new Money(20D));
        sku.setDiscountable(true);
        sku = catalogService.saveSku(sku);
        item.setSku(sku);
        item.setQuantity(1);
        item.setOrder(order);
        item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
        order.addOrderItem(item);
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item);
        fgItem.setQuantity(1);
        // fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
    }
    order.addOfferCode(createOfferCode("20 Percent Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.PERCENT_OFF, 20, null, "discreteOrderItem.sku.name==\"Test Sku\""));
    order.addOfferCode(createOfferCode("3 Dollars Off Item Offer", OfferType.ORDER_ITEM, OfferDiscountType.AMOUNT_OFF, 3, null, "discreteOrderItem.sku.name!=\"Test Sku\""));
    order.addOfferCode(createOfferCode("1.20 Dollars Off Order Offer", OfferType.ORDER, OfferDiscountType.AMOUNT_OFF, 1.20, null, null));
    order.setTotalShipping(new Money(0D));
    orderService.save(order, true);
    assert order.getSubTotal().subtract(order.getOrderAdjustmentsValue()).equals(new Money(31.80D));
    assert (order.getTotal().greaterThan(order.getSubTotal()));
    // Shipping is not taxable
    assert (order.getTotalTax().equals(order.getSubTotal().subtract(order.getOrderAdjustmentsValue()).multiply(0.05D)));
    // determine the total cost of the fulfillment group fees
    Money fulfillmentGroupFeeTotal = getFulfillmentGroupFeeTotal(order);
    assert (order.getTotal().equals(order.getSubTotal().add(order.getTotalTax()).add(order.getTotalShipping()).add(fulfillmentGroupFeeTotal).subtract(order.getOrderAdjustmentsValue())));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Address(org.broadleafcommerce.profile.core.domain.Address) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) ArrayList(java.util.ArrayList) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) SkuFee(org.broadleafcommerce.core.catalog.domain.SkuFee) State(org.broadleafcommerce.profile.core.domain.State) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) SkuFeeImpl(org.broadleafcommerce.core.catalog.domain.SkuFeeImpl) List(java.util.List) ArrayList(java.util.ArrayList) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with State

use of org.broadleafcommerce.profile.core.domain.State in project BroadleafCommerce by BroadleafCommerce.

the class PricingTest method testShipping.

@Test(groups = { "testShipping" }, dependsOnGroups = { "testShippingInsert", "createCustomerIdGeneration" })
@Transactional
public void testShipping() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    customerService.saveCustomer(order.getCustomer());
    FulfillmentGroup group1 = new FulfillmentGroupImpl();
    FulfillmentGroup group2 = new FulfillmentGroupImpl();
    // setup group1 - standard
    group1.setMethod("standard");
    group1.setService(ShippingServiceType.BANDED_SHIPPING.getType());
    Country country = new CountryImpl();
    country.setAbbreviation("US");
    country.setName("United States");
    country = countryService.save(country);
    ISOCountry isoCountry = new ISOCountryImpl();
    isoCountry.setAlpha2("US");
    isoCountry.setName("UNITED STATES");
    isoCountry = isoService.save(isoCountry);
    State state = new StateImpl();
    state.setAbbreviation("TX");
    state.setName("Texas");
    state.setCountry(country);
    state = stateService.save(state);
    Address address = new AddressImpl();
    address.setAddressLine1("123 Test Rd");
    address.setCity("Dallas");
    address.setFirstName("Jeff");
    address.setLastName("Fischer");
    address.setPostalCode("75240");
    address.setPrimaryPhone("972-978-9067");
    address.setState(state);
    address.setCountry(country);
    address.setIsoCountrySubdivision("US-TX");
    address.setIsoCountryAlpha2(isoCountry);
    group1.setAddress(address);
    group1.setOrder(order);
    // setup group2 - truck
    group2.setMethod("truck");
    group2.setService(ShippingServiceType.BANDED_SHIPPING.getType());
    group2.setOrder(order);
    List<FulfillmentGroup> groups = new ArrayList<>();
    groups.add(group1);
    // groups.add(group2);
    order.setFulfillmentGroups(groups);
    Money total = new Money(8.5D);
    group1.setShippingPrice(total);
    group2.setShippingPrice(total);
    // group1.setTotalTax(new Money(1D));
    // group2.setTotalTax(new Money(1D));
    order.setSubTotal(total);
    order.setTotal(total);
    DiscreteOrderItem item = new DiscreteOrderItemImpl();
    Sku sku = new SkuImpl();
    sku.setRetailPrice(new Money(15D));
    sku.setDiscountable(true);
    sku.setName("Test Sku");
    sku = catalogService.saveSku(sku);
    item.setSku(sku);
    item.setQuantity(1);
    item.setOrder(order);
    item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
    List<OrderItem> items = new ArrayList<>();
    items.add(item);
    order.setOrderItems(items);
    for (OrderItem orderItem : items) {
        FulfillmentGroupItem fgi = new FulfillmentGroupItemImpl();
        fgi.setOrderItem(orderItem);
        fgi.setQuantity(orderItem.getQuantity());
        fgi.setFulfillmentGroup(group1);
        // fgi.setRetailPrice(new Money(15D));
        group1.addFulfillmentGroupItem(fgi);
    }
    order.setTotalShipping(new Money(0D));
    orderService.save(order, true);
    assert (order.getTotal().greaterThan(order.getSubTotal()));
    // Shipping price is not taxable
    assert (order.getTotalTax().equals(order.getSubTotal().multiply(0.05D)));
    assert (order.getTotal().equals(order.getSubTotal().add(order.getTotalTax().add(order.getTotalShipping()))));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Address(org.broadleafcommerce.profile.core.domain.Address) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) ArrayList(java.util.ArrayList) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) State(org.broadleafcommerce.profile.core.domain.State) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with State

use of org.broadleafcommerce.profile.core.domain.State in project BroadleafCommerce by BroadleafCommerce.

the class AddressDataProvider method createAddress.

@DataProvider(name = "setupAddress")
public static Object[][] createAddress() {
    Address address1 = new AddressImpl();
    address1.setAddressLine1("1234 Merit Drive");
    address1.setCity("Dallas");
    State state = new StateImpl();
    state.setAbbreviation("TX");
    address1.setState(state);
    address1.setPostalCode("75251");
    Address address2 = new AddressImpl();
    address2.setAddressLine1("12 Testing Drive");
    address2.setCity("San Jose");
    state = new StateImpl();
    state.setAbbreviation("CA");
    address2.setState(state);
    address2.setPostalCode("75251");
    return new Object[][] { new Object[] { address1 }, new Object[] { address2 } };
}
Also used : Address(org.broadleafcommerce.profile.core.domain.Address) State(org.broadleafcommerce.profile.core.domain.State) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) DataProvider(org.testng.annotations.DataProvider)

Example 10 with State

use of org.broadleafcommerce.profile.core.domain.State in project BroadleafCommerce by BroadleafCommerce.

the class CustomerAddressTest method createCustomerAddress.

/**
 * This method only exists because so many other tests depend on it, but should be removed once tests are more isolated
 * @param customerAddress
 */
@Deprecated
@Test(groups = "createCustomerAddress", dataProvider = "setupCustomerAddress", dataProviderClass = CustomerAddressDataProvider.class, dependsOnGroups = { "readCustomer", "createCountry", "createState" })
@Transactional
@Rollback(false)
public void createCustomerAddress(CustomerAddress customerAddress) {
    userName = "customer1";
    Customer customer = customerService.readCustomerByUsername(userName);
    assert customerAddress.getId() == null;
    customerAddress.setCustomer(customer);
    State state = stateService.findStateByAbbreviation("KY");
    customerAddress.getAddress().setState(state);
    Country country = countryService.findCountryByAbbreviation("US");
    customerAddress.getAddress().setCountry(country);
    customerAddress.getAddress().setIsoCountrySubdivision("US-KY");
    ISOCountry isoCountry = isoService.findISOCountryByAlpha2Code("US");
    customerAddress.getAddress().setIsoCountryAlpha2(isoCountry);
    customerAddress = customerAddressService.saveCustomerAddress(customerAddress);
    assert customer.equals(customerAddress.getCustomer());
    userId = customerAddress.getCustomer().getId();
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) State(org.broadleafcommerce.profile.core.domain.State) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

State (org.broadleafcommerce.profile.core.domain.State)12 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)10 Country (org.broadleafcommerce.profile.core.domain.Country)10 StateImpl (org.broadleafcommerce.profile.core.domain.StateImpl)8 Address (org.broadleafcommerce.profile.core.domain.Address)7 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)7 ISOCountryImpl (org.broadleafcommerce.common.i18n.domain.ISOCountryImpl)6 CountryImpl (org.broadleafcommerce.profile.core.domain.CountryImpl)6 Money (org.broadleafcommerce.common.money.Money)5 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)5 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)5 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)5 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)5 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)5 Sku (org.broadleafcommerce.core.catalog.domain.Sku)4 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)4 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)4 Order (org.broadleafcommerce.core.order.domain.Order)4 Phone (org.broadleafcommerce.profile.core.domain.Phone)4 ArrayList (java.util.ArrayList)3