I am read the office doc https://developer.bigcommerce.com/api-reference/89019d490c6f8-carts
but i can find the cart data end point.
get the singe cart data need cartid Get a Cart GET https://api.bigcommerce.com /stores/{store_hash}/v3/carts/{cartId}
but where to get the CartId
I am using this boilerplate https://github.com/bigcommerce/sample-app-nodejs
my code look like for call api.
const { data } = await bigcommerce.get('/carts'); console.log("this is store cart api call ",data) res.status(200).json(data);
I mention the code block above
expecting output was get the real time store front cart data.
show to the admin where app dashbord show the list of cart activity on going.
Related
When you add BigCommerce product to Wishlist, the SKU is not added to {{wishlist.item}} object.
I did a {{log wishlist}}, after the product is added, the SKU is null.
the item object has a lot of key fields that are null like availability, summary, stock_level and also boolean values like pre-order, has_options etc. How can i populate them when adding a product to wishlist?
Is there a way to pass the SKU thru "/wishlist.php?action=addWIshlist&product_id={{product.id}} ??
if possible, how and where can i use JS code to pass this value to the wishlist action everytime i add a product to wishlist?
According to BC's Wishlist Object documentation, you should have access to the product's SKU. Now, if you have SKUs set at the variant level, and are trying to access that, you will be out of luck. Products only get added to the wishlist at the product level, and do not contain any variant information.
The issue you might be having is you might be trying to access this data on a page where it is not exposed. The only page where this data is exposed is on the wishlist details page for that wishlist. To access it on another page, you would need to make an AJAX request to the wishlist details page.
I would like to show the product variant quantity on the product page like this:
Location 1: 5 in stock
Location 2: 2 in stock
Location 3: 63 in stock
Location 4: 5 in stock
and so on...
Is it possible to do this using the admin API from Shopify?
Thanks in advance.
It is not recommended to use the Shopify admin API directly in the store front as you could be exposing the API username and keys in your JS code.
You should use a backend service or something similar where your frontend will send a request to the backend. The backend will then fetch the records using the Shopify rest admin APIs and return the data back.
If you prefer to go the custom code route below are a few things for you to keep in mind
Shopify has API rate limits. You most likely will be hitting these if you fetch every time a product page is loaded. Limits mentioned here
As an option for the rate limits, you could query the backend every x mins, save them in the database and serve the inventory levels from the DB. Or you could try to cache your request for a certain time limit instead of saving in the DB.
If you just want to how much is available across all inventory locations, you can use the below liquid/JS code.
<script>
var variantStock = {};
{% for variant in product.variants %}
variantStock[{{- variant.id -}}] = {{ variant.inventory_quantity }};
{% endfor %}
console.log(variantStock);
</script>
In the above code, you will have the available inventory quantity for each variant in the variantStock object. You can then write some extra code to display the stock levels when the user changes variants accordingly.
Check the liquid object document for variants here
Having said the above, another option is to use an app that will do the above for you. There are many apps in the Shopify app store that does exactly what you want.
i'm writing on behalf of our client MOEBE.
Our developer has a problem with the way Roomle use the shortID which is used to add the items into the cart. He says that we need to change the shortID from SKU to product variant ID. Shopify doesn’t allow the cart API to use SKU to add items in the basket.
Alternative if we can get access to the backend in Roomle, then he will be able to create a map between the SKU and variant ID.
Sadly shopify do not allow using SKU codes using Ajax API.
If you modify the process of adding to the cart You probably need use some try and error run.
The very fact of adding a product to the cart can be largely solved by extending the JS code on the product page.
I suggest listing the variants of the product to the variable in the liquid template and using an additional script to handle adding to the cart. It might look dirty, but it will work.
<script type="text/javascript">
var product= `{{ product | json }}`; //Whole product variable
var variant_id = {{ product.variants[0].id }}; //First product variant id
</script>
Do you have one variant per product or more?
I would like to add a new product (line item) via Shopify Scripts when a user uses a discount code. Is it possible?
if Input.cart.discount_code && Input.cart.discount_code.code == "first10"
Input.cart.line_items << LineItem.new(variant: 24665166184512, quantity: 10, source_indices:false,grams: 0, properties_was:false, properties:false, line_price_was:false, line_price:50, original_line_price:50, discounts:0, adjustments:nil)
end
Output.cart = Input.cart
And I have error:
[Error] undefined method 'id' for 24665166184512
shopify/std_lib_mutable/core/resources/line_item.rb:164:in LineItem.to_hash
shopify/std_lib_mutable/core/resources/cart.rb:43:in Cart.to_hash
shopify/std_lib_mutable/cart_line_items/output.rb:4:in #<Class:0x7f85471e6280>.to_hash
shopify/std_lib_mutable/cart_line_items/output.rb:4:in #<Class:0x7f85471e6280>.to_hash
shopify/std_lib_mutable/core/script_kernel.rb:12:in Object.prepare_output
(prepare_output):1
Unfortunately you cannot add products to a cart using Shopify Cart Scripts.
Cart scripts can only see and handle items that are already present in the cart.
as mentioned in comments, you can delete an item because it already exists in the cart.
My advise is to use either of these methods.
1) discount codes that when someone buys something they get another product at a certain price or free.
2) create an Ajax API script that when an item is added to the cart it looks up what items are in the cart and if the item is found then adds the free item or discounted item to the cart.
https://help.shopify.com/en/themes/development/getting-started/using-ajax-api
3) (PAID OPTION) is to have a look in the app market place and you can find a few different apps available to help you with this. this one looks like it might help you? https://apps.shopify.com/special-offers
I am trying to get cart options to be included in the line item response
My Attempt (nodejs)
return bc_acc.get(`/carts/${cartId}?include=options`, {include:'options'}).then(data => {..
The response is fine but i expected to see options per line item. But its not there. The API Docs show it in the response.
The Response
Specify the full path of the include object like:
/carts/${cartId}?include=line_items.physical_items.options