获取集合特色产品

时间:2017-04-05 16:09:58

标签: magento magento-1.9

我试图检索所有我的产品归因于yes(1)的特色,但int工作我的代码。我打错了方法吗?我的代码出了什么问题。 我检查了一些类似的问题,但大多数都采用了基本相同的方法。

<?php
$_products = $this->getProductCollection();
$_products->addAttributeToSelect('featured',1);


?>
<?php if ($_products && $_products->getSize()): ?>
    <div class="widget widget-new-products">
        <div class="widget-title">
            <h2><?php echo $this->__('Produtos em Destaque') ?></h2>
        </div>
        <div class="widget-products">
            <?php echo $this->getPagerHtml() ?>
            <?php $_columnCount = $this->getColumnCount(); ?>
            <?php $i=0; ?>
            <ul class="products-grid products-grid--max-<?php echo $_columnCount; ?>-col-widget">
                <?php foreach ($_products->getItems() as $_product): ?>
                    <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                        <?php $_imgSize = 210; ?>
                        <?php // The image size is locked at 210 for this for display purposes. CSS has it at 75% which should equate to 278px?>
                        <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image">
                            <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(210) ?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
                        </a>
                        <div class="product-info">
                            <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></a></h3>
                            <?php echo $this->getPriceHtml($_product, true, '-widget-new-grid') ?>
                            <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                            <div class="actions">
                                <?php if ($_product->isSaleable()): ?>
                                    <button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Add to Cart')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                                <?php else: ?>
                                    <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                                <?php endif; ?>
                                <ul class="add-to-links">
                                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                                        <li><a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                                    <?php endif; ?>
                                    <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                                        <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                                    <?php endif; ?>
                                </ul>
                            </div>
                        </div>
                    </li>
                <?php endforeach; ?>
            </ul>
        </div>
    </div>
<?php endif; ?>

1 个答案:

答案 0 :(得分:0)

使用以下内容检索所有具有yes属性的产品:

<?php
$_categoryId = $this->getCategoryId(); // Category ID

$_productCollection = Mage::getModel('catalog/category')->load($_categoryId)
    ->getProductCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('status', 1)
    ->addAttributeToFilter('visibility', 4)
    ->setOrder('price', 'ASC');
?>
<div class="featured-product">
    <?php foreach ($_productCollection as $_product): ?>
        <div class="item">
            <a class="product-image" href="<?php echo $_product->getProductUrl() ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(200); ?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
            </a>
            <a class="product-name" href="<?php echo $_product->getProductUrl() ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a>

            <?php echo $this->getPriceHtml($_product, true) ?>
        </div>
    <?php endforeach ?>
</div>