commercelayer / demo-store-core

Commerce Layer Demo Store CORE
https://commercelayer.github.io/demo-store-core
MIT License
7 stars 20 forks source link

Add to Cart never works #2

Open osseonews opened 2 years ago

osseonews commented 2 years ago

We built this demo store locally, with our unique client id and endpoint, and we were able to see all the pages, navigate etc. However, on the actual product page, the "Add to Cart" button is never functional. It is just greyed out and you can't click it. Is there some other setting required to activate the Cart? Thanks.

osseonews commented 2 years ago

So I figured out that the application needs to actually get a price of a product to create the Add to Cart, but there is no indication that a price needs to be in the JSON file for the product. So are the prices only getting fetched from the Commerce Layer endpoint? Not clear how this works. Also, it looks like the "sku" key in the products.json is what is used to fetch the data from CommerceLayer. If so, what is the purpose of the "variantCode" key?

marcomontalbano commented 2 years ago

Hi @osseonews , Commerce Layer manages SKUs , as you said in the products.json there's an attribute called sku that is the connection between the demo store product and commerce layer. Inside the products.json you can find 3 codes:

  1. productCode identifies the master product.
  2. variantCode identifies a specific variation for a master product (e.g. a red shirt, or a blue shirt).
  3. Sku uniquely identifies a product (e.g. a red shirt with xl size) that can be sold. At the moment the variantCode is used to show different variations when you are using facets or doing a search. This can be also used if you want to show all the variations for a product in the product list page.

Going back to your original question, you already added the client id and the endpoint in your environment variables. As said, the product sku has to be present as sku in your commerce layer organization and your organization need to be properly configured (did you add a price and a stock for that sku?) Last but not least, you should update the countries.json file specifically you should update all market references, pointing them to your commerce layer markets. You don't need to put the price in the products.json; the price will be automatically fetched for commerce layer.

If this still doesn't work, open the developer tool from your browser and check if you have any console error and if you see any network request to commerce layer API endpoint.

I hope that this can help you, and thanks for your feedback. We will update the demo store documentation to better clarify all these aspects.

osseonews commented 2 years ago

Hi @marcomontalbano Thanks for the comments. Yes, we realized that we need to have the SKU in the commerce layer organization and also that we need to update the countries.json file with the correct market id. We did both, but the problem is that whenever we update the products.json file with the correct SKU from our commerce layer organization, we get errors on the frontend. Specifically, one error is Error: Cannot find a Product with sku equal to 5PANECAP000000FFFFFFXXXX

This happens because have changed the SKU in the products.json file to our sku, but for some reason the system is still looking for the old SKU 5PANECAP000000FFFFFFXXXX. We tried to remove the .next folder to clear the cache and rebuild, but it doesn't do anything.

Basically, we cannot figure out how to actually use our own product.json data. We have tried repeatedly to update the products.json file per above with the correct SKU's, but we keeping errors for SKU's that only exist in your implementation of the products.json. Any ideas? Thanks.

marcomontalbano commented 2 years ago

Hi, did you update the pages.json and taxons.json? In these file there are references to skus for our demo.

Let us know

osseonews commented 2 years ago

Thanks. Yeah, we didn't update those. Wasn't sure what they were for. We will update now and see if it fixes the error.

osseonews commented 2 years ago

BTW, fixing the pages.json and taxons.json file worked! But, we also needed to modify the slug in the products.json. Anyway, we can now get our products from commercelayer. Have a few more unrelated issues, i'll post. thanks.

marcomontalbano commented 2 years ago

Thanks a lot for your feedback! We will improve the documentation with all these findings. I'll keep this issue open until that.

osseonews commented 2 years ago

@marcomontalbano below are some more issues I have found. I figured it might be easier to just list them all here instead of opening a new issue for each one:

That's it. hope it helps.

marcomontalbano commented 2 years ago

Hi @osseonews, thank for sharing these. About the first one we already have an internal card to handle that scenario when the hosted cart is used with embed=true About the SEO issue we are using the canonical url for all the product pages ..all variants point to the first variant of a master product. This should be enough to solve duplicate content. Let us know if this is fine for you. We also have a card to general improve the SEO of the demo-store but currently should be good enough. About last two I'll share them internally.. both look interesting!

osseonews commented 2 years ago

Hi @marcomontalbano Thanks. What does it mean, internal card? That means you are already working on fixing the cart bug? As for SEO: Yes, if there is only 1 canonical, that should be fine. I wasn't able to confirm that. I'll look.

osseonews commented 2 years ago

BTW, I think "Removing locale from URL for main locale " is a critical thing, though obviously not a bug. The issue is that this repo is a low-code way of building a CommerceLayer website. Most low-code website are built by small biz, who will not have websites in multiple countries and languages. So even though it's great to have a solution that can support growth via different languages down the road, if you need to, for immediate needs it's not a good solution. I would think you can set some sort of default value for the location in an ENV variable, and then the main routes in the store can drop the location in the URL, and then only the secondary locations will show up in the URL, if they are used.

marcomontalbano commented 2 years ago

Hi @marcomontalbano Thanks. What does it mean, internal card? That means you are already working on fixing the cart bug? As for SEO: Yes, if there is only 1 canonical, that should be fine. I wasn't able to confirm that. I'll look.

Yes exactly. We already having an internal discussion about that. Demo Store is embedding our Hosted Cart, that's why state is not shared at all.

osseonews commented 2 years ago

Just a quick update, I did some research on the SEO issue and I'm quite convinced that doing it the way you are doing it now, all variants have their own URL even if the canonical URL points to the master product, is not good for SEO. As SEO is critical for any website, I think this is the wrong route to go down. It's also very confusing for a user in terms of a UI, as you have multiple URL's with the same exact content. The correct way to do this is that variants of a product should never have their own URL. Only the master product page should have a URL/Slug. For products that don't have variants, then obviously it's not an issue.