Magento – Add product custom content as a tab in product details

Picture

We wanted a store in the product description below to the already existing Tabs as “Description“, “Additional Information“, “Upselling” etc.. another other tab add, to display more information by product attribute can. In this particular case involved the addition of a “FAQ” Rider. In the article itself, it should then Attribute give, which is being maintained, then there appears to be down to.

First, we have this one faq.phtml File in the folder /app / design / frontend /[default or base]/[IhrTemplate]/template/catalog/product/view created. Thereinto then came the following code:

<?php if(count($this->getProduct()->getFaq())): ?>
<div class ="product-specs">
<?php echo $this->getProduct()->getFaq() ?>
</div>
<?php endif ?>

Then we need a faq.php in the folder app/code/local/Mage/Catalog/Block/Product/View with the following content:

<?php
class Mage_Catalog_Block_Product_View_Faq extends Mage_Core_Block_Template
{
protected $_product = null;

function getProduct()
{
if (!$this->_product) {
$this->_product = Mage::registry('product');
}
return $this->_product;
}
}

Then let's create a suitable attribute for our FAQ. For this we go in in Magento backend Catalog > Attribute > Manage attributes and then create a new attribute with the following settings:

Attribut Code: faq
Scope: (normally) StoreView
Input Type: Multi-line text field
Other settings as desired
Visible on the product page on the front-end: No (Otherwise, the attribute is also displayed in detailed information)

So, apart, that of course that attribute are now maintained in the products must, we need to make one final adjustment, to show the new tab. For this, the catalog.xml in the folder app / design / frontend /[base or default]/[IhrTemplate]/layout opened and after the line

<block type="catalog/product_view_tabs" name ="product.info.tabs" as="info_tabs" template ="catalog/product/view/tabs.phtml" >

search. Among these are the already displayed tabs specified. The sort can be adjusted freely, the first is called open directly, when you get to the page (s.a. this post).

Now at the desired location, the following row is inserted:

<action method="addTab" translate="title" module ="catalog"><alias>faq</alias><title>FAQ</title><block>catalog/product_view</block><template>catalog/product/view/faq.phtml</template></action>

Subsequently (latest after cache reload) there is then a new tab with the values ​​of the attribute.

If a tab with a static block will be incorporated, which is the same for all products, there is HERE the instruction.

Used in Magento Version 1.5.1.0 Comments? Additions? Notes? Gladly!

Supplement for Magento 1.9 and the RWD Theme

Bei Magento 1.9 in conjunction with the RWD theme a few changes set, the need to be considered.

  1. the .phtml- and .php files are created exactly as described above.
  2. However, we place (if not already present) in the used theme a local.xml and add there the following code
    <?xml version="1.0"?>
    <layout>
     <catalog_product_view>
      <reference name="product.info">
          <block type="catalog/product_view_attributes" name ="product.meintabname" as="meintabname" template ="catalog/product/view/meineangelegte.phtml">
              <action method="addToParentGroup"><group>detailed_info</group></action>
              <action method="setTitle" translate="value"><value>Meintabname</value></action>
          </block>
        </reference>
    </catalog_product_view>
    </layout>
  3. the Code, the above is inputted into the catalog.xml, we do not need.
  4. If the tab is not be displayed, it could be due to a lack of authorization block: To forget in backend (from Magento 1.9) under system > permissions > to deposit an authorization block for the block to be invoked, will only see the block, if he turns on developer mode in the backend and the paths (and possibly. Blocknamen) can show. Otherwise Magento blocks the output off easily and you look for a branch.
    Alternatively, one could have also adapted the shop so, that tabs / Attribute names are displayed, if a value is stored. Thus, in any case ensure, that the respective tab at the relevant product has really content.

Published by Covos

Since 2009 I have been working intensively with Magento. I started with the creation and operation of B2C stores. This was extended through my work in the logistics sector. This resulted first specialized B2E systems. Today I work day-a day with exciting B2C, B2B- and B2E projects and reports in this blog about challenges and give insider tips.

2 comments on “Magento – Add product custom content as a tab in product details”

  1. Super – Thank you. With a few small adjustments (e.g.. Rights for CMS Blocks) it will come our NewYorkCoffee.de Store, where we can show our financing offers in the tab.

    Thank you – and keep it 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *