App: Create product by API that respects shop.taxesIncluded and calculates total price

App: Create product by API that respects shop.taxesIncluded and calculates total price

densekernel
Shopify Partner
9 0 0

We are developing an app that creates products by API and we are trying to determine how we calculate the correct price for the product depending on the merchant's tax settings.

 

We are always creating products with this API operation: https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productCreate

 

We then add variants (with a price) using this API operation: https://shopify.dev/docs/api/admin-graphql/2024-04/mutations/productVariantsBulkCreate

 

In the Shopify guide: https://help.shopify.com/en/manual/taxes/location#include-taxes-in-product-prices, they include the following instructions.

 

This means we can have 2 types of store:

 

  • Store Tax Inclusive: Include sales tax in product price and shipping rate is checked
  • Store Tax Exclusive: Include sales tax in product price and shipping rate is unchecked

Store Tax Exclusive

 

If we start with the exclusive store, we can simply create a product with a price of $1000.

 

As we have unchecked the global setting and setup a region to collect tax in.

 

The tax is automatically calculated at the checkout and added to the total price.

 

Screenshot 2024-07-11 at 14.19.12.png

Store Tax Inclusive 

 

Now the global setting to include taxes is checked (as this is expected in some areas such as UK/France) 

 

The tax component is still calculated automatically and displayed below.

 

However, the total price has now been reduced.

 

Screenshot 2024-07-11 at 14.21.24.png

 

We would still want the total price of $1,122.33 - Does this mean we need to calculate that price when we create the product via the API?

 

It looks like this might be possible by checking if taxes are included: https://shopify.dev/docs/api/admin-graphql/2024-07/objects/Shop#field-taxesincluded

 

Screenshot 2024-07-11 at 14.25.43.png

 

But it doesn't seem like there is a way to query the home tax rate of the store - so how would we know what tax component to add?

 

We did find this: https://shopify.dev/docs/api/admin-graphql/2024-07/objects/TaxLine#field-rate - but it appears that this would only be available as a dynamic rate calculated for draft orders or actual orders as opposed to a static field we could check. 

Reply 1 (1)

densekernel
Shopify Partner
9 0 0

https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/draftOrderCalculate

 

We found that we might be able to use draftOrderCalculate - but this would still require a product variant to exist ahead of time

 

Screenshot 2024-07-11 at 15.20.40.png

 

We could either create a product that we always use to verify these tax rates against - or perform this check for all newly created products and then update the price as required