所有Addtional属性分组产品在Magento [英] All Addtional Attributes for Grouped Products in Magento

查看:294
本文介绍了所有Addtional属性分组产品在Magento的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类似在问的问题:
<一href=\"http://stackoverflow.com/questions/1005394/magento-show-custom-attributes-in-grouped-product-table\">http://stackoverflow.com/questions/1005394/magento-show-custom-attributes-in-grouped-product-table

我想在组合产品页面显示简单的产品属性。<​​/ P>

不过,我需要它的工作,这样你没有明确指定显示得到哪些属性。相反,它会显示所有会得到显示在该产品的简单的产品视图属性。

我试过的变化:

(从/template/catalog/product/view/type/grouped.phtml)

<?pre> &LT; PHP的foreach($ _associatedProducts为$ _item):GT;?
  &所述; TR&GT;
            &LT; TD&GT;&LT; PHP的echo $这个 - &GT; htmlEscape($ _本期特价货品&GT;的getName())&GT;&LT; / TD&GT;   &LT;! - 重大问题的一部分 - &GT;
   ?&LT; PHP的foreach($ _item-&GT;的getAttributes()为$ ARR):&GT;
    &LT; TD&GT;&LT; PHP的echo $ arr-&GT;的getData()&GT;&LT; / TD&GT;
   &LT; PHP endforeach; ?&GT;
   &LT;! - 问题部分的结束 - &GT;            &LT; TD类=一个右派&GT;
                &LT;?PHP的echo $这个 - &GT; getPriceHtml($ _项目,真)GT?;
            &LT; / TD&GT;
            ?&LT; PHP的如果($ _product-&GT; isSaleable()):&GT;
            &LT; TD类=一个中心&GT;
            ?&LT; PHP的如果($ _item-&GT; isSaleable()):&GT;
    &LT; A HREF =&LT; PHP的echo $ _item-&GT; getUrlPath()&GT;&gt;查看&LT; / A&GT;
            &LT;其他的PHP:?&GT;
                &LT; p类=可用性&GT;&LT;跨度类=外的股票&GT;&LT; PHP的echo $这个 - &GT;('缺货')__&GT;&LT; / SPAN&GT ;&所述; / p&GT;
            &LT; PHP ENDIF; ?&GT;
            &LT; / TD&GT;
            &LT; PHP ENDIF; ?&GT;
        &LT; / TR&GT;
    &LT; PHP endforeach; ?&GT;

和其他的变化,但是,我不能限制属性显示只是我需要的那些(即只是在简单的产品视图中显示的附加属性,这些设置为可视的前端)。有任何想法吗?先谢谢了。


解决方案

添加后 $ _产品= $这个 - &GT; getProduct();

  / * code至获取属性* /
$ gridattributes =阵列();
$属性= $ _product-&GT;的getAttributes();
的foreach($属性为$属性){
  如果($属性 - &GT; getIsVisibleOnFront()及和放大器;!in_array($属性 - &GT;的getAttribute code(),$ excludeAttr)){
    $值= $属性 - &GT; getFrontend() - GT;的getValue($ _产品);
    如果($ _产品展示&GT;!hasData($属性 - &GT;的getAttribute code())){
      $值=法师::助手('目录') - GT; __('N / A');
    } ELSEIF((字符串)$价值==''){
      $值=法师::助手('目录') - GT; __('无');
    } ELSEIF($属性 - &GT; getFrontendInput()=='价格'和;&安培; IS_STRING($值)){
      $值=法师::应用() - GT; getStore() - GT; convertPrice($价值,真实);
    }    如果(IS_STRING($值)及&放大器; strlen的($值)){
      $ gridattributes [$属性 - &GT;的getAttribute code()] =阵列(
        标签= GT; $属性 - &GT; getStoreLabel(),
        '值'=&GT; $值,
        code'=&GT; $属性 - &GT;的getAttribute code()
      );
    }
  }
}
?&GT;

添加后百分位&GT;&LT; PHP的echo $这个 - &GT; __('商品名称')&GT;&LT; /次&GT;

 的foreach($ gridattributes为$ ATTRIB){
    呼应'&LT;第i'$这个 - 方式&gt; htmlEscape($ ATTRIB [标签])。'&LT; /第i';
}

添加后&LT; TD&GT;&LT; PHP的echo $这个 - &GT; htmlEscape($ _本期特价货品&GT;的getName())&GT;&LT; / TD&GT;

 的foreach($ gridattributes为$ ATTRIBNAME =&GT; $ attribval​​){
    呼应'&LT; TD&GT;'$这个 - 方式&gt; htmlEscape($ _本期特价货品&GT;的getData($ ATTRIBNAME))。'&LT; / TD&GT;';
}

Similar to the question asked at: http://stackoverflow.com/questions/1005394/magento-show-custom-attributes-in-grouped-product-table

I'd like to display attributes of simple products in the grouped product page.

However, I need it to work such that you do not explicitly specify which attributes get displayed. Instead, it displays all the attributes that would get displayed on the simple product view of that product.

I've tried variations of:

(from /template/catalog/product/view/type/grouped.phtml)

<?php foreach ($_associatedProducts as $_item): ?>
  <tr>
            <td><?php echo $this->htmlEscape($_item->getName()) ?></td>

   <!-- important problem part -->
   <?php foreach ($_item->getAttributes() as $arr): ?>
    <td><?php echo $arr->getData() ?></td>
   <?php endforeach; ?>
   <!-- end of problem part -->

            <td class="a-right">
                <?php echo $this->getPriceHtml($_item, true) ?>
            </td>
            <?php if ($_product->isSaleable()): ?>
            <td class="a-center">
            <?php if ($_item->isSaleable()) : ?>
    <a href="<?php echo $_item->getUrlPath() ?>">View</a>
            <?php else: ?>
                <p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock.') ?></span></p>
            <?php endif; ?>
            </td>
            <?php endif; ?>
        </tr>
    <?php endforeach; ?>

And other variations, however, I cannot limit the attributes being displayed to just the ones I need (i.e. just the additional attributes displayed on the simple product view; those set as Viewable on Frontend). Any ideas? Thanks in advance.

解决方案

Add after $_product = $this->getProduct();

/* CODE TO GET ATTRIBUTES */
$gridattributes = array();
$attributes = $_product->getAttributes();
foreach ($attributes as $attribute) {
  if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
    $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)) {
      $gridattributes[$attribute->getAttributeCode()] = array(
        'label' => $attribute->getStoreLabel(),
        'value' => $value,
        'code'  => $attribute->getAttributeCode()
      );
    }
  }
}
?>

Add after <th><?php echo $this->__('Product Name') ?></th>:

foreach($gridattributes as $attrib){
    echo '<th>'.$this->htmlEscape($attrib[label]).'</th>';
}

Add after <td><?php echo $this->htmlEscape($_item->getName()) ?></td>:

foreach($gridattributes as $attribname=>$attribval){
    echo '<td>'.$this->htmlEscape($_item->getData($attribname)).'</td>';
}

这篇关于所有Addtional属性分组产品在Magento的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆