3

I have 4 attributes inside my Magento for two of my products. In order to make jquery tabs on product page with attributes values, I need to seperate thoose values in phtml files.

Is there a way to retreive attributes value for a specific product inside newly created phtml file?

3

The simplest way to do this would be to create blocks that use the Catalog Product View block code, which grabs the product out of the registry. Here's an example:

[yourtheme]/layout/local.xml
<catalog_product_view>
    <reference name="product.info"> <!-- the name of the main product view from catalog.xml -->
        <block type="catalog/product_view" name="product.tab.mytab1" template="path/to/tab.phtml"/>
    </reference>
</catalog_product_view>

[yourtheme]/template/path/to/tab.phtml
<?php $_product = $this->getProduct(); ?>
<!-- Access whatever product property you need here -->
<?php echo $_product->getDescription() ?>

You can then just include the tab on your product view (inside your local catalog/product/view.phtml) with <?php echo $this->getChildHtml('product.tab.mytab1') ?> or whatever you choose to alias it as.

| improve this answer | |
0

You can retrieve attribute text on product view page:

$_product->getAttributeText('brand');// brand attribute input type is drop-down
$_product->getData('manufacturer');//manufacturer attribute type is text or textarea

And attributes which you want to output on product listing or product view page should be following options accordingly (see attribute edit page):

"Used in Product Listing" -> "Yes"
"Visible on Product View Page on Front-end" -> "Yes"
| improve this answer | |
-2

Is this what you mean?

$quote  = $this->getQuote();
$quoteItems = $quote->getAllItems();

// iterate through all items in the order
foreach ($quoteItems as $item) {
    $myAttribute = Mage::getModel('catalog/product')->load($item->getProduct()->getId())->getAttributeText('my_attribute');
    // check the attribute
    if ( ($myAttribute != 'sexy') ) {
        Mage::throwException(Mage::helper('checkout')->__('Sorry, it is not sexy.'));
    }
}

Hope it helps :)

| improve this answer | |
  • This is definitely wrong. – user487772 May 29 '13 at 19:37
  • Why is this 'definitely wrong'? – Jongosi May 30 '13 at 8:20
  • 1
    Your answer is wrong. The question is about the product display in the catalog. It has nothing to do with the quote. – Marius May 30 '13 at 8:43
  • Oh right. Soz, I misunderstood then. – Jongosi May 30 '13 at 8:56
  • @Marius I declined your flag because even wrong answer has a right to live as long as it is not violating any rules. – user487772 May 30 '13 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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