Latest News : 亮瞎双眼的那些年!

magento产品页面调用属性

Magento admin 1191 views 0 comments

 
1-自定义属性时,必须将Used in Product Listing这个选项选为:Yes
2-打开须要调用的phtml模板,如:categories page, open:app\design\frontend\default\f001\template\catalog\product\list.phtml
3-根据你定义属性的类型不同,加入不同的代码,现以Color与Yield_Oem为例,具体请看以下:

3.1-新增的属性为下拉菜单类型(Dropdown)和多项选择类型(Multiple Select)

<div class="listattribute">
   <div class="listColor"><strong><?php echo $this->__('--Color:') ?></strong><?php echo $_product->getAttributeText('color') ?></div>
   <div class="listYield"><strong><?php echo $this->__('--Yield:') ?></strong><?php echo $_product->getAttributeText('yield_oem') ?> </div> 
</div>
3.2-新增的属性为文本或文本域类型(Text Field or Text Area): 
<div class="listattribute">
   <div class="listColor"><strong><?php echo $this->__('--Color:') ?></strong><?php echo $_product->getColor() ?></div>
   <div class="listYield"><strong><?php echo $this->__('--Yield:') ?></strong><?php echo $_product->getYield_Oem() ?></div> 
</div>

3.3.你新增的属性为文本或文本域类型(Text Field or TextArea),那么你的代码应为:

< ?php echo$_product->getAttributeName()?>

 

例如,你新增了一个属性代码(Attribute Code)为 shoe_size的属性,那么你的调用代码应写成下面格式:

< ?php echo$_product->getShoeSize()?>

 

你应该把去掉下划线,并且第一字母大写,然后替代AttributeName ,如果你使用的是getshoesize() ,magento将无法工作。

定义属性调用方法二:
若上述还是调用不成功,说明该模板没有包含调用此属性 ,方法如下:

<!--pgl--><?php $_product = Mage::getModel('catalog/product')->loadByAttribute('sku', $_item->getSku()); ?>
            <div class="listYield"><strong><?php echo $this->__('--Yield:') ?></strong><?php echo $_product->getAttributeText('yield') ?> </div>
<div class="listColor"><strong><?php echo $this->__('--Color:') ?></strong><?php echo $_product->getAttributeText('color') ?>
               
                  <?php $getcolor = $_product->getAttributeText('color');?>
                  <?php if($getcolor == "C"):?>
                  <?php echo "<span style='color:#009ee0;font-size:16px;'>●</span>";?>
                  <?php elseif ($getcolor == "Y"):?>
                  <?php echo "<span style='color:#ffff00;font-size:16px;'>●</span>";?>
                  <?php elseif ($getcolor == "M"):?>
                  <?php echo "<span style='color:#e2007a;font-size:16px;'>●</span>";?>
                  <?php elseif ($getcolor == "BK"):?>
                  <?php echo "<span style='color:black;font-size:16px;'>●</span>";?>
                  <?php endif ?>
                  </div> 
                  <div class="listOem"><strong><?php echo $this->__('Model:') ?></strong><?php echo $_product->getAttributeText('oem') ?></div>
                   <!--pgl-->
以下为magento默认属性调用方法:

1-简单描述(short description):

<?php echo $this_helper(‘catalog/output’)->productAttribute($_product, nl2br($_product->getShortDescription()), ’short_description’) ?>

2-描 述(description)

<?php echo $this->helper(‘catalog/output’)->productAttribute($this->getProduct(),  nl2br($this->getProduct()->getDescription()), ‘description’)  
?>

3-产品名称(name)

<?php echo $_helper->productAttribute($_product, $this->htmlEscape($_product->getName()), ‘name’) ?>

4-产品编号(sku)

<?php echo $this->htmlEscape($_product->getSku()) ?>

5-产品价格(price)

<?php echo $_coreHelper->currency($_finalPrice,true,false) ?>


6.自定义一个TEXT文本属性调用
<?php echo $_product->getResource()->getAttribute('buyurl')->getFrontend()->getValue($_product); ?>

Please indicate: 无趣的人生也产生有意思的事件 » magento产品页面调用属性

Hi, you must log in to comment !