doulang1945
2014-07-04 11:10
浏览 19
已采纳

在Magento购物车页面上显示下拉供应商属性

I'm trying to display the supplier of a product in the shopping basket.

We have a supplier attribute with a dropdown input type which is used on the default attribute set.

We have a product using the default attribute set with a supplier set in our shopping basket.

I've tried adding the below lines of code to display the supplier.

  1. <?= $this->getAttributeText('supplier') ?>
  2. <?= $_item->getAttributeText('supplier') ?>
  3. <?= $_product->getAttributeText('supplier') ?>
  4. <?php echo $_product->getAttributeText('supplier') ?>
  5. <?php echo $this->htmlEscape(_product->getAttributeText('supplier'))?>
  6. <?php echo $this->htmlEscape($this->getAttributeText('supplier'))?>

When I use $_product I get the below error.

 Fatal error: Call to a member function getAttributeText() on a non-object in /var/www/magento/app/design/frontend/mypackage/mytheme/template/checkout/cart/item/default.phtml on line 44

Here is part of my code from template/checkout/cart/item/default.phtml

<?php
$_item = $this->getItem();
$isVisibleProduct = $_item->getProduct()->isVisibleInSiteVisibility();
$canApplyMsrp = Mage::helper('catalog')->canApplyMsrp($_item->getProduct(), Mage_Catalog_Model_Product_Attribute_Source_Msrp_Type::TYPE_BEFORE_ORDER_CONFIRM);
?>
<tr>
<td class="col-img"><?php if ($this->hasProductUrl()):?><a href="<?php echo $this->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getProductName()) ?>" class="product-image"><?php endif;?><img src="<?php echo $this->getProductThumbnail()->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->resize(168); ?>" alt="<?php echo $this->htmlEscape($this->getProductName()) ?>" /><?php if ($this->hasProductUrl()):?></a><?php endif;?></td>
<td>

    <?php if ($this->hasProductUrl()):?>
        <a href="<?php echo $this->getProductUrl() ?>">
            <h1>Testing<?= $_product->getAttributeText('supplier') ?></h1>
            <h2 class="product-name"><?php echo $this->htmlEscape($this->getProductName()) ?></h2>
        </a>
    <?php else: ?>
        <?php echo $this->htmlEscape($this->getProductName()) ?>
    <?php endif; ?>
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dronthpi05943 2014-07-04 11:14
    已采纳

    Try this -

        <?php $myproduct = Mage::getModel('catalog/product')->load($_item->getProduct()->getId());
    
    echo $myproduct->getAttributeText('supplier'); ?>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题