|
|
|
@ -1,4 +1,4 @@ |
|
|
|
package common.ecommerce.lingxing.platform.shopify.product; |
|
|
|
package common.ecommerce.lingxing.platform.target.product; |
|
|
|
|
|
|
|
|
|
|
|
import common.ecommerce.http.HttpRequest; |
|
|
|
import common.ecommerce.http.HttpRequest; |
|
|
|
import common.ecommerce.http.HttpResponse; |
|
|
|
import common.ecommerce.http.HttpResponse; |
|
|
|
@ -6,7 +6,7 @@ import common.ecommerce.lingxing.LingxingApi; |
|
|
|
import common.ecommerce.lingxing.http.LingxingEnvelope; |
|
|
|
import common.ecommerce.lingxing.http.LingxingEnvelope; |
|
|
|
import common.ecommerce.lingxing.platform.LingxingCall; |
|
|
|
import common.ecommerce.lingxing.platform.LingxingCall; |
|
|
|
import common.ecommerce.lingxing.platform.LingxingProductSource; |
|
|
|
import common.ecommerce.lingxing.platform.LingxingProductSource; |
|
|
|
import common.ecommerce.lingxing.platform.shopify.dto.ShopifyListingDto; |
|
|
|
import common.ecommerce.lingxing.platform.target.dto.TargetListingDto; |
|
|
|
import common.ecommerce.model.ChannelProvider; |
|
|
|
import common.ecommerce.model.ChannelProvider; |
|
|
|
import common.ecommerce.model.product.ProductListing; |
|
|
|
import common.ecommerce.model.product.ProductListing; |
|
|
|
import common.ecommerce.model.product.ProductQuery; |
|
|
|
import common.ecommerce.model.product.ProductQuery; |
|
|
|
@ -27,12 +27,15 @@ import java.util.Locale; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 领星 · Shopify 在线商品(变体维度)。 |
|
|
|
* 领星 · Target 在线商品(变体维度)。 |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>接口 {@code /basicOpen/multiplatform/shopify/variantList}:POST,{@code offset}/{@code length} |
|
|
|
* <p>接口 {@code /basicOpen/multiplatform/shopify/variantList}:POST,{@code offset}/{@code length} |
|
|
|
* (上限 1000),返回 {@code data.list};令牌桶容量 1。</p> |
|
|
|
* (上限 1000),返回 {@code data.list};令牌桶容量 1。</p> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p>{@code store_ids} 是<b>非必填</b>项:文档未标必填,不传时返回该 app 下所有店铺的商品。 |
|
|
|
|
|
|
|
* 这里按账户的 {@code externalStoreId} 过滤,避免把其它店铺的商品混进同一个 omsStoreId。</p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public final class ShopifyProductSource implements LingxingProductSource { |
|
|
|
public final class TargetProductSource implements LingxingProductSource { |
|
|
|
|
|
|
|
|
|
|
|
private static final int MAX_PAGE_SIZE = 1000; |
|
|
|
private static final int MAX_PAGE_SIZE = 1000; |
|
|
|
|
|
|
|
|
|
|
|
@ -46,16 +49,20 @@ public final class ShopifyProductSource implements LingxingProductSource { |
|
|
|
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
|
|
|
Map<String, Object> body = new LinkedHashMap<String, Object>(); |
|
|
|
body.put("offset", offset); |
|
|
|
body.put("offset", offset); |
|
|
|
body.put("length", length); |
|
|
|
body.put("length", length); |
|
|
|
body.put("store_ids", Collections.singletonList(call.ctx().account().externalStoreId())); |
|
|
|
// store_ids 非必填:账户配了才传,由平台侧校验是否必填
|
|
|
|
|
|
|
|
String storeId = call.ctx().account().externalStoreId(); |
|
|
|
|
|
|
|
if (storeId != null && !storeId.trim().isEmpty()) { |
|
|
|
|
|
|
|
body.put("store_ids", Collections.singletonList(storeId)); |
|
|
|
|
|
|
|
} |
|
|
|
applyTimeWindow(body, query); |
|
|
|
applyTimeWindow(body, query); |
|
|
|
|
|
|
|
|
|
|
|
HttpRequest req = call.signed(LingxingApi.LISTING_SHOPIFY, body, "products.pull"); |
|
|
|
HttpRequest req = call.signed(LingxingApi.LISTING_SHOPIFY, body, "products.pull"); |
|
|
|
HttpResponse resp = call.execute(req); |
|
|
|
HttpResponse resp = call.execute(req); |
|
|
|
LingxingEnvelope envelope = call.envelope(resp, "products.pull"); |
|
|
|
LingxingEnvelope envelope = call.envelope(resp, "products.pull"); |
|
|
|
|
|
|
|
|
|
|
|
List<ShopifyListingDto> dtos = call.json().listAt(envelope.body(), "data.list", ShopifyListingDto.class); |
|
|
|
List<TargetListingDto> dtos = call.json().listAt(envelope.body(), "data.list", TargetListingDto.class); |
|
|
|
List<ProductListing> out = new ArrayList<ProductListing>(dtos.size()); |
|
|
|
List<ProductListing> out = new ArrayList<ProductListing>(dtos.size()); |
|
|
|
for (ShopifyListingDto dto : dtos) { |
|
|
|
for (TargetListingDto dto : dtos) { |
|
|
|
out.add(toProductListing(dto, call)); |
|
|
|
out.add(toProductListing(dto, call)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -98,7 +105,7 @@ public final class ShopifyProductSource implements LingxingProductSource { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 领星 Shopify 商品 → 统一模型。 |
|
|
|
* 领星 Target 商品 → 统一模型。 |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>统一字段来源:</p> |
|
|
|
* <p>统一字段来源:</p> |
|
|
|
* <ul> |
|
|
|
* <ul> |
|
|
|
@ -115,7 +122,7 @@ public final class ShopifyProductSource implements LingxingProductSource { |
|
|
|
* <li>attributes ← 其余全部原始字段</li> |
|
|
|
* <li>attributes ← 其余全部原始字段</li> |
|
|
|
* </ul> |
|
|
|
* </ul> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ProductListing toProductListing(ShopifyListingDto dto, LingxingCall call) { |
|
|
|
private ProductListing toProductListing(TargetListingDto dto, LingxingCall call) { |
|
|
|
ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone()); |
|
|
|
ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone()); |
|
|
|
String currency = currencyOf(dto.getCurrencyIcon()); |
|
|
|
String currency = currencyOf(dto.getCurrencyIcon()); |
|
|
|
String image = firstNonBlank(dto.getPictureUrl(), dto.getParentPictureUrl()); |
|
|
|
String image = firstNonBlank(dto.getPictureUrl(), dto.getParentPictureUrl()); |
|
|
|
@ -139,8 +146,8 @@ public final class ShopifyProductSource implements LingxingProductSource { |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** Shopify:1 active / 2 draft / 3 archived / 4 deleted。 */ |
|
|
|
/** Target:1 active / 2 draft / 3 archived / 4 deleted。 */ |
|
|
|
private static ProductStatus statusOf(ShopifyListingDto dto) { |
|
|
|
private static ProductStatus statusOf(TargetListingDto dto) { |
|
|
|
if (dto.getStatus() == null) { |
|
|
|
if (dto.getStatus() == null) { |
|
|
|
String name = dto.getStatusName(); |
|
|
|
String name = dto.getStatusName(); |
|
|
|
if (name != null) { |
|
|
|
if (name != null) { |
|
|
|
@ -170,7 +177,7 @@ public final class ShopifyProductSource implements LingxingProductSource { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static Map<String, Object> attributesOf(ShopifyListingDto dto) { |
|
|
|
private static Map<String, Object> attributesOf(TargetListingDto dto) { |
|
|
|
Map<String, Object> attrs = new LinkedHashMap<String, Object>(); |
|
|
|
Map<String, Object> attrs = new LinkedHashMap<String, Object>(); |
|
|
|
attrs.put("item_id", dto.getItemId()); |
|
|
|
attrs.put("item_id", dto.getItemId()); |
|
|
|
attrs.put("item_url", dto.getItemUrl()); |
|
|
|
attrs.put("item_url", dto.getItemUrl()); |