限制包含特定类别的产品的购物车数量
Limit cart quantity of products that contain a specific category
如果属于特定类别 ID 的产品数量大于 3,我想显示一条消息。
这是我目前的情况,如果产品包含类别 ID,可以设置和 "if" 声明?
<?php
$session= Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllItems();
$class2 = "hide";
$count = 0;
foreach ($items as $item) {
$categories = $item->getProduct()->getCategoryIds();
foreach ($categories as $categoryId){
if($categoryId == 125) $count++;
}
if($count > 3) $class2 = "show";
}
?>
<div class="<?php echo $class2; ?> warning">
<p style="margin:0;" class="red">Flash Sale Quantity Is Limited To 3</p>
</div>
可能类似这样的方法可以解决问题...第一步是找到类别 ID,然后在 if 语句中开始计数,如果 $count
是 >3
,则 $class2
将是 "show"
;
<?php
$session= Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllItems();
$class2 = "hide";
$count = 0;
foreach ($items as $item) {
$categories = $item->getProduct()->getCategoryIds();
foreach ($categories as $categoryId){
if($categoryId == 125) {
if($count > 3) { $class2 = "show" }
$count = $count + 1;
}
}
}
?>
<div class="<?php echo $class2; ?> warning">
<p style="margin:0;" class="red">Flash Sale Quantity Is Limited To 3</p>
</div>
如果属于特定类别 ID 的产品数量大于 3,我想显示一条消息。
这是我目前的情况,如果产品包含类别 ID,可以设置和 "if" 声明?
<?php
$session= Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllItems();
$class2 = "hide";
$count = 0;
foreach ($items as $item) {
$categories = $item->getProduct()->getCategoryIds();
foreach ($categories as $categoryId){
if($categoryId == 125) $count++;
}
if($count > 3) $class2 = "show";
}
?>
<div class="<?php echo $class2; ?> warning">
<p style="margin:0;" class="red">Flash Sale Quantity Is Limited To 3</p>
</div>
可能类似这样的方法可以解决问题...第一步是找到类别 ID,然后在 if 语句中开始计数,如果 $count
是 >3
,则 $class2
将是 "show"
;
<?php
$session= Mage::getSingleton('checkout/session');
$items = $session->getQuote()->getAllItems();
$class2 = "hide";
$count = 0;
foreach ($items as $item) {
$categories = $item->getProduct()->getCategoryIds();
foreach ($categories as $categoryId){
if($categoryId == 125) {
if($count > 3) { $class2 = "show" }
$count = $count + 1;
}
}
}
?>
<div class="<?php echo $class2; ?> warning">
<p style="margin:0;" class="red">Flash Sale Quantity Is Limited To 3</p>
</div>