All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.fruitful.ecomerce.service.cart.MagentoCartServiceImpl Maven / Gradle / Ivy

There is a newer version: 1.2
Show newest version
package io.fruitful.ecomerce.service.cart;

import io.fruitful.ecomerce.commons.MagentoErrorInfo;
import io.fruitful.ecomerce.commons.MagentoException;

import io.fruitful.ecomerce.dto.*;
import io.fruitful.ecomerce.utils.MagentoInitService;
import io.fruitful.ecomerce.utils.RetrofitService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import retrofit2.Response;

import java.util.List;


@Service
@Log4j2
public class MagentoCartServiceImpl implements MagentoCartService {

    @Autowired
    private MagentoInitService magentoInitSv;

    @Override
    public Boolean magentoRemoveItemsCart(RemoveItemCartRequest request) throws MagentoException {
        Response response = null;
        try {
            response = magentoInitSv.getMagentoCartApi().removeItemsCart(request.getBearerToken(), request.getItemId()).execute();
        } catch (Exception ex) {
            log.error("removeItemsCart error ", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);
    }

    @Override
    public MagentoCartTotalsResponse magentoGetCartTotals(BaseCustomerTokenRequest request) throws MagentoException {
        Response response = null;
        try {
            response = magentoInitSv.getMagentoCartApi().getCartTotals(request.getBearerToken()).execute();
        } catch (Exception ex) {
            log.error("getCartTotals error ", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);
    }

    @Override
    public MagentoCartResponse magentoGetCurrentCart(BaseCustomerTokenRequest request) throws MagentoException {
        Response response = null;
        try {
            response = magentoInitSv.getMagentoCartApi().getCurrentCart(request.getBearerToken()).execute();
        } catch (Exception ex) {
            log.error("getCurrentCart error ", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);
    }

    @Override
    public String createCart(BaseCustomerTokenRequest request) throws MagentoException {
        Response response = null;
        try {
            response = magentoInitSv.getMagentoCartApi().createCart(request.getBearerToken()).execute();
        } catch (Exception ex) {
            log.error("createCart error ", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);
    }

    @Override
    public MagentoAddProductToCartResponse magentoAddProductToCart(MagentoAddProductToCartRequest request) throws MagentoException {
        Response response = null;
        try {
            response = magentoInitSv.getMagentoCartApi().addProductToCart(request.getBearerToken(), request).execute();
        } catch (Exception ex) {
            log.error("addProductToCart error ", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);
    }

    @Override
    public MagentoAddProductToCartResponse magentoUpdateProductCart(MagentoAddProductToCartRequest request) throws MagentoException {
        Response response = null;
        try {
            response = magentoInitSv.getMagentoCartApi().updateProductCart(request.getBearerToken(), request.getCartItem().getItemId(), request).execute();
        } catch (Exception ex) {
            log.error("addProductToCart error ", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);

    }

    @Override
    public List getCountries() throws MagentoException {
        Response> response;
        try {
            response = magentoInitSv.getMagentoCartApi().getCountries().execute();
        } catch (Exception ex) {
            log.error("Get countries error ", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);
    }

    @Override
    public MagentoCountryDetail getCountryDetail(String countryId) throws MagentoException {
        Response response;
        try {
            response = magentoInitSv.getMagentoCartApi().getCountryDetail(countryId).execute();
        } catch (Exception ex) {
            log.error("Get countries error ", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);
    }

    @Override
    public List estimateShippingMethods(MagentoEstimateShippingRequest request) throws MagentoException {
        Response> response;
        try {
            response = magentoInitSv.getMagentoCartApi().estimateShippingMethods(request.getBearerToken(), request).execute();
        } catch (Exception ex) {
            log.error("Estimate shipping methods failed.", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);
    }

    @Override
    public MagentoShippingInfo getShippingInfo(MagentoShippingInfoRequest request) throws MagentoException {
        Response response;
        try {
            response = magentoInitSv.getMagentoCartApi().getShippingInfo(request.getBearerToken(), request).execute();
        } catch (Exception ex) {
            log.error("Get shipping information failed.", ex);
            throw new MagentoException(MagentoErrorInfo.MAGENTO_CUSTOM_ERROR_CODE, ex.getMessage());
        }
        return RetrofitService.getData(response);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy