0

my problem is, that i can get correct product url, but it doesn't get product name, image, price and description.

i have 6 item random product block like this:

http://www.upload.ee/image/3374325/magento.png

all the six items are clickable and they have correctly random products url's behind. Just can't figure out why image, price and name won't apper.

current code:

    <?php $_productCollection = Mage::getModel('catalog/product')->getCollection(); ?>
    <?php if(!$_productCollection->count()): ?>
        <div class="padder">
            <div class="note-msg">
                <?php echo $this->__('There are no products matching the selection.') ?>
            </div>
        </div>
    <?php else: ?>
        <div class="listing-type-cell  catalog-listing padder"  style="margin-bottom:-20px;margin-top:10px;border-top: 1px solid rgba(221,221,221,0.53);"> <!-- the class name will change to .listing-type-grid if viewing in grid mode -->
        <?php $_collectionSize = $_productCollection->count() ?>

        <?php $_items = $_productCollection->getItems(); 
            shuffle($_items); ?>
        <h2 style="margin:20px 0;">Seda toodet vaadanud inimesed vaatasid ka neid tooteid</h2>
        <table cellspacing="0" class="products-grid" id="product-grid-table">
            <?php $i=0; foreach ($_items as $_product): ?>
                <?php if ($i++%6==0): ?>
            <tr height="290">
                <?php endif ?>
                <td class="random_item" style="width:150px;padding-right:10px;">
                    <a class="product-image" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $_product->getName() ?>">
                        <img src="<?php echo $_product->getImageUrl(); ?>" width="144" height="216" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                        <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></h3>
                        <?php echo $this->getPriceHtml($_product, true) ?>
                    </a>
                </td>
            <?php if ($i%12==0 && $i!=$_collectionSize): ?>
            </tr>
            <?php endif ?>
            <?php if ($i==6) break;  // show 6 products max ?> 

        <?php endforeach ?>
        <?php for($i;$i%12!=0;$i++): ?>
            <td class="empty-product">&nbsp;</td>
        <?php endfor ?>
        <?php if ($i%12==0): ?>
        </tr>
        <?php endif ?>
        </table>
        <script type="text/javascript">decorateTable('product-grid-table')</script>
    </div>
    <?php endif; ?>
mLeht
  • 17
  • 5

1 Answers1

1

See this question for adding name and price: retrieve product attributes in collection and this thread for images: load the media_gallery in a product collection

Community
  • 1
  • 1
Simon H
  • 2,495
  • 4
  • 30
  • 38
  • Thanks! I just added these lines: $_productCollection->addAttributeToSelect('name'); $_productCollection->addAttributeToSelect('price'); $_productCollection->addAttributeToSelect('image'); and it solved the problem. – mLeht Jun 11 '13 at 13:10