urlmoltin

Moltin URLs for Product Images


Swift 4.0 | iOS 11

I require image URLs from Moltin Products request.

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.


Solution

  • I posted a ticket for this with Moltin.

    They have now updated the API call to the following:

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