2
<action method="addTab" translate="title" module="catalog" ><alias>upsell_tabbed</alias><title>additional products</title><block>catalog/product_list_upsell</block><template>catalog/product/list/upsell.phtml</template></action>
  • i have created a custom tab on product detail page and load all upsell
    products of current product in that tab.

  • but now i want that tab will display only when there is any product otherwise it should not display on the product page.

    any help would be appreciated. thanx.

2 Answers 2

0
  • Find and open the tabs.phtml file. you can find it here:
  • app/design/frontend/[YOUR PACKAGE]/[YOUR THEME]/template/catalog/product/view/tabs.phtml

Now get the total number of upsell products for the current product

$product_id = Mage::registry("current_product")->getId();
$_product = $object->load($product_id);
$upsell_count = count($_product->getUpSellProductIds());

NOW FIND THIS LINES OF CODE

<?php foreach ($this->getTabs() as $_index => $_tab): ?>
            <?php if($this->getChildHtml($_tab['alias'])): ?>
                <li id="tab_<?php echo $_tab['alias'] ?>" class="<?php echo ($i==0)?' active first':''?>"><a href="#"><?php echo $_tab['title']?></a></li>
            <?php endif; ?>
        <?php endforeach; ?>

AND REPLACE IT WITH THIS CODE

<?php foreach ($this->getTabs() as $_index => $_tab): ?>
            <?php if($this->getChildHtml($_tab['alias'])):
                if($_tab['alias'] == 'youe_newly_created_tab_id' && ($upsell_count > 0))
                { ?>
                        <li id="tab_<?php echo $_tab['alias'] ?>" class="<?php echo ($i==0)?' active first':''?>"><a href="#"><?php echo $_tab['title']?></a></li>
        <?php   }           
                elseif($_tab['alias'] == 'youe_newly_created_tab_id' && ($upsell_count == 0))
                {
                        echo "";                      
                }
                else
                {  ?>                   
                        <li id="tab_<?php echo $_tab['alias'] ?>" class="<?php echo ($i==0)?' active first':''?>"><a href="#"><?php echo $_tab['title']?></a></li>
        <?php   }              

                 $i++; ?>
            <?php endif; ?>
        <?php endforeach; ?>

AFTER REPLACING CODE IT WILL HIDE YOUR TAB IF UPSELL PRODUCTS IS NOT THERE

enter image description here

AND FOR TAB CONTENT (BELOW TAB TITLE) APPLY SAME CODITIONS WHERE TAB CONTENT ARE CREATED

enter image description here

NOTE: i know this is not a proper solution but it solved my issue

-2

Find and open the attributes.phtml file. This file can be found here: /app/design/frontend/[YOUR PACKAGE]/[YOUR THEME]/template/catalog/product/view/attribute.phtml

Open the file and search for the following lines:

<?php foreach ($_additional as $_data): ?>
    <tr>
        <th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
    </tr>
<?php endforeach; ?>

Replace the entire foreach loop with the following lines of code:

<?php foreach ($_additional as $_data): ?> 
    <?php if ((string)$_data['value'] != '' and $_data['value'] != 'N/A' and $_data['value'] != 'No'): ?>
    <tr>
        <th class="label" style="width:25%;"><?php echo $this->escapeHtml($this->__($_data['label'])) ?></th>
        <td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td><?php }?>
    </tr>
    <?php endif; ?>
<?php endforeach; ?>
1
  • I think this answer has nothing to do with the question. The question is related to custom(upsell products) tab and your code is related to additional info tab.
    – John
    Commented May 22, 2017 at 10:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.