Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added add to cart behavior global setting #744

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion assets/product-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ if (!customElements.get('product-form')) {
}

onSubmitHandler(evt) {
if (this.dataset.addToCartBehavior == 'go_to_cart') return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could move this right after the this.handleErrorMessage(); so we still notify the user on the product page if there isn't more of this product ?
Here is some errors I noticed on the cart while testing it: video. But Let me know in case it was just local issues.

There seem to be an issue coming from dynamic checkout buttons 🤔 on the cart page: screenshot.

Copy link
Contributor Author

@tyleralsbury tyleralsbury Oct 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the first issue with the cart error, I'm thinking it might be a local environment issue (or a bug that came from elsewhere) since I didn't change any of the actual cart JS.

For the second issue, I'm wondering if we should do anything to change that... my thought is, the merchant is looking to effectively take the user right to the cart page and if we were to show an error on the product page, then that would mean we're still making an AJAX call and then sending them there only if there's a success. This will slow things down a lot compared to what I'm doing right now which is effectively just submitting the form (basically the no-js flow).

I do find it interesting that the cart can't auto-adjust though, but I wonder if that's a limitation of the Liquid API. Like when you go to the cart page, it would make sense for the Liquid to have an awareness that the total quantity is higher than the available quantity. Because again, if the Liquid doesn't have that available, it's another situation where we'd need to make the check on the cart page when the page load via AJAX and then make adjustments. This also goes against one of our theme development principles of "don't do DOM adjustments prior to user input".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's kind of an odd situation. I think that if I can't add the product to the cart because there is none left/I've added them all already, then don't take me to the cart. Let me know on the spot rather than make me wait and load a new page to tell me that 🤔

It's kind of like a frustrating flow there was with recaptcha where sometimes you'd need to go through captcha verification to just be told the email was already registered or something. Ideally if something is wrong or can't be done, don't make me wait and tell me right away.

My 🪙 🪙 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the problem is just that it would cause a delay in all of the cases where the action is valid since we'd need to do a round-trip AJAX call and then redirect to the cart anyway. Since the checkout itself can correct this, I think it makes sense for us to leave this behaviour in because the alternative is too clunky.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to add more logic in here then.
So that if this.dataset.addToCartBehavior == 'go_to_cart' is true we run a check on the product quantity available before going to the cart page with a fetch 🤔


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

this.handleErrorMessage();
this.cartNotification.setActiveElement(document.activeElement);
Expand Down
21 changes: 21 additions & 0 deletions config/settings_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,26 @@
"default": true
}
]
},
{
"name": "t:settings_schema.cart.name",
"settings": [
{
"type": "select",
"id": "add_to_cart_behavior",
"options": [
{
"value": "cart_notification",
"label": "t:settings_schema.cart.settings.add_to_cart_behavior.cart_notification.label"
},
{
"value": "go_to_cart",
"label": "t:settings_schema.cart.settings.add_to_cart_behavior.go_to_cart.label"
}
],
Comment on lines +338 to +347
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"options": [
{
"value": "cart_notification",
"label": "t:settings_schema.cart.settings.add_to_cart_behavior.cart_notification.label"
},
{
"value": "go_to_cart",
"label": "t:settings_schema.cart.settings.add_to_cart_behavior.go_to_cart.label"
}
],
"options": [
{
"value": "go_to_cart",
"label": "t:settings_schema.cart.settings.add_to_cart_behavior.go_to_cart.label"
},
{
"value": "cart_notification",
"label": "t:settings_schema.cart.settings.add_to_cart_behavior.cart_notification.label"
}
],

I would like to order the options alphabetically please! 🙏

"default": "cart_notification",
"label": "t:settings_schema.cart.settings.add_to_cart_behavior.label"
}
]
}
]
14 changes: 14 additions & 0 deletions locales/cs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Zobrazuje se v případě, že jsou povoleny návrhy produktů."
}
}
},
"cart": {
"name": "Košík",
"settings": {
"add_to_cart_behavior": {
"label": "Typ košíku",
"go_to_cart": {
"label": "Stránka"
},
"cart_notification": {
"label": "Oznámení ve vyskakovacím okně"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/da.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Synlig når produktforslag aktiveret."
}
}
},
"cart": {
"name": "Indkøbskurv",
"settings": {
"add_to_cart_behavior": {
"label": "Indkøbskurvtype",
"go_to_cart": {
"label": "Side"
},
"cart_notification": {
"label": "Pop op-meddelelse"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/de.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Sichtbar, wenn Produktvorschläge aktiviert sind."
}
}
},
"cart": {
"name": "Warenkorb",
"settings": {
"add_to_cart_behavior": {
"label": "Warenkorbstil",
"go_to_cart": {
"label": "Seite"
},
"cart_notification": {
"label": "Pop-up-Benachrichtigung"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/en.default.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
}
}
}
},
"cart": {
"name": "Cart",
"settings": {
"add_to_cart_behavior": {
"label": "Cart type",
"go_to_cart": {
"label": "Page"
},
"cart_notification": {
"label": "Popup notification"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/es.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Visible cuando las sugerencias de productos están activadas."
}
}
},
"cart": {
"name": "Carrito",
"settings": {
"add_to_cart_behavior": {
"label": "Tipo de carrito",
"go_to_cart": {
"label": "Página"
},
"cart_notification": {
"label": "Notificación emergente"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/fi.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Näkyy, kun tuote-ehdotukset ovat käytössä."
}
}
},
"cart": {
"name": "Ostoskori",
"settings": {
"add_to_cart_behavior": {
"label": "Ostoskorin tyyppi",
"go_to_cart": {
"label": "Sivu"
},
"cart_notification": {
"label": "Ponnahdusikkunailmoitukset"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/fr.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Visible lorsque les suggestions de produits sont activées."
}
}
},
"cart": {
"name": "Panier",
"settings": {
"add_to_cart_behavior": {
"label": "Type de panier",
"go_to_cart": {
"label": "Page"
},
"cart_notification": {
"label": "Notification pop-up"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/it.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Visibile quando i suggerimenti sui prodotti sono abilitati."
}
}
},
"cart": {
"name": "Carrello",
"settings": {
"add_to_cart_behavior": {
"label": "Tipo di carrello",
"go_to_cart": {
"label": "Pagina"
},
"cart_notification": {
"label": "Notifica pop up"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/ja.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "商品のおすすめが有効な場合に表示されます。"
}
}
},
"cart": {
"name": "カート",
"settings": {
"add_to_cart_behavior": {
"label": "カートタイプ",
"go_to_cart": {
"label": "ページ"
},
"cart_notification": {
"label": "ポップアップ通知"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/ko.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "제품 제안이 활성화되면 표시됩니다."
}
}
},
"cart": {
"name": "카트",
"settings": {
"add_to_cart_behavior": {
"label": "카트 유형",
"go_to_cart": {
"label": "페이지"
},
"cart_notification": {
"label": "팝업 알림"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/nb.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Synlig når produktforslag er aktivert."
}
}
},
"cart": {
"name": "Handlekurv",
"settings": {
"add_to_cart_behavior": {
"label": "Handlekurvtype",
"go_to_cart": {
"label": "Side"
},
"cart_notification": {
"label": "Popup-varsel"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/nl.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Zichtbaar als productsuggesties zijn ingeschakeld."
}
}
},
"cart": {
"name": "Winkelwagen",
"settings": {
"add_to_cart_behavior": {
"label": "Type winkelwagen",
"go_to_cart": {
"label": "Pagina"
},
"cart_notification": {
"label": "Pop-upmelding"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/pl.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Widoczne w przypadku włączenia propozycji dotyczących produktu."
}
}
},
"cart": {
"name": "Koszyk",
"settings": {
"add_to_cart_behavior": {
"label": "Typ koszyka",
"go_to_cart": {
"label": "Strona"
},
"cart_notification": {
"label": "Powiadomienie w wyskakującym okienku"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/pt-BR.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Visível quando as sugestões de produto estão habilitadas."
}
}
},
"cart": {
"name": "Carrinho",
"settings": {
"add_to_cart_behavior": {
"label": "Tipo de carrinho",
"go_to_cart": {
"label": "Página"
},
"cart_notification": {
"label": "Notificação pop-up"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/pt-PT.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Visível quando as sugestões de produto estão ativas."
}
}
},
"cart": {
"name": "Carrinho",
"settings": {
"add_to_cart_behavior": {
"label": "Tipo de carrinho",
"go_to_cart": {
"label": "Página"
},
"cart_notification": {
"label": "Notificação pop-up"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/sv.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "Synlig när produktförslag är aktiverat."
}
}
},
"cart": {
"name": "Varukorg",
"settings": {
"add_to_cart_behavior": {
"label": "Varukorgstyp",
"go_to_cart": {
"label": "Sida"
},
"cart_notification": {
"label": "Popup-avisering"
}
}
}
}
},
"sections": {
Expand Down
14 changes: 14 additions & 0 deletions locales/th.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,20 @@
"info": "จะปรากฏให้เห็นเมื่อเปิดใช้คำแนะนำสินค้า"
}
}
},
"cart": {
"name": "ตะกร้าสินค้า",
"settings": {
"add_to_cart_behavior": {
"label": "ประเภทตะกร้าสินค้า",
"go_to_cart": {
"label": "หน้า"
},
"cart_notification": {
"label": "การแจ้งเตือนแบบป๊อปอัพ"
}
}
}
}
},
"sections": {
Expand Down
Loading