Double Discounted Lines in Shopify Order API - shopify

I came across a situation that I hope someone else has seen.
The order looks like this in shopify:
The Discounted Line Item JSON looks like this:
{
"id": XXXXX,
"name": "NAME",
"price": "19.10",
"product_exists": true,
"quantity": 1,
"sku": "SKU",
"total_discount": "9.55",
"discount_allocations": [
{
"amount": "9.55",
"amount_set": {
"shop_money": {
"amount": "9.55",
"currency_code": "USD"
},
"presentment_money": {
"amount": "9.55",
"currency_code": "USD"
}
},
"discount_application_index": 0
}
]
},
An Automatic Discount as a "BOGO at 50% off" was applied to this order, but I cant quite get the discounting right for a net unit price, without also causing issues elsewhere in this particular Shopify Tenant.
Previously I would
line_unit_price = price - (TotalDiscount/Quantity) - SumOfDiscountApplications
But in this case, that would just double discount it to zero, which is not correct. In other cases with this Shopify Tenant, I do need to use the Discount Applications as TotalDiscount would be 0. I cant quite figure out when/where/why to do the math differently for an effective Line Net Unit Price.
Very odd. Any help would be great.

Related

How to get a product / variant "committed" inventory?

Problem:
On the Shopify Admin, section Products > Inventory, there's a "committed" inventory.
Based on my comprehension it means "reserved stock for pending orders", or "inventory reserved by orders created but not yet completed".
This "committed" stock value can be very useful for stock updates by app. But pratically this value seems hard to retreive.
Question:
How to get this "committed" inventory value in an efficient way ?
Current state of researchs :
Not possible via Shopify APIs (REST & GraphQL, version 2022-07)
Can be approximated (not sure it's the right method) by looping over all unfulfilled orders, and sum up (by variant) the unfulfilled product variant quantity. However, it takes time and consumes a lot of API resources.
According to a Shopify Community Manager (ref. post)
The Committed inventory state isn't added to the API currently.
It's possible now in the 2023-01 version of the API. The InventoryLevel got a new field quantities, which returns this for a product with a total stock of 10 and two sold:
[
{
"quantity": 8,
"name": "available"
},
{
"quantity": 2,
"name": "committed"
},
{
"quantity": 0,
"name": "incoming"
},
{
"quantity": 10,
"name": "on_hand"
},
{
"quantity": 0,
"name": "reserved"
}
]

Great Expectations Row Based Dimensions

I have data like this:
[ {
"name": "Apple",
"price": 1,
"type": "Food"
},
{
"name": "Apple",
"price": 0.90,
"type": "Food"
},
{
"name": "Apple",
"price": 1000,
"type": "Computer"
},
{
"name": "Apple",
"price": 900,
"type": "Computer"
}
]
Using the Great Expectations automatic profile, a valid range for price would be 0.90 to 1,000. Is it possible to have it slice on the type dimension, so food would be 0.90 to 1 and computer would be 900 to 1000? Or would I need to transform the data first using dbt? I know the column that will create the dimension, but I don't know the particular values.
Also, same question on differences between rows. Like if they had a timestamp, instead of 900 to 1000, it validates -100 for the change in value.
I used this approach to first load the data in a pandas data frame:
https://discuss.greatexpectations.io/t/how-can-i-use-the-return-format-unexpected-index-list-to-select-row-from-a-pandasdataset/70/2

Querying Line Items of Order with JSON Functions in BigQuery

I am banging my head head here for the past 2 hours with all the available JSON_... functions in BigQuery. I've read quite a few questions here but no matter why I try, I never succeed in extracting the "amounts" from my JSON below.
This is my JSON stored in a BQ column:
{
"lines": [
{
"id": "70223039-83d6-463d-a482-7ce4d50bf0fc",
"charges": [
{
"type": "price",
"amount": 50.0
},
{
"type": "discount",
"amount": -40.00
}
]
},
{
"id": "70223039-83d6-463d-a482-7ce4d50bf0fc",
"charges": [
{
"type": "price",
"amount": 20.00
},
{
"type": "discount",
"amount": 0.00
}
]
}
]
}
Imagine the above being an order containing multiple items.
I am trying to get a sum of all amounts => 50-40+20+0. The result needs to be 30 = the total order price.
Is it possible to pull all the amount values and then have them summed up just via SQL without any custom JS functions? I guess the summing is the easy part - getting the amounts into an array is the challenge here.
Use below
select (
select sum(cast(json_value(charge, '$.amount') as float64))
from unnest(json_extract_array(order_as_json, '$.lines')) line,
unnest(json_extract_array(line, '$.charges')) charge
) total
from your_table
if applied to sample data in y our question - output is

BigCommerce Stencil - Retrieve Product Custom Fields in Product Card

I'm trying to retrieve each product's custom_fields data on the category list pages in BigCommerce Stencil. This documentation here, and the JSON product representation below, would suggest this is not possible.
It is hard for me to believe this functionality would be left out of Stencil, considering it was available in Blueprint.
{
"id": 691,
"name": "Archipelago Botanicals - Pomegranate Lip Gloss",
"url": "http://******.mybigcommerce.com/archipelago-botanicals-pomegranate-lip-gloss/",
"brand": {
"name": "Archipelago Botanicals"
},
"rating": 0,
"availability": "",
"summary": "Pomegranate lip gloss leaves lips hydrated, shiny and smooth. Apply liberally.Net Weight: 0.42 oz. / 12 g Mineral Oil, Polybutene, Octyidodecanol, Butylene, Ethylene, Styrene Copolymer, Ethylene, Propylene, Styrene Copolymer, C18-36 Acid Triglycerides, Fr",
"image": {
"data": "https://cdn3.bigcommerce.com/*****/images/stencil/{:size}/products/691/41439/arbopolipgl__77026.1464267682.jpg?c=2",
"alt": "Archipelago Botanicals - Pomegranate Lip Gloss"
},
"date_added": "Apr 7th 2016",
"qty_in_cart": 0,
"pre_order": false,
"has_options": false,
"show_cart_action": false,
"price": {
"without_tax": {
"formatted": "$5.00",
"value": 5
},
"rrp_without_tax": {
"formatted": "$12.50",
"value": 12.5
},
"saved": {
"formatted": "$7.50",
"value": 7.5
},
"tax_label": "Tax"
}
},
Am I missing something, or is this functionality not available on Stencil at this time?
Has anyone come up with a creative solution to retrieve this data inside each product card?
Thanks
The product card now allows this to be exposed. It provides an array of all custom fields associated with a product. Information on the product card object is here.
It was a change that had to be made in the BC core app and the fix was released on Sept 20th

How do i make custom reordering for products in collection in shopify

How do i make custom reorder for products in collection in shopify. i mean for exapmle i have 'test' collection and i want to reorder products in 'test' collection by using product tag i mean i put some tags like 'firstshowup' in some product in 'test' collection so when customer click 'test' collection customer see products which have 'firstshowup' tag first and then see the rest so what iam trying here is reordering using custom reordering not using like order by bestseller or allpabetically or date created s.t
thank you so much guys in advance
Your collection will be made up of Collect objects, which have a position attribute. Assuming you're using a CustomCollection, you can modify the position of the Collects by updating the CustomCollection: http://api.shopify.com/customcollection.html#update
From the examples, to update a collection, you can use:
PUT /admin/custom_collections/#{id}.json
With the following payload:
{
"custom_collection": {
"body_html": "<p>The best selling ipod ever</p>",
"handle": "ipods",
"id": 841564295,
"published_at": "2008-02-01T19:00:00-05:00",
"sort_order": "manual",
"template_suffix": null,
"title": "IPods",
"updated_at": "2008-02-01T19:00:00-05:00",
"image": {
"created_at": "2012-12-11T12:01:29-05:00",
"src": "http://cdn.shopify.com/s/files/1/0006/9093/3842/collections/ipod_nano_8gb.jpg?0"
},
"collects": [
{
"product_id": 921728736,
"position": 1
},
{
"id": 841564295,
"position": 2
}
]
}
}