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

Any way to access cart status messages from the sdk? #859

Open
flyingL123 opened this issue May 5, 2020 · 10 comments
Open

Any way to access cart status messages from the sdk? #859

flyingL123 opened this issue May 5, 2020 · 10 comments

Comments

@flyingL123
Copy link

Is there any way to access to cart status messages within the sdk? I'm referring to the messages that you can access in stencil via handlebars {{ cart.status_messages }}. These are used to indicate discounts the customer may or may not receive depending on what's in their cart.

It would be useful if they are in the available via the sdk since they change depending on the cart contents.

@lpschz
Copy link
Contributor

lpschz commented May 6, 2020

I think what you are looking for are promotion.banners. They belong to the checkout object https://github.com/bigcommerce/checkout-sdk-js/blob/master/docs/interfaces/checkout.md#promotions

@flyingL123
Copy link
Author

Thanks @capsula4, but based on what I'm seeing this is not the right information. I'm referring to the information that appears in cart.status_messages if you were to add debug=context to a locally running stencil store. The messages should correspond to promotions that were created in the BigCommerce control panel under Marketing > Promotions > Automatic.

Is that what you're referring to also? For example, I have a free shipping promotion created in there that looks like this:

image

When I navigate to the cart page with debug=context I can see the free shipping message in the json that's returned. However, from the same page, if I use the sdk to load the current checkout, I don't see any entries in the promotions array:

image

Also, confusingly there are two discounts appearing in the cart object, but the only information provided is a discountedAmount of 0:

image

Do you know what those discounts represent or where they are coming from? I really appreciate your help!

@flyingL123
Copy link
Author

Hi @capsula4 - just wanted to check in on this. It's actually blocking me from getting our cart finished. If these messages aren't available, I'm going to have to build some hacky workaround to get the data from stencil, but that feels really gross since I wanted to only use the storefront cart api to manage our new cart. I don't want start building the hack if there is a better solution.

Any idea? Thanks again!

@flyingL123
Copy link
Author

Looking at the cart functionality in the default Cornerstone theme, I don't see these messages in the floating cart. They only appear on the cart page itself. I'm guessing that means the information is not available to the floating cart via the API. :(

@lpschz
Copy link
Contributor

lpschz commented Jul 14, 2020

Checkout SDK only shows discounts applied to carts, but won't tell you exactly the name of the applied promotion/discount. Would be good to understand what's the exact requirement from your side.

@flyingL123
Copy link
Author

flyingL123 commented Jul 17, 2020

Thanks @capsula4. The requirement is simply to be able to show messages in the cart for discounts that have been applied. In the BigCommerce control panel you are able to set messages for when a cart-level discount is applied, or a message to promote it. For example, we have a rule set up in the control panel that says when your order total is more than $75, show "Your order qualifies for free standard shipping". Or, when it's below $75, show "Add another $2 your order for free standard shipping".

In the context of the cart in stencil, you get access to those cart messages so they can be displayed on the page. We recently rebuilt our own custom cart, and I was planning to use the new storefront cart api to do it, but found a lot of features to be missing. This was one of them.

Here's a screenshot of our current cart (on StoreYourBoard.com), when you qualify for free shipping:

image

Here's an example of when you haven't reached free shipping yet:

image

These messages are accessed in stencil via cart.status_messages. There is nothing equivalent within the storefront cart api. So, unfortunately I wasn't able to use the api. Instead I had to create a stencil handlebars template that I called cart-json.html. That file only contains the following line:

{{{JSONstringify cart }}}

Then, within my cart api code I fetch a cart like this:

async getCart(suggestId = '') {
	const { data: cart } = await axios.get(`/cart.php?suggest=${suggestId}`, {
	  headers: {
		'stencil-options': '{"render_with":"cart/cart-json"}',
	  }
	});

	return cart;
},

This allows me to build a nice floating cart, and still access the cart status messages I need since they are missing from the API.

Does that help?

@lpschz
Copy link
Contributor

lpschz commented Jul 17, 2020

Thanks for your feedback. We do expose some of these messages but not all. Could look into expanding the set of messages we expose.

@lpschz
Copy link
Contributor

lpschz commented Nov 26, 2020

We have created an internal ticket to track this issue CHECKOUT-5413

@jeffthemaximum
Copy link
Contributor

jeffthemaximum commented Nov 9, 2021

@capsula4 any update on this? I'm blocked by this issue, too.

@animesh1987
Copy link
Contributor

Hey @jeffthemaximum we haven't had time to work on this one as of now.

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

No branches or pull requests

4 participants