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