Rev 35367 | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.shopify.services;import com.spice.profitmandi.dao.entity.fofo.FofoStore;import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;import com.spice.profitmandi.dao.service.shopify.ShopifyGraphQLService;import com.spice.profitmandi.shopify.models.ShopifySyncModel;import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import java.util.HashMap;import java.util.Map;@Servicepublic class FofoShopifyService {private static final Logger logger = LogManager.getLogger(FofoShopifyService.class);@Autowiredprivate FofoStoreRepository fofoStoreRepository;@Autowiredprivate ShopifyGraphQLService shopifyGraphQLService;public FofoStore syncStoreToShopify(ShopifySyncModel req) throws Exception {FofoStore store = fofoStoreRepository.selectByRetailerId(req.getFofoStoreId());if (store == null) throw new RuntimeException("FofoStore not found: " + req.getFofoStoreId());if (req.isSyncLocation()) {Map<String,String> address = new HashMap<>();address.put("address1", store.getUserAddress() != null ? store.getUserAddress().getAddressDescription() : "");address.put("city", store.getUserAddress().getCity() != null ? store.getUserAddress().getCity() : "");address.put("province", store.getUserAddress().getState() != null ? store.getUserAddress().getState() : "");address.put("zip", store.getUserAddress().getPinCode() != null ? store.getUserAddress().getPinCode() : "");address.put("country", "IN");address.put("phone", store.getUserAddress().getPhoneNumber() != null ? store.getUserAddress().getPhoneNumber() : "");String locationGid = shopifyGraphQLService.createLocation(store.getCode(), address);String numeric = shopifyGraphQLService.extractIdFromGid(locationGid);//store.setShopifyLocationId(numeric);}if (req.isSyncCustomer()) {String email = store.getCode() + "@franchise.example.com";String customerGid = shopifyGraphQLService.createCustomer(email, store.getCode(), store.getCode());String numeric = shopifyGraphQLService.extractIdFromGid(customerGid);//store.setShopifyCustomerId(numeric);}return store;}}