Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior change in price_range.max and .min in product.getById #208

Open
bobghkuranda opened this issue Aug 3, 2023 · 3 comments
Open

Comments

@bobghkuranda
Copy link

bobghkuranda commented Aug 3, 2023

Hi, for some time we've called product.getById for 2 products to render the price ranges for the 2 products compared in a table at the bottom of this page.
https://kuranda.com/dog-breeds/airedale-terrier

Somewhere along the way the behavior has changed where the max price returned is no longer correct for both and the min price is wrong for the second. You can see the correct prices ranges by taking a look at the first and third products on this page.
https://kuranda.com/dog-beds

I can confirm it's not an issue where my template is changing the value, if I look at the debug context for the data returned by the API call it shows the incorrect numbers as they render on the page. The only parameter I'm passing to the call besides the product ID is my custom template to render the response with.

Our products do have around 250 variants, and the true max price is found toward the end of that range assuming you sort by order of creating those variants. It's possible the change in behavior is that whatever happens on the API side with stencil utils is now capping the amount of variants it loads where before it loaded all of them. We are also on v2 product options if that makes a difference.

@bobghkuranda
Copy link
Author

bobghkuranda commented Sep 5, 2023

Here's a way this can be tested: In a stencil theme, we need a template for stencil utils to show the data it's returning.
So I'm making a file
templates/components/custom/products/demo.html
with the following contents
{{{json product}}}
Next, we need a place to call stencil utils and show this output. I'm going to stick it at the bottom of the onready function in assets/js/theme/global.js so in theory it should fire in any place where that global js is called.

Don't forget to add to the top of the file
import utils from '@bigcommerce/stencil-utils';
then at the bottom of the onready function add
utils.api.product.getById(321, { template: 'custom/products/demo' }, (err, response) => { console.log(response); });
Make sure to change 321 to an ID of a product in your store that has product attributes with a range of prices.
And make sure the template path matches what you set up in the beginning of this guide.
When you visit any page and this call takes place, you should see some json in the console. It's all one on line, but if you can paste that output into an editor that will format json it will be easier to read. Either way, look for a field in that output called: price_range
If you look at the prices in those fields, for me they used to correctly reflect the most expensive and least expensive variants but now no longer do. And it's not something where they're scoped to one default selection either. If you look back at the links in my original post, you should see how the wrong min/max and correct min/max reflect on a similar template loaded from front matter.

@bobghkuranda
Copy link
Author

Working with one support agent they’ve found that the issue is the min/max price is based on the default product options. It would be great if it could be changed so that when asking the question of a product, the min max answer is truly with respect to that product and not its default selection.

@jairo-bc
Copy link
Contributor

Hi @bobghkuranda, stencil-utils library is a frontend layer between theme and API. We are going to create a ticket and investigate a potential issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants