4

您好,我已经阅读了很多关于此的帖子,虽然它的工作原理并不完整。

例如; 属性 1 = 鞋码,属性 2 = 鞋子颜色。两者都在下拉列表中,我想在类别页面中列出每个产品的所有可能属性颜色。

问题:当我测试代码时,它只会显示第一个鞋子颜色,而不是所有可能的颜色。我在这里做错了什么?

以下是我所拥有的 3 个示例。所有代码都有效,但只显示第一个属性颜色。示例 1:

<!-- Find the following loop -->
<?php foreach ($_productCollection as $_product): ?>
<!-- Inside it insert one of the following codes as needed -->
<!-- Use this for regular text attributes -->
<?php echo $_product->getMyAttribute() ?>
<?php echo $_product->getAnotherCustomAttribute() ?>

<!-- Use this for dropdown attributes -->
<?php echo $_product->getAttributeText('shoecolor') ?>
<?php endforeach?>
<!-- ... --> 

示例 2

<?php echo $_product->getResource()->getAttribute('shoecolor')->getFrontend()->getValue($_product) ?>

示例 3

<?php $type = "simple"; $p = "0" ?> 
<?php foreach ($_productCollection as $_product): ?> 
<?php $custom = Mage::getModel('catalog/product_type_configurable')->setProduct($_product); ?> 
<?php $col = $custom->getUsedProductCollection()->addAttributeToSelect('shoecolor')->addFilterByRequiredOptions(); ?> 
<?php foreach($col as $simple_product) { $p=$simple_product->getId(); $type="configurable"; } ?> 

<?php if($type == "configurable"): ?> 
<h5><?php echo $_product->load($p)->getAttributeText('shoecolor'); ?><?php $type="simple" ?></h5> 
 <?php endif; ?> 
4

4 回答 4

14

您可以在属性编辑页面中配置它

用于产品列表 -> 是

于 2013-12-17T03:46:12.113 回答
6

另一种方式

$_product = Mage::getModel('catalog/product')->load($this->getProduct()->getId());

如果您创建像您的“鞋码”这样的属性,那么您可以通过以下代码访问。

如果您的属性类型为文本字段(应加载 $_product):

<?php
  echo $_product->getShoesize();
  // if your arribute was shoe_size then
  echo $_product->getShoeSize();
?>

如果您的属性类型为 Multiple Select 或 Dropdown,则获取所有属性值:

<?php
   echo $_product->getAttributeText('shoesize');
?>
于 2011-12-22T19:05:42.663 回答
1

这是获取不属于任何产品的属性名称和值的代码

$attributeCode = 'YOUR_ATTRIBUTE_CODE';

$product = Mage::getModel('catalog/product');

$productCollection = Mage::getResourceModel('eav/entity_attribute_collection')
   ->setEntityTypeFilter($product->getResource()->getTypeId())
   ->addFieldToFilter('attribute_code', $attributeCode);

$attribute = $productCollection->getFirstItem()->setEntity($product->getResource());
print_r($attribute->getData()); // print out the available attributes

$options = $attribute->getSource()->getAllOptions(false);
print_r($options); // print out attribute options
于 2011-12-22T18:48:08.840 回答
0

尝试这个:

$_pp2 = Mage::getModel('catalog/product')->load(    $_product->getId()    );
echo $_pp2->getdm();

在:

 <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>

属性代码:dm

Type: Text area

在 view.phtml 中

echo $_product->get>getdm(); ?>
于 2014-04-11T12:29:59.150 回答