1

I have a new attribute, and I want to display the new attributes, those related to the product, why this code does not work ?? What is wrong?

<?php echo $this->escapeHtml($_item->getData('condition')) ?>

why, to display the SKU, this works?

<?php echo $this->escapeHtml($_item->getsku()) ?>
  • attribute type?? – Shyam Krishna Sreekumar May 15 '15 at 7:06
  • I do not know attribute type ?? What is that? but I add atrubute of: Catalog> attribute> attribute Manage attribute. and I want to display it in the block related product. – Falah Failasuf May 15 '15 at 7:12
1

As $item is object of class Mage_Catalog_Model_Product_Link that why you cannot get condition field value from $item .If condition is a product attribute then you need to get Product object from $_item.Usually getProduct() is given you the Mage_Catalog_Model_Object.Using this you can get this attribute value

See code:

$_product=$_item->getProduct();

  $_product->getResource()->getAttribute('condition')->getFrontend()->getValue($_product);
0

Can I know the explanation? Why double? and how to make foreach?

<?php
$_product = $this->getProduct();

if($this->getItems()->getSize()){


$related_prods = Mage::getModel('catalog/product')
                    ->getCollection()
                    ->addAttributeToSelect('condition')
                    ->addAttributeToFilter('entity_id',array('in'=>$_product->getRelatedProductIds()));

    foreach($this->getItems() as $_item){

        foreach($related_prods as $related){
?>
            <li class="item col-lg-12 border-ngisor">
                <div class="col-lg-6">
                <?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
                    <?php if (!$_item->getRequiredOptions()): ?>
                        <input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $_item->getId() ?>" name="related_products[]" value="<?php echo $_item->getId() ?>" />
                    <?php endif; ?>
                <?php endif; ?>
                <div class="product">
                    <a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->escapeHtml($_item->getsku()) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_item, 'thumbnail')->resize(50) ?>" width="50" height="50" alt="<?php echo $this->escapeHtml($_item->getName()) ?>" /></a>
                    <div class="product-details">
                        <p class="product-name"><a href="<?php echo $_item->getProductUrl() ?>"><?php echo $this->escapeHtml($_item->getName()) ?></a></p>
                        <?php echo $this->getPriceHtml($_item, true, '-related') ?>
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <a href="<?php echo $this->getAddToWishlistUrl($_item) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a>
                        <?php endif; ?>
                    </div>
                </div>
                </div>
                <div class="col-lg-6">
                    <?php echo $related->getData('condition'); ?>
                </div>
            </li>
<?php
        }
    }
}
?>

SS:

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.