I’m need help in resolving an issue where adding a product to the cart does not work when navigating through a collection page, while it works fine when accessing the product directly. Despite several debugging attempts, including inspecting network requests, reviewing JavaScript functions, and adding console logs for debugging, the issue persists. There seems to be a discrepancy in how the add-to-cart functionality behaves based on the URL structure or the page context. Any insights or suggestions from the Shopify Community would be greatly appreciated.
Issue Summary:
Problem Description:
- When navigating to a product via the dropdown menu and selecting a category (e.g., hats), adding the product to the cart does not work. However, adding the same product to the cart works as expected when navigating directly from the main page, bypassing the category route.
URL Structures:
- Working: Direct product page (https://www.birdcollective.com/products/chickadee-corduroy-hat)
- Not Working: Collection page (https://www.birdcollective.com/collections/bird-hats/products/chickadee-corduroy-hat)
Tests Conducted:1. Comparison of Network Requests:
- Analyzed network requests when adding a product to the cart from both the collection page and the product page. Observed a 400 Bad Request error when adding from the collection page, while the direct product page worked fine.
-
Review of AJAX Add-to-Cart Functionality:
- Examined the AJAXFormAddToCart and AJAXAddToCart functions in the functions.js file, responsible for handling add-to-cart operations. Suggested adding console.log statements for debugging, but no logs were observed when clicking the button.
-
Inspection of Button’s onClick Event:
- Inspected the Liquid code for the add-to-cart button, which calls an addToCart function. Added console.log to the onClick attribute and directly into the addToCart function for debugging. Again, no console output was observed upon clicking the button.
-
Exploration of Potential Causes:
- Discussed various potential causes including event propagation, JavaScript errors on the page, conflicts between scripts or libraries, dynamic content loading, browser extensions, script execution context, and server-side configurations.
I’m stumped on this issue and could use some guidance on where else to troubleshoot and see what’s happening.