0 レビュー
4 回答
php-Magento-同じカテゴリ内の2つのifステートメント
カテゴリ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>
わからない
0
レビュー
答え :
解決策:
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,
わからない
0
レビュー
答え :
解決策:
$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 } ?>
これがお役に立てば幸いです
わからない
0
レビュー
答え :
解決策:
これを試してください
<?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 } ?>
わからない
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;?>
ご意見ありがとうございます。みんなのコードの断片を組み合わせて結果を出すことができました。
乾杯:)
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。