use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class ShippingQuoteByWeightTest method testGetCustomShippingQuotesByWeight.
@Ignore
public // @Test
void testGetCustomShippingQuotesByWeight() throws ServiceException {
Language en = languageService.getByCode("en");
Country country = countryService.getByCode("CA");
Zone zone = zoneService.getByCode("QC");
MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
ProductType generalType = productTypeService.getProductType(ProductType.GENERAL_TYPE);
// set valid store postal code
store.setStorepostalcode("J4B-9J9");
Product product = new Product();
product.setProductHeight(new BigDecimal(4));
product.setProductLength(new BigDecimal(3));
product.setProductWidth(new BigDecimal(5));
product.setProductWeight(new BigDecimal(8));
product.setSku("TESTSKU");
product.setType(generalType);
product.setMerchantStore(store);
// Product description
ProductDescription description = new ProductDescription();
description.setName("Product 1");
description.setLanguage(en);
description.setProduct(product);
product.getDescriptions().add(description);
productService.create(product);
// productService.saveOrUpdate(product);
// Availability
ProductAvailability availability = new ProductAvailability();
availability.setProductDateAvailable(new Date());
availability.setProductQuantity(100);
availability.setRegion("*");
// associate with product
availability.setProduct(product);
product.getAvailabilities().add(availability);
productAvailabilityService.create(availability);
ProductPrice dprice = new ProductPrice();
dprice.setDefaultPrice(true);
dprice.setProductPriceAmount(new BigDecimal(29.99));
dprice.setProductAvailability(availability);
ProductPriceDescription dpd = new ProductPriceDescription();
dpd.setName("Base price");
dpd.setProductPrice(dprice);
dpd.setLanguage(en);
dprice.getDescriptions().add(dpd);
availability.getPrices().add(dprice);
productPriceService.create(dprice);
// get product
product = productService.getByCode("TESTSKU", en);
// check the product
Set<ProductAvailability> avails = product.getAvailabilities();
for (ProductAvailability as : avails) {
Set<ProductPrice> availabilityPrices = as.getPrices();
for (ProductPrice ps : availabilityPrices) {
System.out.println(ps.getProductPriceAmount().toString());
}
}
// check availability
Set<ProductPrice> availabilityPrices = availability.getPrices();
for (ProductPrice ps : availabilityPrices) {
System.out.println(ps.getProductPriceAmount().toString());
}
// configure shipping
ShippingConfiguration shippingConfiguration = new ShippingConfiguration();
// based on shipping or billing address
shippingConfiguration.setShippingBasisType(ShippingBasisType.SHIPPING);
shippingConfiguration.setShippingType(ShippingType.INTERNATIONAL);
// individual item pricing or box packaging (see unit test above)
shippingConfiguration.setShippingPackageType(ShippingPackageType.ITEM);
// only if package type is package
shippingConfiguration.setBoxHeight(5);
shippingConfiguration.setBoxLength(5);
shippingConfiguration.setBoxWidth(5);
shippingConfiguration.setBoxWeight(1);
shippingConfiguration.setMaxWeight(10);
List<String> supportedCountries = new ArrayList<String>();
supportedCountries.add("CA");
supportedCountries.add("US");
supportedCountries.add("UK");
supportedCountries.add("FR");
shippingService.setSupportedCountries(store, supportedCountries);
CustomShippingQuotesConfiguration customConfiguration = new CustomShippingQuotesConfiguration();
customConfiguration.setModuleCode("weightBased");
customConfiguration.setActive(true);
CustomShippingQuotesRegion northRegion = new CustomShippingQuotesRegion();
northRegion.setCustomRegionName("NORTH");
List<String> countries = new ArrayList<String>();
countries.add("CA");
countries.add("US");
northRegion.setCountries(countries);
CustomShippingQuoteWeightItem caQuote4 = new CustomShippingQuoteWeightItem();
caQuote4.setMaximumWeight(4);
caQuote4.setPrice(new BigDecimal(20));
CustomShippingQuoteWeightItem caQuote10 = new CustomShippingQuoteWeightItem();
caQuote10.setMaximumWeight(10);
caQuote10.setPrice(new BigDecimal(50));
CustomShippingQuoteWeightItem caQuote100 = new CustomShippingQuoteWeightItem();
caQuote100.setMaximumWeight(100);
caQuote100.setPrice(new BigDecimal(120));
List<CustomShippingQuoteWeightItem> quotes = new ArrayList<CustomShippingQuoteWeightItem>();
quotes.add(caQuote4);
quotes.add(caQuote10);
quotes.add(caQuote100);
northRegion.setQuoteItems(quotes);
customConfiguration.getRegions().add(northRegion);
// create an integration configuration - USPS
IntegrationConfiguration configuration = new IntegrationConfiguration();
configuration.setActive(true);
configuration.setEnvironment(Environment.TEST.name());
configuration.setModuleCode("weightBased");
// configure module
shippingService.saveShippingConfiguration(shippingConfiguration, store);
// create the basic configuration
shippingService.saveShippingQuoteModuleConfiguration(configuration, store);
// and the custom configuration
shippingService.saveCustomShippingConfiguration("weightBased", customConfiguration, store);
// now create ShippingProduct
ShippingProduct shippingProduct1 = new ShippingProduct(product);
FinalPrice price = pricingService.calculateProductPrice(product);
shippingProduct1.setFinalPrice(price);
List<ShippingProduct> shippingProducts = new ArrayList<ShippingProduct>();
shippingProducts.add(shippingProduct1);
Customer customer = new Customer();
customer.setMerchantStore(store);
customer.setEmailAddress("test@test.com");
customer.setGender(CustomerGender.M);
customer.setDefaultLanguage(en);
customer.setAnonymous(true);
customer.setCompany("ifactory");
customer.setDateOfBirth(new Date());
customer.setNick("My nick");
customer.setPassword("123456");
Delivery delivery = new Delivery();
delivery.setAddress("Shipping address");
delivery.setCity("Boucherville");
delivery.setCountry(country);
delivery.setZone(zone);
delivery.setPostalCode("J5C-6J4");
// overwrite delivery to US
/* delivery.setPostalCode("90002");
delivery.setCountry(us);
Zone california = zoneService.getByCode("CA");
delivery.setZone(california);*/
Billing billing = new Billing();
billing.setAddress("Billing address");
billing.setCountry(country);
billing.setZone(zone);
billing.setPostalCode("J4B-8J9");
billing.setFirstName("Carl");
billing.setLastName("Samson");
customer.setBilling(billing);
customer.setDelivery(delivery);
customerService.create(customer);
// for correlation
Long dummyCartId = 0L;
ShippingQuote shippingQuote = shippingService.getShippingQuote(dummyCartId, store, delivery, shippingProducts, en);
Assert.notNull(shippingQuote);
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class CustomerTest method createCustomer.
@Test
public void createCustomer() throws ServiceException {
Language en = languageService.getByCode("en");
MerchantStore store = merchantService.getByCode(MerchantStore.DEFAULT_STORE);
Country country = countryService.getByCode("CA");
Zone zone = zoneService.getByCode("QC");
/**
* Core customer attributes *
*/
Customer customer = new Customer();
customer.setMerchantStore(store);
customer.setEmailAddress("test@test.com");
customer.setGender(CustomerGender.M);
customer.setAnonymous(true);
customer.setCompany("ifactory");
customer.setDateOfBirth(new Date());
customer.setNick("My nick");
customer.setPassword("123456");
customer.setDefaultLanguage(store.getDefaultLanguage());
Delivery delivery = new Delivery();
delivery.setAddress("Shipping address");
delivery.setCountry(country);
delivery.setZone(zone);
Billing billing = new Billing();
billing.setFirstName("John");
billing.setLastName("Bossanova");
billing.setAddress("Billing address");
billing.setCountry(country);
billing.setZone(zone);
customer.setBilling(billing);
customer.setDelivery(delivery);
customerService.create(customer);
customer = customerService.getById(customer.getId());
// create an option value
CustomerOptionValue yes = new CustomerOptionValue();
yes.setCode("yes");
yes.setMerchantStore(store);
CustomerOptionValueDescription yesDescription = new CustomerOptionValueDescription();
yesDescription.setLanguage(en);
yesDescription.setCustomerOptionValue(yes);
CustomerOptionValueDescription yes_sir = new CustomerOptionValueDescription();
yes_sir.setCustomerOptionValue(yes);
yes_sir.setDescription("Yes sir!");
yes_sir.setName("Yes sir!");
yes_sir.setLanguage(en);
yes.getDescriptions().add(yes_sir);
// needs to be saved before using it
customerOptionValueService.create(yes);
CustomerOptionValue no = new CustomerOptionValue();
no.setCode("no");
no.setMerchantStore(store);
CustomerOptionValueDescription noDescription = new CustomerOptionValueDescription();
noDescription.setLanguage(en);
noDescription.setCustomerOptionValue(no);
CustomerOptionValueDescription no_sir = new CustomerOptionValueDescription();
no_sir.setCustomerOptionValue(no);
no_sir.setDescription("Nope!");
no_sir.setName("Nope!");
no_sir.setLanguage(en);
no.getDescriptions().add(no_sir);
// needs to be saved before using it
customerOptionValueService.create(no);
// create a customer option to be used
CustomerOption subscribedToMailingList = new CustomerOption();
subscribedToMailingList.setActive(true);
subscribedToMailingList.setPublicOption(true);
subscribedToMailingList.setCode("subscribedToMailingList");
subscribedToMailingList.setMerchantStore(store);
CustomerOptionDescription mailingListDesciption = new CustomerOptionDescription();
mailingListDesciption.setName("Subscribed to mailing list");
mailingListDesciption.setDescription("Subscribed to mailing list");
mailingListDesciption.setLanguage(en);
mailingListDesciption.setCustomerOption(subscribedToMailingList);
Set<CustomerOptionDescription> mailingListDesciptionList = new HashSet<CustomerOptionDescription>();
mailingListDesciptionList.add(mailingListDesciption);
subscribedToMailingList.setDescriptions(mailingListDesciptionList);
customerOptionService.create(subscribedToMailingList);
// create a customer option to be used
CustomerOption hasReturnedItems = new CustomerOption();
hasReturnedItems.setActive(true);
hasReturnedItems.setPublicOption(true);
hasReturnedItems.setCode("hasReturnedItems");
hasReturnedItems.setMerchantStore(store);
CustomerOptionDescription hasReturnedItemsDesciption = new CustomerOptionDescription();
hasReturnedItemsDesciption.setName("Has returned items");
hasReturnedItemsDesciption.setDescription("Has returned items");
hasReturnedItemsDesciption.setLanguage(en);
hasReturnedItemsDesciption.setCustomerOption(hasReturnedItems);
Set<CustomerOptionDescription> hasReturnedItemsList = new HashSet<CustomerOptionDescription>();
hasReturnedItemsList.add(hasReturnedItemsDesciption);
hasReturnedItems.setDescriptions(hasReturnedItemsList);
customerOptionService.create(hasReturnedItems);
subscribedToMailingList.setSortOrder(3);
customerOptionService.update(subscribedToMailingList);
// --
// now create an option set (association of a customer option with possible customer option values)
// --
// possible yes
CustomerOptionSet mailingListSetYes = new CustomerOptionSet();
mailingListSetYes.setSortOrder(0);
mailingListSetYes.setCustomerOption(subscribedToMailingList);
mailingListSetYes.setCustomerOptionValue(yes);
customerOptionSetService.create(mailingListSetYes);
// possible no
CustomerOptionSet mailingListSetNo = new CustomerOptionSet();
// mailingListSetNo.setPk(mailingListSetNoId);
mailingListSetNo.setSortOrder(1);
mailingListSetNo.setCustomerOption(subscribedToMailingList);
mailingListSetNo.setCustomerOptionValue(no);
customerOptionSetService.create(mailingListSetNo);
// possible has returned items
CustomerOptionSet hasReturnedItemsYes = new CustomerOptionSet();
hasReturnedItemsYes.setSortOrder(0);
hasReturnedItemsYes.setCustomerOption(hasReturnedItems);
hasReturnedItemsYes.setCustomerOptionValue(yes);
customerOptionSetService.create(hasReturnedItemsYes);
subscribedToMailingList.setSortOrder(2);
customerOptionService.update(subscribedToMailingList);
CustomerOption option = customerOptionService.getById(subscribedToMailingList.getId());
option.setSortOrder(4);
customerOptionService.update(option);
List<CustomerOptionSet> optionSetList = customerOptionSetService.listByStore(store, en);
// Assert.assertEquals(3, optionSetList.size());
System.out.println("Size of options : " + optionSetList.size());
/**
* Now create a customer option attribute
* A customer attribute is a selected customer option set transformed to an
* attribute for a given customer
*/
CustomerAttribute customerAttributeMailingList = new CustomerAttribute();
customerAttributeMailingList.setCustomer(customer);
customerAttributeMailingList.setCustomerOption(subscribedToMailingList);
customerAttributeMailingList.setCustomerOptionValue(no);
customer.getAttributes().add(customerAttributeMailingList);
customerService.save(customer);
customerService.delete(customer);
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class AbstractCustomerServices method loadUserByUsername.
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException, DataAccessException {
Customer user = null;
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
try {
LOGGER.debug("Loading user by user id: {}", userName);
user = customerService.getByNick(userName);
if (user == null) {
// return null;
throw new UsernameNotFoundException("User " + userName + " not found");
}
// required to login
GrantedAuthority role = new SimpleGrantedAuthority(ROLE_PREFIX + Constants.PERMISSION_CUSTOMER_AUTHENTICATED);
authorities.add(role);
List<Integer> groupsId = new ArrayList<Integer>();
List<Group> groups = user.getGroups();
for (Group group : groups) {
groupsId.add(group.getId());
}
if (CollectionUtils.isNotEmpty(groupsId)) {
List<Permission> permissions = permissionService.getPermissions(groupsId);
for (Permission permission : permissions) {
GrantedAuthority auth = new SimpleGrantedAuthority(permission.getPermissionName());
authorities.add(auth);
}
}
} catch (ServiceException e) {
LOGGER.error("Exception while querrying customer", e);
throw new SecurityDataAccessException("Cannot authenticate customer", e);
}
return userDetails(userName, user, authorities);
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class PersistableProductReviewPopulator method populate.
@Override
public ProductReview populate(PersistableProductReview source, ProductReview target, MerchantStore store, Language language) throws ConversionException {
Validate.notNull(customerService, "customerService cannot be null");
Validate.notNull(productService, "productService cannot be null");
Validate.notNull(languageService, "languageService cannot be null");
Validate.notNull(source.getRating(), "Rating cannot bot be null");
try {
if (target == null) {
target = new ProductReview();
}
Customer customer = customerService.getById(source.getCustomerId());
// check if customer belongs to store
if (customer == null || customer.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid customer id for the given store");
}
if (source.getDate() == null) {
String date = DateUtil.formatDate(new Date());
source.setDate(date);
}
target.setReviewDate(DateUtil.getDate(source.getDate()));
target.setCustomer(customer);
target.setReviewRating(source.getRating());
Product product = productService.getById(source.getProductId());
// check if product belongs to store
if (product == null || product.getMerchantStore().getId().intValue() != store.getId().intValue()) {
throw new ConversionException("Invalid product id for the given store");
}
target.setProduct(product);
Language lang = languageService.getByCode(language.getCode());
if (lang == null) {
throw new ConversionException("Invalid language code, use iso codes (en, fr ...)");
}
ProductReviewDescription description = new ProductReviewDescription();
description.setDescription(source.getDescription());
description.setLanguage(lang);
description.setName("-");
description.setProductReview(target);
Set<ProductReviewDescription> descriptions = new HashSet<ProductReviewDescription>();
descriptions.add(description);
target.setDescriptions(descriptions);
return target;
} catch (Exception e) {
throw new ConversionException("Cannot populate ProductReview", e);
}
}
use of com.salesmanager.core.model.customer.Customer in project shopizer by shopizer-ecommerce.
the class PersistableOrderApiPopulator method populate.
@Override
public Order populate(PersistableOrder source, Order target, MerchantStore store, Language language) throws ConversionException {
/* Validate.notNull(currencyService,"currencyService must be set");
Validate.notNull(customerService,"customerService must be set");
Validate.notNull(shoppingCartService,"shoppingCartService must be set");
Validate.notNull(productService,"productService must be set");
Validate.notNull(productAttributeService,"productAttributeService must be set");
Validate.notNull(digitalProductService,"digitalProductService must be set");*/
Validate.notNull(source.getPayment(), "Payment cannot be null");
try {
if (target == null) {
target = new Order();
}
// target.setLocale(LocaleUtils.getLocale(store));
target.setLocale(LocaleUtils.getLocale(store));
Currency currency = null;
try {
currency = currencyService.getByCode(source.getCurrency());
} catch (Exception e) {
throw new ConversionException("Currency not found for code " + source.getCurrency());
}
if (currency == null) {
throw new ConversionException("Currency not found for code " + source.getCurrency());
}
// Customer
Customer customer = null;
if (source.getCustomerId() != null && source.getCustomerId().longValue() > 0) {
Long customerId = source.getCustomerId();
customer = customerService.getById(customerId);
if (customer == null) {
throw new ConversionException("Curstomer with id " + source.getCustomerId() + " does not exist");
}
target.setCustomerId(customerId);
} else {
if (source instanceof PersistableAnonymousOrder) {
PersistableCustomer persistableCustomer = ((PersistableAnonymousOrder) source).getCustomer();
customer = new Customer();
customer = customerPopulator.populate(persistableCustomer, customer, store, language);
} else {
throw new ConversionException("Curstomer details or id not set in request");
}
}
target.setCustomerEmailAddress(customer.getEmailAddress());
Delivery delivery = customer.getDelivery();
target.setDelivery(delivery);
Billing billing = customer.getBilling();
target.setBilling(billing);
if (source.getAttributes() != null && source.getAttributes().size() > 0) {
Set<OrderAttribute> attrs = new HashSet<OrderAttribute>();
for (com.salesmanager.shop.model.order.OrderAttribute attribute : source.getAttributes()) {
OrderAttribute attr = new OrderAttribute();
attr.setKey(attribute.getKey());
attr.setValue(attribute.getValue());
attr.setOrder(target);
attrs.add(attr);
}
target.setOrderAttributes(attrs);
}
target.setDatePurchased(new Date());
target.setCurrency(currency);
target.setCurrencyValue(new BigDecimal(0));
target.setMerchant(store);
target.setChannel(OrderChannel.API);
// need this
target.setStatus(OrderStatus.ORDERED);
target.setPaymentModuleCode(source.getPayment().getPaymentModule());
target.setPaymentType(PaymentType.valueOf(source.getPayment().getPaymentType()));
target.setCustomerAgreement(source.isCustomerAgreement());
// force this to true, cannot perform this activity from the API
target.setConfirmedAddress(true);
if (!StringUtils.isBlank(source.getComments())) {
OrderStatusHistory statusHistory = new OrderStatusHistory();
statusHistory.setStatus(null);
statusHistory.setOrder(target);
statusHistory.setComments(source.getComments());
target.getOrderHistory().add(statusHistory);
}
return target;
} catch (Exception e) {
throw new ConversionException(e);
}
}
Aggregations