0

我的问题是,我可以获得正确的产品 url,但它没有获得产品名称、图像、价格和描述。

我有 6 项随机产品块,如下所示:

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

所有六个项目都是可点击的,并且它们后面有正确的随机产品 URL。只是无法弄清楚为什么图像、价格和名称不会出现。

当前代码:

    <?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; ?>
4

1 回答 1

1

请参阅此问题以添加名称和价格:retrieve product attributes in collection和 this thread for images:load the media_gallery in a product collection

于 2013-06-11T11:32:23.913 回答