Search in sources :

Example 36 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class CommonSetupBaseTest method addProductBundle.

public ProductBundle addProductBundle() {
    // Create the product
    Product p = addTestProduct("bundleproduct1", "bundlecat1");
    // Create the sku for the ProductBundle object
    Sku bundleSku = catalogService.createSku();
    bundleSku.setName(p.getName());
    bundleSku.setRetailPrice(new Money(44.99));
    bundleSku.setActiveStartDate(p.getActiveStartDate());
    bundleSku.setActiveEndDate(p.getActiveEndDate());
    bundleSku.setDiscountable(true);
    // Create the ProductBundle and associate the sku
    ProductBundle bundle = (ProductBundle) catalogService.createProduct(ProductType.BUNDLE);
    bundle.setDefaultCategory(p.getDefaultCategory());
    bundle.setDefaultSku(bundleSku);
    bundle = (ProductBundle) catalogService.saveProduct(bundle);
    // Reverse-associate the ProductBundle to the sku (Must be done this way because it's a
    // bidirectional OneToOne relationship
    // bundleSku.setDefaultProduct(bundle);
    // catalogService.saveSku(bundleSku);
    // Wrap the product/sku that is part of the bundle in a SkuBundleItem
    SkuBundleItem skuBundleItem = new SkuBundleItemImpl();
    skuBundleItem.setBundle(bundle);
    skuBundleItem.setQuantity(1);
    skuBundleItem.setSku(p.getDefaultSku());
    // Add the SkuBundleItem to the ProductBundle
    bundle.getSkuBundleItems().add(skuBundleItem);
    bundle = (ProductBundle) catalogService.saveProduct(bundle);
    return bundle;
}
Also used : Money(org.broadleafcommerce.common.money.Money) SkuBundleItem(org.broadleafcommerce.core.catalog.domain.SkuBundleItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) SkuBundleItemImpl(org.broadleafcommerce.core.catalog.domain.SkuBundleItemImpl)

Example 37 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class CommonSetupBaseTest method createCustomerWithBasicOrderAndAddresses.

/**
 * Create a state, country, and customer with a basic order and some addresses
 */
public Customer createCustomerWithBasicOrderAndAddresses() {
    Customer customer = createCustomerWithAddresses();
    Order order = new OrderImpl();
    order.setStatus(OrderStatus.IN_PROCESS);
    order.setTotal(new Money(BigDecimal.valueOf(1000)));
    assert order.getId() == null;
    order.setCustomer(customer);
    order = orderDao.save(order);
    assert order.getId() != null;
    return customer;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) Customer(org.broadleafcommerce.profile.core.domain.Customer) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl)

Example 38 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentItemPricingActivityTest method testDistributeOneDollarAcrossFiveEqualItems.

public void testDistributeOneDollarAcrossFiveEqualItems() throws Exception {
    Order order = dataProvider.createBasicOrder();
    Money subTotal = new Money(order.getCurrency());
    for (OrderItem orderItem : order.getOrderItems()) {
        orderItem.setSalePrice(new Money(10D));
        orderItem.getOrderItemPriceDetails().clear();
        subTotal = subTotal.add(orderItem.getTotalPrice());
    }
    OrderAdjustment adjustment = new OrderAdjustmentImpl();
    adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
    order.getOrderAdjustments().add(adjustment);
    adjustment.setOrder(order);
    order.setSubTotal(subTotal);
    ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
    context.setSeedData(order);
    fulfillmentItemPricingActivity.execute(context);
    // Each item is equally priced, so the adjustment should be .20 per item.
    Money proratedAdjustment = new Money(".20");
    for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
        for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
            assertTrue(fulfillmentGroupItem.getProratedOrderAdjustmentAmount().compareTo(proratedAdjustment.multiply(fulfillmentGroupItem.getQuantity())) == 0);
        }
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) BigDecimal(java.math.BigDecimal)

Example 39 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentItemPricingActivityTest method testBundleDistribution.

public void testBundleDistribution() throws Exception {
    Order order = dataProvider.createOrderWithBundle();
    Money subTotal = new Money(order.getCurrency());
    for (OrderItem orderItem : order.getOrderItems()) {
        subTotal = subTotal.add(orderItem.getTotalPrice());
    }
    order.setSubTotal(subTotal);
    OrderAdjustment adjustment = new OrderAdjustmentImpl();
    adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
    adjustment.setOrder(order);
    order.getOrderAdjustments().add(adjustment);
    ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
    context.setSeedData(order);
    fulfillmentItemPricingActivity.execute(context);
    assertTrue(sumProratedOfferAdjustments(order).equals(new Money(new BigDecimal("1"), order.getCurrency())));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) BigDecimal(java.math.BigDecimal)

Example 40 with Money

use of org.broadleafcommerce.common.money.Money in project BroadleafCommerce by BroadleafCommerce.

the class NullIntegrationGatewayTransactionServiceImpl method refund.

@Override
public PaymentResponseDTO refund(PaymentRequestDTO paymentRequestDTO) throws PaymentException {
    PaymentResponseDTO responseDTO = new PaymentResponseDTO(PaymentType.CREDIT_CARD, NullIntegrationGatewayType.NULL_INTEGRATION_GATEWAY);
    responseDTO.valid(true).paymentTransactionType(PaymentTransactionType.REFUND).amount(new Money(paymentRequestDTO.getTransactionTotal())).rawResponse("Successful Refund").successful(true);
    return responseDTO;
}
Also used : Money(org.broadleafcommerce.common.money.Money) PaymentResponseDTO(org.broadleafcommerce.common.payment.dto.PaymentResponseDTO)

Aggregations

Money (org.broadleafcommerce.common.money.Money)158 Order (org.broadleafcommerce.core.order.domain.Order)43 BigDecimal (java.math.BigDecimal)38 Offer (org.broadleafcommerce.core.offer.domain.Offer)29 Test (org.testng.annotations.Test)29 Transactional (org.springframework.transaction.annotation.Transactional)24 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)22 ArrayList (java.util.ArrayList)21 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)21 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)19 CustomerOffer (org.broadleafcommerce.core.offer.domain.CustomerOffer)18 Sku (org.broadleafcommerce.core.catalog.domain.Sku)16 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)14 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)13 HashMap (java.util.HashMap)12 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)12 FixedPriceFulfillmentOption (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption)12 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)11 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)11 FixedPriceFulfillmentOptionImpl (org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl)10