简体   繁体   English

如何通过cms块magento在产品页面上添加产品属性

[英]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. 一个cms页面,其内容显示在产品页面上。 (by calling the cms block in the template phtml file) (通过调用模板phtml文件中的cms块)

I do not want to touch the product page phtml file, so that I can keep my template upgrade safe (I bought the template) 我不想触摸产品页面的phtml文件,以便我可以安全地进行模板升级(我购买了模板)

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. 除了要显示在具有其他属性的部分中的sku之外,我还想在产品页面中显示产品的sku号,这是默认设置。

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. 由于模板已经提供了cms块,使内容出现在产品价格附近(这是我希望sku出现的位置),所以我想通过在cms中调用phtml文件来尝试在sms块中获取sku块。

I have created a phtml file as follows: 我创建了一个phtml文件,如下所示:

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

And I have placed the following code therein (this supposedly gets the product sku): 并且我在其中放置了以下代码(这应该得到产品sku):

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

And I have placed the following in the cms block (calls the phtml file): 并且我在cms块中放置了以下内容(称为phtml文件):

{{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 我在这里找到了答案: 在magento的CMS块中调用属性

It involved getting the product model on the phtml page first by using the following: 它涉及到首先使用以下方法在phtml页面上获得产品模型:

<?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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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