Frage

Wie der Titel schon sagt, mag ich genannt, neue Produkte zeigen, in von bestimmten Kategorien von Reihen in der Homepage getrennt.

  

Zeile 1 -> Neue Produkte von Kategorie 1

     

Row 2 -> Neue Produkte von Kategorie 2

     

Zeile 3 -> Neue Produkte aus der Kategorie 3

     

... etc

In meinem Magento Admin CMS unter Startseite werden sie in als separate Blöcke genannt werden:

<block type="catalog/product_new" name="home.catalog.product.new_category_1" alias="product_new_category_1" template="catalog/product/new_category_1.phtml">

<block type="catalog/product_new" name="home.catalog.product.new_category_2" alias="product_new_category_2" template="catalog/product/new_category_2.phtml">

<block type="catalog/product_new" name="home.catalog.product.new_category_3" alias="product_new_category_3" template="catalog/product/new_category_3.phtml">

...etc

Im Grunde denke ich an new.phtml duplizieren und nennt es new_category_1.phtml, new_category_2.phtml, etc und „neue“ Produkte aus der Kategorie-ID 1, Kategorie-ID 2 jeweils erhalten.

Ich spielte mit Mage::getModel('catalog/category')->getCollection();, getProductCollection und getCatId und kann es nicht in einer Kopie new.phml (app/design/frontend/default/default/template/catalog/product/) erhalten zu arbeiten.

Der folgende Code funktioniert, aber nicht „neu“ zugewiesen Produkte in der Kategorie-ID zugewiesen laden, lädt er alle Produkte innerhalb es.

<?php 

$cat_id = 46; // category id
$category = Mage::getModel('catalog/category')->load($cat_id);
$products = $category->getProductCollection()->addCategoryFilter($category)->addAttributeToSelect('*');

if (($products=($_products = $this->getProductCollection()) && $_products->getSize())): ?>

<div class="hp-report">
    <div class="head-alt">
        <h2 class="title"><?php echo $this->__('New Products') ?></h2>
    </div>
    <table cellspacing="0" class="generic-product-grid" id="new-products-list-table">
        <tr>
        <?php $i=0; foreach ($_products->getItems() as $_product): ?>
            <?php if ($i>=4): continue; endif; ?>

            <td>
                <p class="product-image">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(170) ?>" width="170" height="170" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
                </p>
                <p><a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php echo $this->getPriceHtml($_product, true, '-new') ?>
                <?php if($_product->isSaleable()): ?>
                    <a href="<?php echo $this->getAddToCartUrl($_product) ?>"><img src="<?php echo $this->getSkinUrl('images/btn_add_to_cart.gif') ?>" alt="<?php echo $this->__('Add to Cart') ?>" title="<?php echo $this->__('Add to Cart') ?>" /></a>
                <?php else: ?>
                <div class="out-of-stock"><?php echo $this->__('Out of stock') ?></div>
                <?php endif; ?>
                <div class="clear"></div>
                <ul class="add-to">
                    <?php if ($this->helper('wishlist')->isAllow()) : ?>
                        <li><a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist') ?></a></li>
                    <?php endif; ?>
                    <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                        <li><a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare') ?></a></li>
                    <?php endif; ?>
                </ul>
                </td>
        <?php $i++; endforeach; ?>
        <?php for($i;$i%4!=0;$i++): ?>
                <td>&nbsp;</td>
            <?php endfor ?>
            </tr>
    </table>
    <script type="text/javascript">decorateTable('new-products-list-table');</script>
</div>

<?php endif; ?>

Alle Gedanken geschätzt.

War es hilfreich?

Lösung

Th folgende Sammlung Abfrage sollten Sie bekommen, was Sie wollen

$todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);            
$products = $category->
getProductCollection()->
addCategoryFilter($category)->
addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))->
addAttributeToFilter('news_to_date', array('or'=> array(
    0 => array('date' => true, 'from' => $todayDate),
    1 => array('is' => new Zend_Db_Expr('null')))
), 'left')->            
addAttributeToSelect('*');

A Produkte „Neuheit“ wird durch zwei Attribute bestimmt, news_from_date und news_to_date, so dass Sie wollen zwei weitere Attribute zum Filter hinzuzufügen. Die spezifische Methode ruft von oben, dass dies tun sind

addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))->
addAttributeToFilter('news_to_date', array('or'=> array(
    0 => array('date' => true, 'from' => $todayDate),
    1 => array('is' => new Zend_Db_Expr('null')))
), 'left')->            

Sie sind direkt aus dem New Product Block bei

genommen
/app/code/core/Mage/Catalog/Block/Product/New.php

Andere Tipps

Million Dank Alan. Der Code wurde die Auflistung noch alle Produkte innerhalb der zugewiesenen Kategorie, sondern eine geringfügige Änderung es behoben. Hier ist der endgültige Code für jeden, der interessiert sein könnte.

$_products = $category->
getProductCollection()->
addCategoryFilter($category)->
addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))->
addAttributeToFilter('news_to_date', array('or'=> array(
        0 => array('date' => true, 'from' => $todayDate),
        1 => array('is' => new Zend_Db_Expr('null')))
), 'left')->            
addAttributeToSelect('*');

if (($this->getProductCollection()) && $_products->getSize()): ?> 

Gibt es eine Möglichkeit den Code nicht von new.php zu duplizieren und noch in der Lage sein, die Filter anwenden? Ich bin kein Programmierer per se, aber ich gehe davon aus einer Zwischendatei darum kümmern wird.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top