1

Using 1.9.0.1 rwd

Hi, I am trying without any success to add details from a product attribute to a CMS page. Basically I want to be able to select a product (say via its id number) and the display a selected attribute from that product (say short description) and then display it in a CMS page along with what ever else is on that page. I have seen lots of ways to create and add categories such as “featured Products” but none for a individual product. The products are all simple and not configurable etc. if that makes a difference?

Any ideas on how I can achieve this? Many Thanks

1

here is the short version.
Create a template file like this.

app/design/frontend/{theme}/{package}/template/cms/product_attribute.phtml

<?php 
$id = $this->getProductId();
$attribute = $this->getProductAttribute();
if ($id && $attribute) {
   $product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($id);
    if ($product) {
        $attributeRawValue = $product->getData($attribute);
        $attributeValue = $this->helper('catalog/output')->productAttribute($product, $attributeRawValue, $attribute)
    }
    else {
        $attributeValue = '';
    }
}
echo $attributeValue;

Now you should be able to use this template inside a cms page like this.
Add this to the content of the cms page:

{{block type="core/template" template="cms/product_attribute.phtml" product_id="YOUR PRODUCT ID HERE" product_attribute="YOUR PRODUCT ATTRIBUTE CODE HERE"}}

This is the quick and dirty way of doing it. IN theory you should not use load in templates. All your logic should go in a block. But in order to have a block class you need to create a module and that take more time and more code.

I haven't tested the code so watch out for syntax errors.

|improve this answer|||||
  • Thanks Marius, but i cant get it to work. No errors it just dosnt dispaly anything in that area of the CMS Page i have put it. Not sure what to look for or what i may have done wrong.. – perpixon Dec 5 '14 at 16:36

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.