0

I'm just working on a project of mine and I can't seem to get certain product attributes to display on the front end of the category page.

This is the current configuration for one of the custom attributes that wont work:

Attribute

I then have this block of PHP:

     <?php if($_product->isSaleable()): ?>
                            <?php  if ( !($_product->getData('has_options') || $_product->isGrouped()) ) :  ?>
                                <a href="/book-testdrive" class="addtocart" value="<?php echo $this->escapeHtml($_product->getAttributeText('registration')); ?>" title="<?php echo $this->__('Book Test Drive') ?>"><i class="glyphicon glyphicon-road"></i><span>&nbsp;<?php echo $this->__('Book Test Drive') ?></span></a>
                            <?php else : ?>
                                <a href="/book-testdrive" class="addtocart" value="<?php echo $this->escapeHtml($_product->getAttributeText('registration')); ?>" title="<?php echo $this->__('Book Test Drive') ?>"><i class="glyphicon glyphicon-road"></i><span>&nbsp;<?php echo $this->__('Book Test Drive') ?></span></a>
                                <a href='/book-testdrive' style='display:none'>Options</a>
                            <?php endif;?>
      <?php else: ?>

This is replacing the add to bag button with a <a> tag that links to another page.

As you can see I am trying to put the registration attribute within a value on the <a> tag:

value="<?php echo $this->escapeHtml($_product->getAttributeText('registration')); ?>"

However the attribute never gets placed into the value, I've also tried adding it to any part of the page and it wont display.

Any idea where I am going wrong with this?

It must be because the attribute is a custom one that I have made however I'm unsure exactly what is causing the issue.

Thanks, Nick

0

You're using the wrong function, getAttributeText isn't for text attributes

/**
 * Get attribute text by its code
 *
 * @param $attributeCode Code of the attribute
 * @return string
 */
public function getAttributeText($attributeCode)
{
    return $this->getResource()
        ->getAttribute($attributeCode)
            ->getSource()
                ->getOptionText($this->getData($attributeCode));
}

A text attribute will just get its value loaded with the product, so $_product->getRegistration() or $_product->getData('registration') etc should all work.

You have use ->getData() to get an array of everything loaded into the object, and (string) $collection->getSelect() to see the sql query that generated your collection if you want to make sure everything is loaded properly

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.