[英]Check if product is in cart - Prestashop 1.7.4.2
I'm facing a problem with prestashop 1.7.4.2
. 我遇到了prestashop
1.7.4.2
的问题。 I want to check if certain product ID is in cart before to allow customer proceeds checkout. 我想先检查购物车中是否有某些产品ID,才能允许客户进行结帐。 If not, I want to display an alert.
如果没有,我想显示一个警报。
In 1.6
, I could achieve this with : 在
1.6
,我可以使用以下方法实现此目的:
{if !Context::getContext()->cart->containsProduct(784)}
message
{/if}
It doesn't work in 1.7.4.2
... 在
1.7.4.2
中1.7.4.2
...
Any help will be greatly appreciated ! 任何帮助将不胜感激 ! Thanks a lot & cheers !
非常感谢和欢呼!
Camille. 卡米尔
You can loop all products in $cart var : 您可以在$ cart var中循环所有产品:
{assign var="inCart" value=false}
{assign var="idProduct" value=YOUR_PRODUCT_ID}
{foreach from=$cart.products item=product}
{if $product.id_product == $idProduct}
{assign var="inCart" value=true}
{/if}
{/foreach}
{if $inCart == true}
idProduct is cart !
{/if}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.