产品图片的 Moltin URL

Moltin URLs for Product Images

Swift 4.0 | iOS11

我需要来自 Moltin Products 请求的图像 URLs。

我有以下功能:

private func loadProducts() {
    let query = MoltinQuery(offset: nil, limit: 20, sort: nil, filter: nil, include: [.products, .files])
    Moltin.product.list(withQuery: query) { (result) in
        switch result {
        case .failure(let error):
            print("Failed to get products:\n\(error)")
        case .success(let productList):
            print("Got products \(productList.products)")
            DispatchQueue.main.async {
                self.productsCollectionView.reloadData()
            }
        }
    }
}

这是吐槽:

Got products [Moltin.Product(id: "fad1eb64-2248-4798-938b-60cbffd8bf95", name: "Hat", slug: "hat", sku: "sku", description: "Some hat", commodityType: Moltin.Product.CommodityType.physical, dimensions: nil, weight: nil, files: [], collections: [], categories: [], brands: [], json: ["commodity_type": physical, "name": Hat, "sku": sku, "manage_stock": 1, "id": fad1eb64-2248-4798-938b-60cbffd8bf95, "slug": hat, "meta": {
stock =     {
    availability = "in-stock";
    level = 5;
};
timestamps =     {
    "created_at" = "2018-02-21T18:57:15+00:00";
    "updated_at" = "2018-02-24T06:36:40+00:00";
};
}, "status": live, "description": Some hat, "type": product, "price": <__NSSingleObjectArrayI 0x604000007f80>(
{
amount = 3499;
currency = USD;
"includes_tax" = 1;
}
)
, "relationships": {
"main_image" =     {
    data =         {
        id = "e016d89b-13e3-40e4-a247-24c1d00a1411";
        type = "main_image";
    };
};
}], prices: [Moltin.Price(amount: 3499, currency: "USD", includesTax: true, json: ["includes_tax": 1, "currency": USD, "amount": 3499])], displayPriceWithTax: nil, displayPriceWithoutTax: nil)]

有没有人成功地为 main_image 拉取 URL?...它只提供图像 ID 和类型。

我用 Moltin 发了一张票。

他们现在已将 API 调用更新为以下内容:

private func loadProducts() {
    let query = MoltinQuery(offset: nil, limit: 20, sort: nil, filter: nil, include: [.main_image])
    Moltin.product.list(withQuery: query) { (result) in
        switch result {
        case .failure(let error):
            print("Failed to get products:\n\(error)")
        case .success(let productList):
            print(productList)
            DispatchQueue.main.async {
                self.productsCollectionView.reloadData()
            }
        }
    }
}