I need to add products to the cart depending on the shipping method. So doing this is not possible before Shipping Method page on Shopify.
I know that products can be added via AJAX api, but I am noticing a weird behavior. The scenario is something like:
On Payment page in Checkout page :
Add products via AJAX and then go to payment page - added products are not in cart anymore
Add products via AJAX and trigger reload via JS and then go to payment page - added products are in cart now
I don't know why Shopify overrides cart on payment page, if I don't reload. So looking for a solution that works without reloading the whole page.
To reproduce the bug, you can check at sample Shopify website for AJAX cart
Add some product to cart.
Go to checkout page
Add another product to cart via AJAX api ( code given below )
Get Cart via AJAX to verify that item was added.
Proceed to next page and your added products via AJAX are gone.
Add Product to cart
Checkout.$.ajax({
url: "/cart/add.js",
type: "POST",
data: JSON.stringify({
quantity: 1,
id: 794864101
}),
dataType: 'json',
contentType: 'application/json',
});
Get Cart to verify
Checkout.$.getJSON('/cart');
After adding and verifying products, just go to next Checkout step and added products via AJAX will be gone.
You can only use Javascript with checkout on Shopify Plus. If you are on Shopify Plus you would inspect the cart and add products via the Shopify Scripts and not Javascript. So your answer is:
No Shopify Plus, you can only play with the cart outside checkout
With Shopify Plus, use Shopify Scripts
Related
How we able to remove Ajax load functionality inside the Cart page when we update the quantity and press “Update Shopping Cart” button? During this process we want to refresh(Reload) the cart page.
Actually inside the cart page we have added Klarna Payment gateway option. So here Ajax load functionality not update the Klarna Payment gateway final total. Please review this -> https://nimb.ws/Pbtrzq screen shot.
So please inform me how to remove Ajax load functionality inside the Cart page “Update Shopping Cart” button.
You can simply use the below snippet for that.
jQuery( document.body ).on( 'updated_cart_totals', function () {
location.reload( true );
} );
I am using [woocommerce_cart] shortcode to load Cart in hidden absolute full-overlay div which can be opened on any page (it's located in header).
The problem: Cart AJAX is not working on any other page except mywebsite.com/cart page.
For example, when I am on my home page, I open my absolute full-overlay div which contains Shopping Cart called by shortcode, and I click on Update Cart button, it does update the cart, but instead of doing it with AJAX, it redirects me to mywebsite.com/cart page.
I figured out how to prevent redirection to /cart page by following this instructions: WooCommerce: updating cart from checkout page redirects to cart page , but it still reloads the current page instead of using AJAX.
So, the main thing I would like to achieve is to force Cart AJAX on all pages. However, it would also be helpful if someone knows how to prevent redirections after click on Update Cart, Remove Item... BUT only redirections, and let the processes of updating cart, removing items etc. to be completed (so preventDefault() is not an option.)
Thanks.
Am using the following shortcode for displaying the cart
[woocommerce_cart]
And also am using https://wordpress.org/support/plugin/woocommerce-ajax-cart plugin. When there is no products and am clicking on the button to see the Cart items it shows that the cart is empty but when am refreshing the page am getting that added product.
When i already have one product in the cart it is refreshed by ajax but when no products it did not work.
Any idea why?
Thanks in advance.
In prestashop 1.6
Using Ajax-cart
If i log-in as a Customer and add products to the cart and checkout the order all work.
Then the ajax cart stop working.
If I add a product to the cart and refresh the page the cart return
empty.
If i add a product to the cart and click "go to cart" the cart return empty.
If i log out and log in again, the cart return working for an order, then if i checkout the new order the problem return.
seem to be a problem whith Cookie the is overwritter in some ajax call in ajax-cart.js
I've look this but is not my case :Cart products dissapear on refresh page Prestashop
If i disable ajax cart all work fine.
EDIT
On Google i've found something and seem to be an ajax problem but all the solution suggested don't work.
I was also facing the same issue. You should try the following module and try last two options from the module's configuration and this issue will be gone:
https://github.com/PrestaShop/pscleaner
IMPORTANT: If you are trying it on live site make sure you do not enable first options in this module i.e. Clean up Customers, Clean up Catalog & Orders.
Reply back if you still face the issue.
Cheers!!
I have products with individual landing pages. I want the landing pages to contain everything needed to checkout with that product. This includes a dropdown to select the quantity of the product desired, shipping information and billing information. Is this possible? In default Magento, you can't get to the checkout process without first having an item in the cart.
Default Magento allows you to choose where to redirect after a product is added to cart: to the cart overview or back to the page where the "Add to Cart" button was clicked. Using a similar approach you can create an extension that overrides the 'addAction' method of the cart controller to redirect to the checkout page immediately after a product is added to cart.
You can't go to checkout with an empty shopping cart, but redirecting after the add to cart action allows customers to skip the cart page, if that is what you intend to achieve.
It is also possible to use the billing and shipping information the customer submits in the landing page for the checkout - your extension will have to validate it and save into the quote object as if it was submitted in the respective checkout steps.
Developing such an extension would not be a simple task - checkout is a very sensitive matter.