Access Product Variant Price with Stencil - bigcommerce

With the legacy API, I can obtain product variant prices for productId 100 with the following:
https://something.com/api/v2/products/100/skus.json
But in the Stencil documentation for Product, there is no price property for a product attribute SKU, and the available properties that are available are limited vs the legacy API.
With product:
"values": [
{
"label": "Hardcover",
"id": 98,
"data": "Hardcover",
"selected": false
},
{
"label": "Paperback",
"id": 100,
"data": "Paperback",
"selected": false
}
],
From what I can gather, the variant pricing is only available via cart.items, but I need to display the prices before the user places an item in the cart.
Is there a way to get product variant pricing/info without using the cart.items object? Thanks!

I'm not aware of a way to do this via a stencil object.
On the product detail page I check if a product has_options, then make ajax calls to the variant URLs to get their prices to create a price range before the user selects their variants. This is pretty necessary when the vendor has huge price differences in variants.
ex.) "From $49.99 - $499.99" instead of "$49.99" default functionality.
I don't have a resolution for category pages as it doesn't make sense to make AJAX requests for each variant of each item on the category page on load. Once Stencil adds support for custom fields on the category page, you could add the child's prices to a parent SKUs custom field and perform some logic for whatever your trying to accomplish.
I don't know when custom fields will be available on the category page but I know they are working on it.

Related

How to get the products in a category thats based on Dynamic Product Groups from the shopware API

I have a high volume shop with a lot of products and categories.
The products are seasonal, so a lot of new products are added.
Because of this, dynamic product groups are perfect. We set conditions and add the group to the category.
Right now i'm trying to get all the products of the category in the api's (both backend and store), but i dont get any product back. I do get a streamId back in the store-api https://localhost//store-api/product-listing/9cf2c65bd7084144aa4d4a35bb3f568e But there is no endpoint i can call for the streamId.
Next to that, the breadcrumbs are also missing on the front-end.
What is the best way to get a the products from a category back in the API?
Thanks!
If you do have the id of the product_stream you can filter product entities by them having that id as part of their streamIds:
// POST /api/search-ids/product
{
"page": 1,
"limit": 500,
"filter": [
{
"type": "equalsAny",
"field": "streamIds",
"value": [
"65103ca79e1e4e3ba846f551fbb1cb36" // your product stream id
]
}
]
}

Item level tracking in Shopify

Could you please specify, what is the correct way to track the quantity of the variants of items in stock?
I see that products/update webhook shows the quantity, but I'm not sure if it fires when an item is purchased (and its quantity reduces by one), and in case of inventory_items/update there's no quantity information (though it seems I can thract it using InventoryLevel API call), but I'm not sure if this notification launches after item purchase.
Short answer: Both products/update and inventory_levels/update are fired when an item is purchased.
The request body of products/update looks something like this:
{
"id": 123,
"variants": [
{
"id": 456,
"product_id": 123,
"inventory_quantity": 99
}
]
}
inventory_quantity is the updated stock of the item that has just been purchased.
On the other hand, the request body of inventory_levels/update looks something like this:
{
"inventory_item_id": 987,
"available": 99
}
So both webhook topics give you access to the data you need. In the end it depends on your specific use case which of those two topics to use.

Shopify Create Order API

I used the Shopify API to create an order using my product's variantID.
For some reason, line_items in orders created using the API always have "vendor":"null". Whereas orders for the same variant created via the store returns the correct vendor.
Am I doing anything wrong?
URL: https://xxyy.myshopify.com/admin/orders.json
{ "order": {
"email": "ken#xxyy.com",
"fulfillment_status": "unfulfilled" ,
"send_receipt": true,
"send_fulfillment_receipt": false,
"line_items": [{
"variant_id": 3866750123,
"quantity": 1
}]
}
}
I get that sometimes too and it is truly crappy. If you create a line item using the API it seems you need to provide not only the product and variant ID, but also the vendor, as even if it exists in the product, that does not get picked up in the order creation process. A lot of Apps screw this up. Which screws up other Apps expecting good orders. And a it seems to me a good order should have the product vendor field set.

Bigcommerce API - Create Shipment - Include all Items

according to the documentation, the Create Shipment method requires the property "items" - an array of the items being shipped, for example:
{
"tracking_number": "EJ958083578US",
"comments": "Ready to go...",
"order_address_id": 1,
"items": [
{
"order_product_id": 15,
"quantity": 2
}
]
}
In our business, a shipment almost invariably contains ALL items from the relevant order.
That being the case, is there a way to create a shipment without listing all items (which would require iterating over the product line-items)? Or, alternatively, a way to include all items by default (without iterating)?
We are simply wishing to automate the process of adding tracking numbers to orders - which (as a manual process) involves uploading a csv with [order_number: tracking_number] - i.e. it self-evidently assumes that all items are being shipped. The API seems not to include that (very sensible) option, but I may be wrong.
From Bigcommerce Support:
There is not a way to add a tracking number without adding a shipment nor a way to default the shipment to include all products. This is a helpful suggestion though that I will be passing on to our Product Team for possible implementation into future versions of the API.
Unfortunately for now it is necessary that you GET to the products subresource of an order and iterate over all of the products to pull their 'id' values and 'order_address_id' values so you can generate your POST request to the shipment subresource. It is not necessary to make a GET request to the shipping address subresource directly unless you want the details of that shipping address. It is also not necessary to make a GET request to the base order object unless you want details found there or you are looking to automate the process of checking for orders ready to ship.
So assuming you know an order ID that you want to ship it should only take 2 requests total to both GET the products subresource and then POST to the shipment resource.

How to retrieve all products from a Smart Collection through Shopify API?

What's the best way to retrieve all products from a Smart Collection through Shopify API?
Thanks!
Update: API version 2020-04
See Codesmith's answer below. As of API version 2020-04, you can now use a smart collection id with the collections endpoint:
GET /admin/api/2020-04/collections/{collection_id}/products.json
See the Collection API docs for more info.
Pre-2020 solution
From the SmartCollection page in the Shopify API docs:
Smart Collections also use collects to connect a product to that smart collection.
And on the Collects page:
List only collects for a certain collection
GET /admin/collects.json?collection_id=841564295
HTTP/1.1 200 OK
{
"collects": [
{
"collection_id": 841564295,
"created_at": "2014-05-23T14:16:47-04:00",
"featured": false,
"id": 1071559648,
"product_id": 921728736,
"sort_value": "0000000001",
"updated_at": "2014-05-23T14:16:47-04:00",
"position": 1
},
...
]
}
The collects contain the product_ids for each of the products in the collection with the specified collection_id.
2020 Update,
For the latest API (2020-04 as of now), you can simply use the /collections/ endpoint, using the Smart Collection ID:
GET https://<shopname>.myshopify.com/admin/api/2020-04/collections/<smart collection id>/products.json
More details can be found in Shopify's Collection API Docs.