简体   繁体   English

产品图片的Moltin URL

[英]Moltin URLs for Product Images

Swift 4.0 | Swift 4.0 | iOS 11 iOS 11

I require image URLs from Moltin Products request. 我需要Moltin产品请求中的图片网址。

I have the following function: 我有以下功能:

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()
            }
        }
    }
}

This is spitting out: 这会吐出来:

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)]

Has anyone had success in pulling a URL for the main_image?... It is only giving the image ID & type. 是否有人成功提取了main_image的URL?...仅提供图像ID和类型。

I posted a ticket for this with Moltin. 我和莫尔丁为此签了票。

They have now updated the API call to the following: 他们现在将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()
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM