0

我创建了以下内容,以允许根据类别 ID 在产品页面上显示不同的静态 CMS 块。

<?php 
    $_category_detail=Mage::registry('current_category'); //Get the current category id
    $product = Mage::getModel('catalog/product')->load($product_id);   //Get the current category id
    $category = Mage::getModel('catalog/layer')->getCurrentCategory(); //Get the current category id
    ?>
<?php if($category->getId()==23): ?>
    <div id="sizingmap">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsslim')->toHtml(); ?>
    </div>
<?php endif;?>  

<?php if($category->getId()==10): ?>
    <div id="sizingmap">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecjacket')->toHtml(); ?>
    </div>
<?php endif;?>

类别部分的一切都很好,尽管我想根据同一类别中的产品 ID 显示不同的块。

例如(这显然是不正确的):

<?php if($category->getId()==23) "AND the product id are "372,363,354,349,344": ?>
<div id="sizingmap">
    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsslim')->toHtml(); ?>
</div>
else // if they are not the mentioned product id's 
<div id="sizingmap">
    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsstd')->toHtml(); ?>
</div> 
4

4 回答 4

2
Try is this not tested.

<?php $productIDarray = array("372","363","354","349","344")?>
<?php if($category->getId()==23 && in_array($productIDarray , $productId)): ?>

<div id="sizingmap">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsslim')->toHtml(); ?>
</div>
<?php else:?>
<div id="sizingmap">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsstd')->toHtml(); ?>
</div> 
<?php endif;?>


Thanks,
于 2013-06-27T07:25:10.413 回答
1

尝试这个

<?php 
$id_array = array(372,363,354,349,344); //product ids
if(($category->getId()==23) && in_array($product_id,$id_array)){ ?>
    <div id="sizingmap">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsslim')->toHtml(); ?>
    </div>

<?php }else{ ?>

<?php if($category->getId()==10): ?>
    <div id="sizingmap">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecjacket')->toHtml(); ?>
    </div>
<?php endif;?>
<?php } ?>
于 2013-06-27T07:26:56.970 回答
1
$id_array = array(372,363,354,349,344); 
<?php if(($category->getId()==23) && in_array($product_id,$id_array){ ?>
    <div id="sizingmap">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsslim')->toHtml(); 
}else{

?>
    </div>    
<?php if($category->getId()==10): ?>
    <div id="sizingmap">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecjacket')->toHtml(); ?>
    </div>
<?php endif;?>
<?php } ?>

希望这可以帮助

于 2013-06-27T08:06:46.013 回答
0
<?php 
    $_category_detail=Mage::registry('current_category'); //Get the current category
    $product = Mage::registry('current_product'); // Get the current product
    $productId = $this->getProduct()->getId(); // Get the current product ID
    $category = Mage::getModel('catalog/layer')->getCurrentCategory(); //Get the current category id
    ?>
<!-- standard pants - sizing chart -->
<?php if(in_array($this->getProduct()->getId(), array(372,363,354,349,344))): ?>
<div id="sizingmap">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsstd')->toHtml(); ?>
</div>
<?php endif;?>
<!-- slim pants - sizing chart -->
<?php if(in_array($this->getProduct()->getId(), array(339,334,329,324,319,314))): ?>
<div id="sizingmap">
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecpantsslim')->toHtml(); ?>
</div>
<?php endif;?>
<!-- jackets - sizing chart -->
<?php if($category->getId()==10): ?>
    <div id="sizingmap">
        <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('sizespecjacket')->toHtml(); ?>
    </div>
<?php endif;?>

谢谢你们的投入,我能够通过将每个人的代码的点点滴滴放在一起来产生结果。

干杯:)

于 2013-06-28T02:01:09.453 回答