Search in sources :

Example 6 with ReadableMerchantStore

use of com.salesmanager.shop.model.store.ReadableMerchantStore in project shopizer by shopizer-ecommerce.

the class StoreFacadeImpl method findAll.

@Override
public ReadableMerchantStoreList findAll(MerchantStoreCriteria criteria, Language language, int page, int count) {
    try {
        Page<MerchantStore> stores = null;
        List<ReadableMerchantStore> readableStores = new ArrayList<ReadableMerchantStore>();
        ReadableMerchantStoreList readableList = new ReadableMerchantStoreList();
        Optional<String> code = Optional.ofNullable(criteria.getStoreCode());
        Optional<String> name = Optional.ofNullable(criteria.getName());
        if (code.isPresent()) {
            stores = merchantStoreService.listByGroup(name, code.get(), page, count);
        } else {
            if (criteria.isRetailers()) {
                stores = merchantStoreService.listAllRetailers(name, page, count);
            } else {
                stores = merchantStoreService.listAll(name, page, count);
            }
        }
        if (!CollectionUtils.isEmpty(stores.getContent())) {
            for (MerchantStore store : stores) readableStores.add(convertMerchantStoreToReadableMerchantStore(language, store));
        }
        readableList.setData(readableStores);
        readableList.setRecordsTotal(stores.getTotalElements());
        readableList.setTotalPages(stores.getTotalPages());
        readableList.setNumber(stores.getSize());
        readableList.setRecordsFiltered(stores.getSize());
        return readableList;
    } catch (ServiceException e) {
        throw new ServiceRuntimeException("Error while finding all merchant", e);
    }
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ReadableMerchantStoreList(com.salesmanager.shop.model.store.ReadableMerchantStoreList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ArrayList(java.util.ArrayList) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) PersistableMerchantStore(com.salesmanager.shop.model.store.PersistableMerchantStore) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 7 with ReadableMerchantStore

use of com.salesmanager.shop.model.store.ReadableMerchantStore in project shopizer by shopizer-ecommerce.

the class ReadableCatalogMapper method merge.

@Override
public ReadableCatalog merge(Catalog source, ReadableCatalog destination, MerchantStore store, Language language) {
    if (destination == null) {
        destination = new ReadableCatalog();
    }
    if (isPositive(source.getId())) {
        destination.setId(source.getId());
    }
    destination.setCode(source.getCode());
    destination.setDefaultCatalog(source.isDefaultCatalog());
    destination.setVisible(source.isVisible());
    Optional<ReadableMerchantStore> readableStore = Optional.ofNullable(source.getMerchantStore()).map(MerchantStore::getCode).map(code -> storeFacade.getByCode(code, language));
    readableStore.ifPresent(destination::setStore);
    destination.setDefaultCatalog(source.isDefaultCatalog());
    Optional<String> formattedCreationDate = Optional.ofNullable(source.getAuditSection()).map(AuditSection::getDateCreated).map(DateUtil::formatDate);
    formattedCreationDate.ifPresent(destination::setCreationDate);
    if (CollectionUtils.isNotEmpty(source.getEntry())) {
        // hierarchy temp object
        Map<Long, ReadableCategory> hierarchy = new HashMap<Long, ReadableCategory>();
        source.getEntry().forEach(entry -> {
            processCategory(entry.getCategory(), store, language, hierarchy, new HashMap<>());
        });
        destination.setCategory(new ArrayList<>(hierarchy.values()));
    }
    return destination;
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) HashMap(java.util.HashMap) DateUtil(com.salesmanager.shop.utils.DateUtil) ReadableCatalog(com.salesmanager.shop.model.catalog.catalog.ReadableCatalog) ReadableCategory(com.salesmanager.shop.model.catalog.category.ReadableCategory)

Example 8 with ReadableMerchantStore

use of com.salesmanager.shop.model.store.ReadableMerchantStore in project shopizer by shopizer-ecommerce.

the class MerchantStoreApiIntegrationTest method testGetDefaultStore.

/**
 * Test get DEFAULT store
 * @throws Exception
 */
@Test
public void testGetDefaultStore() throws Exception {
    final HttpEntity<String> httpEntity = new HttpEntity<>(getHeader());
    final ResponseEntity<ReadableMerchantStore> response = testRestTemplate.exchange(String.format("/api/v1/store/" + MerchantStore.DEFAULT_STORE), HttpMethod.GET, httpEntity, ReadableMerchantStore.class);
    if (response.getStatusCode() != HttpStatus.OK) {
        throw new Exception(response.toString());
    } else {
        final ReadableMerchantStore store = response.getBody();
        assertNotNull(store);
    }
}
Also used : HttpEntity(org.springframework.http.HttpEntity) ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with ReadableMerchantStore

use of com.salesmanager.shop.model.store.ReadableMerchantStore in project shopizer by shopizer-ecommerce.

the class ReadableOrderPopulator method populate.

@Override
public ReadableOrder populate(Order source, ReadableOrder target, MerchantStore store, Language language) throws ConversionException {
    target.setId(source.getId());
    target.setDatePurchased(source.getDatePurchased());
    target.setOrderStatus(source.getStatus());
    target.setCurrency(source.getCurrency().getCode());
    // target.setCurrencyModel(source.getCurrency());
    target.setPaymentType(source.getPaymentType());
    target.setPaymentModule(source.getPaymentModuleCode());
    target.setShippingModule(source.getShippingModuleCode());
    if (source.getMerchant() != null) {
        /*			ReadableMerchantStorePopulator merchantPopulator = new ReadableMerchantStorePopulator();
			merchantPopulator.setCountryService(countryService);
			merchantPopulator.setFilePath(filePath);
			merchantPopulator.setZoneService(zoneService);*/
        ReadableMerchantStore readableStore = readableMerchantStorePopulator.populate(source.getMerchant(), null, store, source.getMerchant().getDefaultLanguage());
        target.setStore(readableStore);
    }
    if (source.getCustomerAgreement() != null) {
        target.setCustomerAgreed(source.getCustomerAgreement());
    }
    if (source.getConfirmedAddress() != null) {
        target.setConfirmedAddress(source.getConfirmedAddress());
    }
    com.salesmanager.shop.model.order.total.OrderTotal taxTotal = null;
    com.salesmanager.shop.model.order.total.OrderTotal shippingTotal = null;
    if (source.getBilling() != null) {
        ReadableBilling address = new ReadableBilling();
        address.setEmail(source.getCustomerEmailAddress());
        address.setCity(source.getBilling().getCity());
        address.setAddress(source.getBilling().getAddress());
        address.setCompany(source.getBilling().getCompany());
        address.setFirstName(source.getBilling().getFirstName());
        address.setLastName(source.getBilling().getLastName());
        address.setPostalCode(source.getBilling().getPostalCode());
        address.setPhone(source.getBilling().getTelephone());
        if (source.getBilling().getCountry() != null) {
            address.setCountry(source.getBilling().getCountry().getIsoCode());
        }
        if (source.getBilling().getZone() != null) {
            address.setZone(source.getBilling().getZone().getCode());
        }
        target.setBilling(address);
    }
    if (source.getOrderAttributes() != null && source.getOrderAttributes().size() > 0) {
        for (OrderAttribute attr : source.getOrderAttributes()) {
            com.salesmanager.shop.model.order.OrderAttribute a = new com.salesmanager.shop.model.order.OrderAttribute();
            a.setKey(attr.getKey());
            a.setValue(attr.getValue());
            target.getAttributes().add(a);
        }
    }
    if (source.getDelivery() != null) {
        ReadableDelivery address = new ReadableDelivery();
        address.setCity(source.getDelivery().getCity());
        address.setAddress(source.getDelivery().getAddress());
        address.setCompany(source.getDelivery().getCompany());
        address.setFirstName(source.getDelivery().getFirstName());
        address.setLastName(source.getDelivery().getLastName());
        address.setPostalCode(source.getDelivery().getPostalCode());
        address.setPhone(source.getDelivery().getTelephone());
        if (source.getDelivery().getCountry() != null) {
            address.setCountry(source.getDelivery().getCountry().getIsoCode());
        }
        if (source.getDelivery().getZone() != null) {
            address.setZone(source.getDelivery().getZone().getCode());
        }
        target.setDelivery(address);
    }
    List<com.salesmanager.shop.model.order.total.OrderTotal> totals = new ArrayList<com.salesmanager.shop.model.order.total.OrderTotal>();
    for (OrderTotal t : source.getOrderTotal()) {
        if (t.getOrderTotalType() == null) {
            continue;
        }
        if (t.getOrderTotalType().name().equals(OrderTotalType.TOTAL.name())) {
            com.salesmanager.shop.model.order.total.OrderTotal totalTotal = createTotal(t);
            target.setTotal(totalTotal);
            totals.add(totalTotal);
        } else if (t.getOrderTotalType().name().equals(OrderTotalType.TAX.name())) {
            com.salesmanager.shop.model.order.total.OrderTotal totalTotal = createTotal(t);
            if (taxTotal == null) {
                taxTotal = totalTotal;
            } else {
                BigDecimal v = taxTotal.getValue();
                v = v.add(totalTotal.getValue());
                taxTotal.setValue(v);
            }
            target.setTax(totalTotal);
            totals.add(totalTotal);
        } else if (t.getOrderTotalType().name().equals(OrderTotalType.SHIPPING.name())) {
            com.salesmanager.shop.model.order.total.OrderTotal totalTotal = createTotal(t);
            if (shippingTotal == null) {
                shippingTotal = totalTotal;
            } else {
                BigDecimal v = shippingTotal.getValue();
                v = v.add(totalTotal.getValue());
                shippingTotal.setValue(v);
            }
            target.setShipping(totalTotal);
            totals.add(totalTotal);
        } else if (t.getOrderTotalType().name().equals(OrderTotalType.HANDLING.name())) {
            com.salesmanager.shop.model.order.total.OrderTotal totalTotal = createTotal(t);
            if (shippingTotal == null) {
                shippingTotal = totalTotal;
            } else {
                BigDecimal v = shippingTotal.getValue();
                v = v.add(totalTotal.getValue());
                shippingTotal.setValue(v);
            }
            target.setShipping(totalTotal);
            totals.add(totalTotal);
        } else if (t.getOrderTotalType().name().equals(OrderTotalType.SUBTOTAL.name())) {
            com.salesmanager.shop.model.order.total.OrderTotal subTotal = createTotal(t);
            totals.add(subTotal);
        } else {
            com.salesmanager.shop.model.order.total.OrderTotal otherTotal = createTotal(t);
            totals.add(otherTotal);
        }
    }
    target.setTotals(totals);
    return target;
}
Also used : ReadableMerchantStore(com.salesmanager.shop.model.store.ReadableMerchantStore) ArrayList(java.util.ArrayList) ReadableDelivery(com.salesmanager.shop.model.customer.ReadableDelivery) BigDecimal(java.math.BigDecimal) ReadableBilling(com.salesmanager.shop.model.customer.ReadableBilling) OrderAttribute(com.salesmanager.core.model.order.attributes.OrderAttribute) OrderTotal(com.salesmanager.core.model.order.OrderTotal)

Aggregations

ReadableMerchantStore (com.salesmanager.shop.model.store.ReadableMerchantStore)9 ServiceException (com.salesmanager.core.business.exception.ServiceException)5 ArrayList (java.util.ArrayList)5 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)4 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)3 PersistableMerchantStore (com.salesmanager.shop.model.store.PersistableMerchantStore)3 ReadableMerchantStoreList (com.salesmanager.shop.model.store.ReadableMerchantStoreList)3 Language (com.salesmanager.core.model.reference.language.Language)2 ReadableImage (com.salesmanager.shop.model.content.ReadableImage)2 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)2 ConversionException (com.salesmanager.core.business.exception.ConversionException)1 ContentService (com.salesmanager.core.business.services.content.ContentService)1 MerchantStoreService (com.salesmanager.core.business.services.merchant.MerchantStoreService)1 CountryService (com.salesmanager.core.business.services.reference.country.CountryService)1 LanguageService (com.salesmanager.core.business.services.reference.language.LanguageService)1 ZoneService (com.salesmanager.core.business.services.reference.zone.ZoneService)1 MerchantConfigurationService (com.salesmanager.core.business.services.system.MerchantConfigurationService)1 MeasureUnit (com.salesmanager.core.constants.MeasureUnit)1 GenericEntityList (com.salesmanager.core.model.common.GenericEntityList)1 InputContentFile (com.salesmanager.core.model.content.InputContentFile)1