-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add an add to cart button to the product list #418
Conversation
Co-authored-by: Sharak <[email protected]>
{if $product.add_to_cart_url} | ||
<form action="{$urls.pages.cart}" method="post" class="d-flex align-items-center mt-3"> | ||
<input type="hidden" value="{$product.id_product}" name="id_product"> | ||
<input type="hidden" name="token" value="{$static_token}" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may won't for the product lists on the homepage from the cached modules, there's a need to have this done via JS to ensure the token is correct.
CC @Oksydan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, @kpodemski is right.
Block might be cached and we should make sure that token provided to request is correct @NeOMakinG.
We could simply replace static_token
value with prestashop.static_token
global variable here https://github.com/PrestaShop/PrestaShop/blob/develop/themes/_core/js/cart.js#L101 with use of https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams or regex replace (might be tricky).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Oksydan do you think it's possible to somehow manage it on the theme side?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NeOMakinG you can make some dirty tricks like:
document.querySelectorAll('[name="token"]').forEach(el => {
el.value = prestashop.static_token
})
That's major disadvantage of using core.js 😕
EDIT:
I just realized that you can ofc create you own function that will handle add to cart process but that's some extra code to maintain with core.js changes. Still no recommended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NeOMakinG you can make some dirty tricks like:
document.querySelectorAll('[name="token"]').forEach(el => { el.value = prestashop.static_token })That's major disadvantage of using core.js 😕
EDIT: I just realized that you can ofc create you own function that will handle add to cart process but that's some extra code to maintain with core.js changes. Still no recommended.
I would probably prefer that dirty tricks over changing the corejs behavior on a minor version
We need to make sure that it works for products with limited stock. If you do this on current Prestashop, have 1 item in stock and you add 2 pieces, you get empty modal. |
…ocart-product-list"" This reverts commit b0c3ec6.
product.tpl
and remove that markup