Search in sources :

Example 1 with ReadableManufacturerPopulator

use of com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator in project shopizer by shopizer-ecommerce.

the class ListItemsController method displayListingPage.

@RequestMapping("/shop/listing/{url}.html")
public String displayListingPage(@PathVariable String url, Model model, HttpServletRequest request, HttpServletResponse response, Locale locale) throws Exception {
    MerchantStore store = (MerchantStore) request.getAttribute(Constants.MERCHANT_STORE);
    Language language = (Language) request.getAttribute("LANGUAGE");
    // Manufacturer manufacturer = manufacturerService.getByUrl(store, language, url); // this needs to be checked
    Manufacturer manufacturer = null;
    if (manufacturer == null) {
        LOGGER.error("No manufacturer found for url " + url);
        // redirect on page not found
        return PageBuilderUtils.build404(store);
    }
    ReadableManufacturer readableManufacturer = new ReadableManufacturer();
    ReadableManufacturerPopulator populator = new ReadableManufacturerPopulator();
    readableManufacturer = populator.populate(manufacturer, readableManufacturer, store, language);
    // meta information
    PageInformation pageInformation = new PageInformation();
    pageInformation.setPageDescription(readableManufacturer.getDescription().getMetaDescription());
    pageInformation.setPageKeywords(readableManufacturer.getDescription().getKeyWords());
    pageInformation.setPageTitle(readableManufacturer.getDescription().getTitle());
    pageInformation.setPageUrl(readableManufacturer.getDescription().getFriendlyUrl());
    model.addAttribute("manufacturer", readableManufacturer);
    /**
     * template *
     */
    StringBuilder template = new StringBuilder().append(ControllerConstants.Tiles.Items.items_manufacturer).append(".").append(store.getStoreTemplate());
    return template.toString();
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Language(com.salesmanager.core.model.reference.language.Language) PageInformation(com.salesmanager.shop.model.shop.PageInformation) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) MerchantStore(com.salesmanager.core.model.merchant.MerchantStore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ReadableManufacturerPopulator

use of com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator in project shopizer by shopizer-ecommerce.

the class ShoppingCategoryController method getManufacturers.

private List<ReadableManufacturer> getManufacturers(MerchantStore store, List<Long> ids, Language language) throws Exception {
    List<ReadableManufacturer> manufacturerList = new ArrayList<ReadableManufacturer>();
    List<com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer> manufacturers = manufacturerService.listByProductsByCategoriesId(store, ids, language);
    if (!manufacturers.isEmpty()) {
        for (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer manufacturer : manufacturers) {
            ReadableManufacturer manuf = new ReadableManufacturerPopulator().populate(manufacturer, new ReadableManufacturer(), store, language);
            manufacturerList.add(manuf);
        }
    }
    return manufacturerList;
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ArrayList(java.util.ArrayList) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)

Example 3 with ReadableManufacturerPopulator

use of com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator in project shopizer by shopizer-ecommerce.

the class ManufacturerFacadeImpl method listByStore.

@Override
public ReadableManufacturerList listByStore(MerchantStore store, Language language, ListCriteria criteria, int page, int count) {
    ReadableManufacturerList readableList = new ReadableManufacturerList();
    try {
        /**
         * Is this a pageable request
         */
        List<Manufacturer> manufacturers = null;
        Page<Manufacturer> m = null;
        if (language != null) {
            m = manufacturerService.listByStore(store, language, criteria.getName(), page, count);
        } else {
            m = manufacturerService.listByStore(store, criteria.getName(), page, count);
        }
        manufacturers = m.getContent();
        readableList.setTotalPages(m.getTotalPages());
        readableList.setRecordsTotal(m.getTotalElements());
        readableList.setNumber(m.getNumber());
        ReadableManufacturerPopulator populator = new ReadableManufacturerPopulator();
        List<ReadableManufacturer> returnList = new ArrayList<ReadableManufacturer>();
        for (Manufacturer mf : manufacturers) {
            ReadableManufacturer readableManufacturer = new ReadableManufacturer();
            populator.populate(mf, readableManufacturer, store, language);
            returnList.add(readableManufacturer);
        }
        readableList.setManufacturers(returnList);
        return readableList;
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while get manufacturers", e);
    }
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) ArrayList(java.util.ArrayList) ReadableManufacturerList(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturerList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 4 with ReadableManufacturerPopulator

use of com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator in project shopizer by shopizer-ecommerce.

the class ManufacturerFacadeImpl method getAllManufacturers.

@Override
public ReadableManufacturerList getAllManufacturers(MerchantStore store, Language language, ListCriteria criteria, int page, int count) {
    ReadableManufacturerList readableList = new ReadableManufacturerList();
    try {
        /**
         * Is this a pageable request
         */
        List<Manufacturer> manufacturers = null;
        if (page == 0 && count == 0) {
            // need total count
            int total = manufacturerService.count(store);
            if (language != null) {
                manufacturers = manufacturerService.listByStore(store, language);
            } else {
                manufacturers = manufacturerService.listByStore(store);
            }
            readableList.setRecordsTotal(total);
            readableList.setNumber(manufacturers.size());
        } else {
            Page<Manufacturer> m = null;
            if (language != null) {
                m = manufacturerService.listByStore(store, language, criteria.getName(), page, count);
            } else {
                m = manufacturerService.listByStore(store, criteria.getName(), page, count);
            }
            manufacturers = m.getContent();
            readableList.setTotalPages(m.getTotalPages());
            readableList.setRecordsTotal(m.getTotalElements());
            readableList.setNumber(m.getNumber());
        }
        ReadableManufacturerPopulator populator = new ReadableManufacturerPopulator();
        List<ReadableManufacturer> returnList = new ArrayList<ReadableManufacturer>();
        for (Manufacturer m : manufacturers) {
            ReadableManufacturer readableManufacturer = new ReadableManufacturer();
            populator.populate(m, readableManufacturer, store, language);
            returnList.add(readableManufacturer);
        }
        readableList.setManufacturers(returnList);
        return readableList;
    } catch (Exception e) {
        throw new ServiceRuntimeException("Error while get manufacturers", e);
    }
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) ArrayList(java.util.ArrayList) ReadableManufacturerList(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturerList) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Example 5 with ReadableManufacturerPopulator

use of com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator in project shopizer by shopizer-ecommerce.

the class ManufacturerFacadeImpl method getManufacturer.

@Override
public ReadableManufacturer getManufacturer(Long id, MerchantStore store, Language language) throws Exception {
    Manufacturer manufacturer = manufacturerService.getById(id);
    if (manufacturer == null) {
        throw new ResourceNotFoundException("Manufacturer [" + id + "] not found");
    }
    if (manufacturer.getMerchantStore().getId() != store.getId()) {
        throw new ResourceNotFoundException("Manufacturer [" + id + "] not found for store [" + store.getId() + "]");
    }
    ReadableManufacturer readableManufacturer = new ReadableManufacturer();
    ReadableManufacturerPopulator populator = new ReadableManufacturerPopulator();
    readableManufacturer = populator.populate(manufacturer, readableManufacturer, store, language);
    return readableManufacturer;
}
Also used : ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) Manufacturer(com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer) PersistableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer) ReadableManufacturer(com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer) ReadableManufacturerPopulator(com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException)

Aggregations

ReadableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturer)5 ReadableManufacturerPopulator (com.salesmanager.shop.populator.manufacturer.ReadableManufacturerPopulator)5 Manufacturer (com.salesmanager.core.model.catalog.product.manufacturer.Manufacturer)4 PersistableManufacturer (com.salesmanager.shop.model.catalog.manufacturer.PersistableManufacturer)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 ArrayList (java.util.ArrayList)3 ServiceException (com.salesmanager.core.business.exception.ServiceException)2 ReadableManufacturerList (com.salesmanager.shop.model.catalog.manufacturer.ReadableManufacturerList)2 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)2 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)2 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 Language (com.salesmanager.core.model.reference.language.Language)1 PageInformation (com.salesmanager.shop.model.shop.PageInformation)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1