diff --git a/api/resources/prices.py b/api/resources/prices.py index 5d606ab..e86468a 100644 --- a/api/resources/prices.py +++ b/api/resources/prices.py @@ -526,8 +526,7 @@ def inquiry_poster(inquiry): return data -def inquiry_external_product(inquiry): - external_id = request.args.get("external_product_id", type=str) +def inquiry_external_product(inquiry, external_id): data = { "id": inquiry.id, "retouch_price": inquiry.local_price_retouch(rounded=False, inc_vat=True), @@ -591,10 +590,20 @@ def inquiry_framed_print(inquiry): @mod.route("/inquiry/", methods=["GET"]) def inquiry(inquiry_id): inquiry = Inquiry.query.get_or_404(inquiry_id) - external_id = request.args.get("external_product_id") + external_product_id = request.args.get("external_product_id") sku = request.args.get("sku", type=str) - if external_id: - data = inquiry_external_product(inquiry) + listprice = request.args.get("listprice") + + if (listprice): + if (listprice == 'canvas'): + external_product_id = get_cheapest_canvas_product() + elif (listprice == 'poster'): + external_product_id = get_cheapest_poster_product() + else: + raise ValueError("Invalid listprice group {}".format(listprice)) + + if external_product_id: + data = inquiry_external_product(inquiry, external_product_id) elif inquiry.product_group == "photo-wallpaper": data = inquiry_wallpaper(inquiry) elif inquiry.product_group == "canvas": diff --git a/docs/prices.md b/docs/prices.md index 404f345..0ab5775 100644 --- a/docs/prices.md +++ b/docs/prices.md @@ -238,14 +238,28 @@ Sample response ## Calculate inquiry price -Calculates the price of an inquiry. For wallpapers inquiries the response will contain price information for all available materials and for canvas it will contain the price for both the framed and the not-framed canvas. External print products uses the `external_product_id` attribute. The `group` attribute tells which kind of product you are dealing with. -The width and height stored on the inquiry will be used in the calculations by default. If you want to override these values you can send in your own width/height parameters in the request. +Calculates the price of an inquiry. + +For wallpapers inquiries the response will contain price information for all available materials. The width and height stored on the inquiry will be used in the calculations by default. If you want to override these values you can send in your own width/height parameters in the request. + +External print products (canvas, posters, framed prints) uses the `external_product_id` attribute. + +The `group` attribute tells which kind of product you are dealing with. + +Parameters wallpapers | Parameter | Description | | --------- | ------------| | `width` | Width in cm e.g `100`. Defaults to the inquiry stored width | | `height` | Height in cm e.g `50`. Defaults to the inquiry stored height | + +Parameters external print products + +| Parameter | Description | +| --------- | ------------| | `external_product_id` | e.g. `canvas_400x600-mm-16x24-inch_canvas_wood-fsc-slim_4-0_ver` | +| `listprice` | Optional, one of `canvas` or `poster`. Will return the price for the cheapest product in group. Used for "Price from x kr" value | + Wallpaper inquiry - sample request @@ -285,42 +299,6 @@ Sample response } ``` -Canvas inquiry - sample request - -`curl -X GET 'https://api.photowall.com/prices/inquiry/310999?width=500&height=150` - -Sample response -``` -{ - "group": "canvas", - "id": 310999, - "prices": [ - { - "framed": true, - "height": 150, - "inquiry_price": 355.71481084, - "inquiry_price_excl_retouch": 355.71481084, - "inquiry_price_excl_vat": 284.571848672, - "m2_price": 112.887, - "m2_price_excl_vat": 90.3096, - "width": 150 - }, - { - "framed": false, - "height": 150, - "inquiry_price": 846.6525, - "inquiry_price_excl_retouch": 846.6525, - "inquiry_price_excl_vat": 677.322, - "m2_price": 112.887, - "m2_price_excl_vat": 90.3096, - "width": 500 - } - ], - "retouch_price": 0 -} -``` - - ## Calculate wallpaper kit price