我正在尝试使用像Color,Delivery_Time ...
在magento中显示一些自定义属性我可以通过以下方式调用某些属性:
<?php echo $item->getName();?>
<?php echo $item->getWeight();?>
但我无法调用大部分属性。我也试过了:
<?php echo $this->htmlEscape($item->getData('luftkammern'));?>
<?php echo $item->getAttributeText('spannung'); ?>
没有任何作用!!
属性代码:
<?php
$_helper = $this->helper('catalog/output');
$_product = $this->getProduct()
?>
<?php if($_additional = $this->getAdditionalData()): ?>
<h2><?php echo $this->__('Additional Information') ?></h2>
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product,$_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('product-attribute-specs-table')</script>
<?php endif;?>
代码
echo $ this-&gt; __('附加信息');?&gt;
<table class="data-table" id="product-attribute-specs-table">
<col width="25%" />
<col />
<tbody>
<?php foreach ($_additional as $_data): ?>
<tr>
<th class="label"><?php echo $this->htmlEscape($this->__($_data['label'])) ?></th>
<td class="data"><?php echo $_helper->productAttribute($_product, $_data['value'], $_data['code']) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
任何人都可以帮忙吗?
答案 0 :(得分:1)
如果您需要在结帐页面中获取这些属性,可以这样做:
$_product = $item->getProduct();
$pid = $_product->getId();
$product = Mage::getModel('catalog/product')->load($pid);
/* getting some attributes */
$color = $product->getData('color');
$manufacturer = $product->getData('manufacturer');
$delivery_date = $product->getData('delivery_date');
....
希望它会对你有所帮助。
答案 1 :(得分:0)
您可以通过调用正确的get函数从产品中获取属性。
例如,要接收颜色,请使用:
echo $item->getColor();
要接收制造商,请使用:
echo $item->getManufacturer();
此外,您必须确保您的产品已满载。试试这个:
print_r($item->getData());
答案 2 :(得分:0)
请检查以下代码:
$attributes = $product->getAttributes();
$additional_data = array();
foreach ($attributes as $attribute) {
if ($attribute->getIsVisibleOnFront() && $attribute->getIsUserDefined()) {
$value = $attribute->getFrontend()->getValue($product);
if (!$product->hasData($attribute->getAttributeCode())) {
$value = Mage::helper('catalog')->__('N/A');
} elseif ((string)$value == '') {
$value = Mage::helper('catalog')->__('No');
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
$value = Mage::app()->getStore()->convertPrice($value, true);
}
if (is_string($value) && strlen($value)) {
$additional_data[$attribute->getAttributeCode()] = array(
'label' => $attribute->getStoreLabel(),
'value' => $value,
'code' => $attribute->getAttributeCode()
);
}
}
}
/* Your code here */
<h2><?php echo $this->__('Additional Information') ?></h2>
...
<?php foreach ($additional_data as $_data): ?>
...