简体   繁体   中英

How to add product attribute on product page via cms block magento

I have the following setup:

A cms page, the contents of which are showing on the product page. (by calling the cms block in the template phtml file)

I do not want to touch the product page phtml file, so that I can keep my template upgrade safe (I bought the template)

I want to show the product sku number inside the product page in addition to the sku appearing in the section with the other attributes, which is the default.

Since the template already provides the cms block to have content appear near the product pricing, (which is where i want the sku to appear) I figured I'll try to get the sku within a cms block by calling a phtml file inside the cms block.

I have created a phtml file as follows:

app/design/frontend/default/mytheme/template/page/getSku.phtml

And I have placed the following code therein (this supposedly gets the product sku):

<?php
    //get product sku
    echo $_product->getAttributeText('sku');
?>

And I have placed the following in the cms block (calls the phtml file):

{{block type="core/template" template="page/getSuk.phtml"}}

Error: My page is not showing completely, (it seems the page doesn't get fully rendered.)

Thank you.

I found the answer here: Calling an attribute in a CMS block in magento

It involved getting the product model on the phtml page first by using the following:

<?php       
   $_prodID = Mage::registry('current_product')->getId();
   $_product = Mage::getModel('catalog/product')->load($_prodID );
?>

Only then can you access the attributes as follows:

echo $_product->getData('sku')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM