Search in sources :

Example 1 with PersistableCustomerOptin

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);
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PersistableCustomerOptin(com.salesmanager.shop.model.customer.optin.PersistableCustomerOptin)

Example 2 with PersistableCustomerOptin

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);
}
Also used : Optin(com.salesmanager.core.model.system.optin.Optin) CustomerOptin(com.salesmanager.core.model.system.optin.CustomerOptin) PersistableCustomerOptin(com.salesmanager.shop.model.customer.optin.PersistableCustomerOptin) CustomerOptin(com.salesmanager.core.model.system.optin.CustomerOptin) CustomerOptin(com.salesmanager.core.model.system.optin.CustomerOptin) PersistableCustomerOptin(com.salesmanager.shop.model.customer.optin.PersistableCustomerOptin) Date(java.util.Date)

Aggregations

PersistableCustomerOptin (com.salesmanager.shop.model.customer.optin.PersistableCustomerOptin)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 CustomerOptin (com.salesmanager.core.model.system.optin.CustomerOptin)1 Optin (com.salesmanager.core.model.system.optin.Optin)1 Date (java.util.Date)1 HttpEntity (org.springframework.http.HttpEntity)1