use of com.salesmanager.shop.model.customer.optin.PersistableCustomerOptin in project shopizer by shopizer-ecommerce.
the class OptinApiIntegrationTest method createCustomerOptinNewsletter.
public void createCustomerOptinNewsletter() throws Exception {
PersistableCustomerOptin customerOptin = new PersistableCustomerOptin();
customerOptin.setEmail("test@test.com");
customerOptin.setFirstName("Jack");
customerOptin.setLastName("John");
final ObjectWriter writer = new ObjectMapper().writer().withDefaultPrettyPrinter();
final String json = writer.writeValueAsString(customerOptin);
System.out.println(json);
final HttpEntity<String> e = new HttpEntity<>(json);
final ResponseEntity<?> resp = testRestTemplate.postForEntity("/api/v1/newsletter", e, PersistableCustomerOptin.class);
if (resp.getStatusCode() != HttpStatus.OK) {
throw new Exception(resp.toString());
} else {
assertTrue(true);
}
}
use of com.salesmanager.shop.model.customer.optin.PersistableCustomerOptin in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method optinCustomer.
@Override
public void optinCustomer(PersistableCustomerOptin optin, MerchantStore store) {
// check if customer optin exists
Optin optinDef = getOptinByCode(store);
CustomerOptin customerOptin = getCustomerOptinByEmailAddress(optin.getEmail(), store, OptinType.NEWSLETTER);
if (customerOptin != null) {
// exists update
customerOptin.setEmail(optin.getEmail());
customerOptin.setFirstName(optin.getFirstName());
customerOptin.setLastName(optin.getLastName());
} else {
customerOptin = new com.salesmanager.core.model.system.optin.CustomerOptin();
customerOptin.setEmail(optin.getEmail());
customerOptin.setFirstName(optin.getFirstName());
customerOptin.setLastName(optin.getLastName());
customerOptin.setOptinDate(new Date());
customerOptin.setOptin(optinDef);
customerOptin.setMerchantStore(store);
}
saveCustomerOption(customerOptin);
}
Aggregations