Redirect to cart page after I click add to cart button - Dawn Theme

Solved
ollivtheone
New Member
2 0 1

I would like to skip the cart popup notification and redirect the customer directly to the cart page. I'm using the Dawn theme.

Thank you in advance!

Accepted Solution (1)

Accepted Solutions
dmwwebartisan
Shopify Partner
9824 2236 3073

This is an accepted solution.

@okt  @ollivtheone 

 Step 1: Go to Online store > Themes > Actions > Edit code. -

Step 2: Go to Assets >product-form.js and find this code 

 

this.form.addEventListener('submit', this.onSubmitHandler.bind(this));

 

comment this code like this 

 

/* this.form.addEventListener('submit', this.onSubmitHandler.bind(this)); */

 

Thanks!

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com | Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | Bag is a cart drawer that maximizes your sales. View app →

View solution in original post

Replies 13 (13)
okt
New Member
2 0 1

Hey,

I'm looking also for the exact same thing, there is no option in the theme editor that allows us to skip the cart notification.

Is there any code modification to do ?

Thanks !

dmwwebartisan
Shopify Partner
9824 2236 3073

This is an accepted solution.

@okt  @ollivtheone 

 Step 1: Go to Online store > Themes > Actions > Edit code. -

Step 2: Go to Assets >product-form.js and find this code 

 

this.form.addEventListener('submit', this.onSubmitHandler.bind(this));

 

comment this code like this 

 

/* this.form.addEventListener('submit', this.onSubmitHandler.bind(this)); */

 

Thanks!

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com | Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | Bag is a cart drawer that maximizes your sales. View app →

View solution in original post

okt
New Member
2 0 1

Thanks man, you're so good !

VuongTuanAnh
Explorer
48 0 7
BenTiemann
Excursionist
16 0 3

like this? because it doesnt work for me

frage 17.10.PNG

Thank you for your help

Best regards

Ben

dmwwebartisan
Shopify Partner
9824 2236 3073

@BenTiemann 

Please share your Assets >product-form.js file code 

 

If helpful then please Like and Accept Solution | Email: dmw.webartisan@gmail.com | Instagram: @dmw.webartisan
Check here PageFly App to customize your pages | Bag is a cart drawer that maximizes your sales. View app →
BenTiemann
Excursionist
16 0 3

Thats my code:

 

if (!customElements.get('product-form')) {
customElements.define('product-form', class ProductForm extends HTMLElement {
constructor() {
super();

this.form = this.querySelector('form');
this.form.addEventListener('submit', this.onSubmitHandler.bind(this));/* this.form.addEventListener('submit', this.onSubmitHandler.bind(this)); */
this.cartNotification = document.querySelector('cart-notification');
}

onSubmitHandler(evt) {
evt.preventDefault();
const submitButton = this.querySelector('[type="submit"]');
if (submitButton.classList.contains('loading')) return;

this.handleErrorMessage();
this.cartNotification.setActiveElement(document.activeElement);

submitButton.setAttribute('aria-disabled', true);
submitButton.classList.add('loading');

const config = fetchConfig('javascript');
config.headers['X-Requested-With'] = 'XMLHttpRequest';
config.body = JSON.stringify({
...JSON.parse(serializeForm(this.form)),
sections: this.cartNotification.getSectionsToRender().map((section) => section.id),
sections_url: window.location.pathname
});

fetch(`${routes.cart_add_url}`, config)
.then((response) => response.json())
.then((response) => {
if (response.status) {
this.handleErrorMessage(response.description);
return;
}

this.cartNotification.renderContents(response);
})
.catch((e) => {
console.error(e);
})
.finally(() => {
submitButton.classList.remove('loading');
submitButton.removeAttribute('aria-disabled');
});
}

handleErrorMessage(errorMessage = false) {
this.errorMessageWrapper = this.errorMessageWrapper || this.querySelector('.product-form__error-message-wrapper');
this.errorMessage = this.errorMessage || this.errorMessageWrapper.querySelector('.product-form__error-message');

this.errorMessageWrapper.toggleAttribute('hidden', !errorMessage);

if (errorMessage) {
this.errorMessage.textContent = errorMessage;
}
}
});
}