woocommerce add to cart ajax issue - ajax

Woocommerce is probably working properly but I would like my add to cart on every page to be like the detail/single item page ajax actions.
This is what I want:
add to cart -> top of page says successfully added to cart and update total on top. This is how the detail/single item page cart buttons work.
Instead of :
Currently they add to cart and a view cart button shows successfully on the side instead and not refreshing the total on top.
How can I accomplish this.
Thank You.

If the cart is being updated after you refresh the page, then look at running a refresh after the form submits:
onsubmit="setTimeout(function () { window.location.reload(); }, 10)"

Related

Capturing Add To Cart Event

I am looking for a solution about how to call a javascript function when an item is added to cart on shopify via ajax. Product can be added from homepage, collection-page or product-page.
I am trying with this method but not working for me. These changes i am doing within the theme files "theme.liquid, product.liquid, collection.liquid"
Everytime product go to cart alert should done.
Shopify.onItemAdded = function(line_item) {
alert('success');
};
You'll want to use CartJs... is does exactly what you need and has events etc for when things are added to cart

when click on add to cart it is not showing value after refreshing the page it is showing value

when click on add to cart it is not showing value after refreshing the
page it is showing value. Setlocation function is not working on list page
You can use the below extension for addign extra fee:
https://github.com/magentix/Fee

Magento : change price in cart on the fly

We have 2 observers to change product price in the cart : checkout_cart_product_add_after to change price the first time the product is added to cart, and checkout_cart_update_items_after to change price for each item in the cart (when user click the "Modify cart" button on cart page). Both are running OK.
My question : On the cart page, when user clicks the link "Edit" to edit the product in product page (so he can change quantity, ...) and clicks the "Update cart" button, this update button does not read any observer to refresh price. Only the quantity is refreshed.
How to force this "Update cart" (on product page) action to process the code in observer? Is there another observer for this? The code in checkout_cart_product_add_after is executed just the first time the product is added to the cart?
Thanks.
Copy this file:
app\code\core\Mage\Checkout\controllers\CartController.php
To:
app\code\local\Mage\Checkout\controllers\CartController.php
Go to:
public function updateItemOptionsAction()
{
Add your custom logic or fire off a custom event you can listen to and run the same logic on.
Don't forget to flush ;)

How do I implement a Shopping Cart with Empty, Update Quantity, and Submit buttons?

I have a page that displays the contents of a shopping cart in a table. The Quantity field is an editable text box, allowing the user to update its value. I need three buttons - one for Empty cart, one for Update cart, and one for Submit cart.
My ShoppingCartController has these methods:
postCartItem($id)
putUpdateCart()
deleteCartItem($id)
deleteCart
The submit button takes it to the store method of the OrderController resource controller
I'm going out of my mind how to do this RESTfully.
Any tips/best practices would really be appreciated.

Woocommerce and AJAX add to cart broken

I have got problem with Woocommerce.
When I click multiple times "add_to_cart_button" on archive-page.php AJAX stops working and redirects to product page.
First I checked the server response and its just fine. 200 OK :)
Then i looked into scripts. I found add-to-cart.js:
if ( response.error && response.product_url ) {
window.location = response.product_url;
return;
}
Great, I added simple alert:
if ( response.error && response.product_url ) {
alert(response.error);
window.location = response.product_url;
return;
}
Ok, "response.error" is equal to true when script is moving into this if... But why this if statement is being true? How can I read error status? $.fail doesn't work.
What is going on? Please help :/
The redirect to the product page is due to an error adding the product to the cart. If you have inventory, order maximums, product in cart maximums and any other limitations set this will happen. It's built in. Please look into your product setup.
I can add couple of things related to problems with WooCommerce add to cart ajax buttons:
In WooCommerce tab (from WP dashboard) => Settings => Products tab you see two checkboxes, one for enable/disable async in buttons and another for redirect to cart page directly on adding to cart a product.
Also I noticed that if product posts visibility setting is set as private will trigger error in ajax request response so will redirect to product page (if available). So watch out of this too.

Resources