| 35079 |
vikas |
1 |
package com.spice.profitmandi.shopify.services;
|
|
|
2 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
3 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
4 |
import com.spice.profitmandi.shopify.models.ShopifySyncModel;
|
|
|
5 |
import org.apache.logging.log4j.LogManager;
|
|
|
6 |
import org.apache.logging.log4j.Logger;
|
|
|
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
8 |
import org.springframework.stereotype.Service;
|
|
|
9 |
|
|
|
10 |
import java.util.HashMap;
|
|
|
11 |
import java.util.Map;
|
|
|
12 |
|
|
|
13 |
@Service
|
|
|
14 |
public class FofoShopifyService {
|
|
|
15 |
private static final Logger logger = LogManager.getLogger(FofoShopifyService.class);
|
|
|
16 |
|
|
|
17 |
@Autowired
|
|
|
18 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
19 |
|
|
|
20 |
@Autowired
|
|
|
21 |
private ShopifyGraphQLService shopifyGraphQLService;
|
|
|
22 |
|
|
|
23 |
public FofoStore syncStoreToShopify(ShopifySyncModel req) throws Exception {
|
|
|
24 |
FofoStore store = fofoStoreRepository.selectByRetailerId(req.getFofoStoreId());
|
|
|
25 |
if (store == null) throw new RuntimeException("FofoStore not found: " + req.getFofoStoreId());
|
|
|
26 |
|
|
|
27 |
if (req.isSyncLocation()) {
|
|
|
28 |
Map<String,String> address = new HashMap<>();
|
|
|
29 |
address.put("address1", store.getUserAddress() != null ? store.getUserAddress().getAddressDescription() : "");
|
|
|
30 |
address.put("city", store.getUserAddress().getCity() != null ? store.getUserAddress().getCity() : "");
|
|
|
31 |
address.put("province", store.getUserAddress().getState() != null ? store.getUserAddress().getState() : "");
|
|
|
32 |
address.put("zip", store.getUserAddress().getPinCode() != null ? store.getUserAddress().getPinCode() : "");
|
|
|
33 |
address.put("country", "IN");
|
|
|
34 |
address.put("phone", store.getUserAddress().getPhoneNumber() != null ? store.getUserAddress().getPhoneNumber() : "");
|
|
|
35 |
|
|
|
36 |
String locationGid = shopifyGraphQLService.createLocation(store.getCode(), address);
|
|
|
37 |
String numeric = shopifyGraphQLService.extractIdFromGid(locationGid);
|
| 35308 |
amit |
38 |
//store.setShopifyLocationId(numeric);
|
| 35079 |
vikas |
39 |
}
|
|
|
40 |
|
|
|
41 |
if (req.isSyncCustomer()) {
|
|
|
42 |
String email = store.getCode() + "@franchise.example.com";
|
|
|
43 |
String customerGid = shopifyGraphQLService.createCustomer(email, store.getCode(), store.getCode());
|
|
|
44 |
String numeric = shopifyGraphQLService.extractIdFromGid(customerGid);
|
| 35308 |
amit |
45 |
//store.setShopifyCustomerId(numeric);
|
| 35079 |
vikas |
46 |
}
|
|
|
47 |
|
|
|
48 |
return store;
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
}
|