1

I succeeded to got all the comparable attributes by the following code:

$_attributes = Mage::getResourceModel('catalog/product_attribute_collection');
$_attributes->addFieldToFilter('additional_table.is_comparable', array('1'));

But I can't call these attributes from the up-sell products when I'm trying:

<?php echo $this->helper('catalog/output')->productAttribute($_link, $this->getProductAttributeValue($_link, $_attribute), $_attribute->getAttributeCode()) ?>
  • No? Can somebody help me? – Demi_Cogni Jan 12 '18 at 21:32
2

Not quite sure what you're trying to achieve, but that could work for you:

<?php $_attributes = Mage::getResourceModel('catalog/product_attribute_collection'); ?>
<?php $_attributes->addFieldToFilter('additional_table.is_comparable', array('1')); ?>
<?php $attributeCodes = array(); ?>
<?php foreach($_attributes as $_attribute): ?>
    <?php $attributeCodes[] = $_attribute->getData('attribute_code'); ?>
<?php enforeach; ?>
<ul>
<?php foreach ($this->getItemCollection()->getItems() as $_link): ?>
    <li>
        <h3 class="product-name"><a href="<?php echo $_link->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_link->getName()) ?>"><?php echo $this->escapeHtml($_link->getName()) ?></a></h3>
        <ul>
            <?php foreach($attributeCodes as $attributeCode): ?>
                <li>
                    <?php echo ($_link->getData($attributeCode)); ?>
                </li>
            <?php enforeach; ?>
        </ul>
        <!-- ... -->
    </li>
<?php enforeach; ?>
</ul>

-- where $attributeCodes will hold an array of comparable attribute codes which you then can re-use inside the upsell-item's foreach. However, you should really overthink whether you want to put a foreach inside another since this may have some noticeable performance impact on larger upsell-lists and many comparable attributes...

  • I'm trying to show comparable attributes in the up-sell block on the product page. – Demi_Cogni Jan 12 '18 at 23:04
  • I changed my code to: <?php echo $this->helper('catalog/output')->productAttribute($_link, $_attribute->getFrontend()->getValue($_link), $_attribute->getAttributeCode()); echo $_attribute->getAttributeCode(); ?> And now the attributes are shown but only ones with "Used in Product Listing" activated. – Demi_Cogni Jan 12 '18 at 23:05
  • @Demi_Cogni You may post a bit bigger snippet as an answer if that was what solved it for you – Christoph Farnleitner Jan 12 '18 at 23:08
2

My solution

    <?php $_attributes = Mage::getResourceModel('catalog/product_attribute_collection');
$_attributes->addFieldToFilter('additional_table.is_comparable', array('1')); ?>
<?php if ($_link = $this->getIterableItem()): ?>
    <li>
        <a href="<?php echo $_link->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_link->getName()) ?>"
           class="product-image"><img
                    src="<?php echo $this->helper('catalog/image')->init($_link, 'small_image')->resize(125) ?>"
                    width="125" height="125" alt="<?php echo $this->escapeHtml($_link->getName()) ?>"/></a>
        <h3 class="product-name"><a href="<?php echo $_link->getProductUrl() ?>"
                                    title="<?php echo $this->escapeHtml($_link->getName()) ?>"><?php echo $this->escapeHtml($_link->getName()) ?></a>
        </h3>
        <?php echo $this->getPriceHtml($_link, true, '-upsell') ?>
        <div class="std">
            <?php foreach ($_attributes as $_attribute): ?>
                <div>
                    <span class="std"><?php echo $this->helper('catalog/output')->productAttribute($_link, $_attribute->getFrontend()->getValue($_link), $_attribute->getAttributeCode());
                        echo $_attribute->getAttributeCode(); ?></span></div>
            <?php endforeach; ?>
        </div>
    </li>
<?php else: ?>
    <li class="empty"></li>
<?php endif; ?>

And set "Used in Product Listing" to Yes in Admin -> Catalog -> Attributes -> Manage Attributes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.