你的问题有几个问题:
保存购物车中项目的数组{$products}
仅在购物车和结帐页面上可用。您不能在其他页面上使用它,因为它不存在。
首先检查特定商品是否在购物车中的方式是错误的。如果您在购物车中有 5 个没有id=3065
.
所以,让我们找到一个解决方案。由于您需要在每个页面上检查一个产品是否在购物车中(以隐藏结帐链接),因此您需要创建检查项目是否存在的 PHP 脚本。我们将设置全局 smarty 变量is_product_in_cart
,您可以在 TPL 文件中的任何位置使用它。我们要更改的 xcart 核心文件home.php
位于根目录下,我们将在显示模板之前添加代码(在结束之前func_display('customer/home.tpl', $smarty);
):
/* academyprohair.com custom code */
$my_products = func_products_in_cart($cart);
$is_product_in_cart = 'N';
foreach( $my_products as $product ) {
if ( $product['productid']==3065 ) {
$is_product_in_cart = 'Y';
break;
};
};
$smarty->assign('is_product_in_cart', $is_product_in_cart);
在您的模板中,除了购物车和结帐页面之外的任何地方,您都可以通过以下方式轻松显示购物车链接:
{if $is_product_in_cart neq 'Y' }
<a href="http://academyprohair.com/cart.php" style="margin-top:5px;"><img src="{$AltImagesDir}/button_checkout.jpg" alt="" /></a>
{/if}