Wie in den Kommentaren erläutert, gibt es meines Erachtens keine Möglichkeit, dies mithilfe der CMS-Seiten zu tun, da der Liste der neuen Produkte kein Ebenenmodell zugeordnet ist. Sie haben nur Ebenenmodelle für den Kategoriekontext und den Suchkontext.
Meine Lösung (getestet und funktioniert) besteht darin, ein Modul zu schreiben, das alle auf einer Seite als neu gekennzeichneten Produkte auflistet und über ein Ebenenmodell verfügt, das die Sammlung neuer Produkte verwaltet.
Hier geht. Seien Sie vorbereitet, es ist lang.
Ich habe die Nebenstelle angerufen, kann StackExchange_NewProducts
aber den Namen jederzeit ändern.
Sie benötigen folgende Dateien:
app/etc/modules/StackExchange_NewProducts.xml
- die Deklarationsdatei:
<?xml version="1.0"?>
<config>
<modules>
<StackExchange_NewProducts>
<codePool>local</codePool>
<active>true</active>
<depends>
<Mage_Catalog />
</depends>
</StackExchange_NewProducts>
</modules>
</config>
app/code/local/StackExchange/NewProducts/etc/config.xml
- die Konfigurationsdatei
<?xml version="1.0"?>
<config>
<modules>
<StackExchange_NewProducts>
<version>1.0.0</version>
</StackExchange_NewProducts>
</modules>
<global>
<models>
<stackexchange_newproducts>
<class>StackExchange_NewProducts_Model</class>
</stackexchange_newproducts>
</models>
<blocks>
<stackexchange_newproducts>
<class>StackExchange_NewProducts_Block</class>
</stackexchange_newproducts>
</blocks>
<helpers>
<stackexchange_newproducts>
<class>StackExchange_NewProducts_Helper</class>
</stackexchange_newproducts>
</helpers>
<events>
<controller_front_init_routers> <!-- create a custom router to handle the 'new-products' url -->
<observers>
<stackexchange_newproducts>
<class>StackExchange_NewProducts_Controller_Router</class>
<method>initControllerRouters</method>
</stackexchange_newproducts>
</observers>
</controller_front_init_routers>
</events>
</global>
<frontend>
<routers> <!-- declare a router -->
<newproducts>
<use>standard</use>
<args>
<module>StackExchange_NewProducts</module>
<frontName>newproducts</frontName>
</args>
</newproducts>
</routers>
<layout>
<updates>
<stackexchange_newproducts>
<file>stackexchange_newproducts.xml</file>
</stackexchange_newproducts>
</updates>
</layout>
</frontend>
</config>
app/code/local/StackExchange/NewProducts/Controller/Router.php
- Der benutzerdefinierte Router, der die URL verarbeitet new-products
und sie einem Controller und einer Aktion zuordnet
<?php
class StackExchange_NewProducts_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract
{
const NEW_PRODUCTS_URL_KEY = 'new-products';
public function initControllerRouters($observer)
{
$front = $observer->getEvent()->getFront();
$front->addRouter('stackexchange_newproducts', $this);
return $this;
}
public function match(Zend_Controller_Request_Http $request)
{
if (!Mage::isInstalled()) {
Mage::app()->getFrontController()->getResponse()
->setRedirect(Mage::getUrl('install'))
->sendResponse();
exit;
}
$urlKey = trim($request->getPathInfo(), '/');
if ($urlKey == self::NEW_PRODUCTS_URL_KEY) {
$request->setModuleName('newproducts')
->setControllerName('index')
->setActionName('index');
$request->setAlias(
Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
$urlKey
);
return true;
}
return false;
}
}
app/code/local/StackExchange/NewProducts/controllers/IndexController.php
- die tatsächliche Steuerung, die die neuen Produkte anzeigt
<?php
class StackExchange_NewProducts_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
app/code/local/StackExchange/NewProducts/Helper/Data.php
- der allgemeine Helfer des Moduls
<?php
class StackExchange_NewProducts_Helper_Data extends Mage_Core_Helper_Abstract
{
}
app/design/frontend/base/default/layout/stackexchange_newproducts.xml
- die Modullayoutdatei, die den Inhalt der Seite definiert
<?xml version="1.0"?>
<layout>
<newproducts_index_index>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-left.phtml</template>
</action>
</reference>
<reference name="left">
<block type="stackexchange_newproducts/layer_new" name="catalog.leftnav" before="-" template="catalog/layer/view.phtml" />
</reference>
<reference name="content">
<block type="core/template" name="new_products_container" as="new_products_container" template="stackexchange_newproducts/container.phtml">
<action method="setTitle" translate="title" module="stackexchange_newproducts">
<title>New Products</title>
</action>
<block type="stackexchange_newproducts/new" name="new_product" as="new_products" template="catalog/product/list.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
</block>
<action method="addColumnCountLayoutDepend"><layout>empty</layout><count>6</count></action>
<action method="addColumnCountLayoutDepend"><layout>one_column</layout><count>5</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_left</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>two_columns_right</layout><count>4</count></action>
<action method="addColumnCountLayoutDepend"><layout>three_columns</layout><count>3</count></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
</block>
</block>
</reference>
</newproducts_index_index>
</layout>
app/code/local/StackExchange/NewProducts/Block/New.php
- der Block, der die neue Produktkollektion rendern soll:
<?php
class StackExchange_NewProducts_Block_New extends Mage_Catalog_Block_Product_List
{
public function __construct()
{
parent::__construct();
}
public function getModuleName()
{
return 'Mage_Catalog';
}
protected function _getProductCollection()
{
if (is_null($this->_productCollection)) {
$this->_productCollection = $this->getLayer()->getProductCollection();
}
return $this->_productCollection;
}
public function getLayer()
{
$layer = Mage::registry('current_layer');
if ($layer) {
return $layer;
}
return Mage::getSingleton('stackexchange_newproducts/layer');
}
}
app/code/local/StackExchange/NewProducts/Block/Layer/New.php
- der Ebenenblock, der auf der linken Seite angezeigt werden soll (Filter)
<?php
class StackExchange_NewProducts_Block_Layer_New extends Mage_Catalog_Block_Layer_View
{
public function getLayer()
{
if (!$this->hasData('_layer')){
$layer = Mage::getSingleton('stackexchange_newproducts/layer');
$this->setData('_layer', $layer);
}
return $this->getData('_layer');
}
protected function _initBlocks()
{
parent::_initBlocks();
$this->_attributeFilterBlockName = 'stackexchange_newproducts/layer_filter_attribute';
$this->_priceFilterBlockName = 'stackexchange_newproducts/layer_filter_price';
$this->_decimalFilterBlockName = 'stackexchange_newproducts/layer_filter_decimal';
}
protected function _prepareLayout()
{
$stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)
->setLayer($this->getLayer());
$this->setChild('layer_state', $stateBlock);
$filterableAttributes = $this->_getFilterableAttributes();
foreach ($filterableAttributes as $attribute) {
if ($attribute->getAttributeCode() == 'price') {
$filterBlockName = $this->_priceFilterBlockName;
} elseif ($attribute->getBackendType() == 'decimal') {
$filterBlockName = $this->_decimalFilterBlockName;
} else {
$filterBlockName = $this->_attributeFilterBlockName;
}
$this->setChild($attribute->getAttributeCode() . '_filter',
$this->getLayout()->createBlock($filterBlockName)
->setLayer($this->getLayer())
->setAttributeModel($attribute)
->init());
}
$this->getLayer()->apply();
return $this;
}
}
Jetzt benötigt jeder Attributtyp einen Filterblock:
app/code/local/StackExchange/NewProducts/Block/Layer/Filter/Attribute.php
- allgemeiner Filterblock für Attribute
<?php
class StackExchange_NewProducts_Block_Layer_Filter_Attribute extends Mage_Catalog_Block_Layer_Filter_Attribute
{
public function __construct()
{
parent::__construct();
$this->_filterModelName = 'stackexchange_newproducts/layer_filter_attribute';
}
}
app/code/local/StackExchange/NewProducts/Block/Layer/Filter/Decimal.php
- Filterblock für Dezimalattribute
<?php
class StackExchange_NewProducts_Block_Layer_Filter_Decimal extends Mage_Catalog_Block_Layer_Filter_Decimal
{
public function __construct()
{
parent::__construct();
$this->_filterModelName = 'stackexchange_newproducts/layer_filter_decimal';
}
}
app/code/local/StackExchange/NewProducts/Block/Layer/Filter/Price.php
- Filterblock für Preisattribut
<?php
class StackExchange_NewProducts_Block_Layer_Filter_Price extends Mage_Catalog_Block_Layer_Filter_Price
{
public function __construct()
{
parent::__construct();
$this->_filterModelName = 'stackexchange_newproducts/layer_filter_price';
}
}
app/code/local/StackExchange/NewProducts/Model/Layer.php
- das Schichtmodell für den Umgang mit neuen Produkten
<?php
class StackExchange_NewProducts_Model_Layer extends Mage_Catalog_Model_Layer
{
public function getStateKey()
{
if ($this->_stateKey === null) {
$this->_stateKey = 'STORE_'.Mage::app()->getStore()->getId()
. '_NEW_PRODUCTS_'
. '_CUSTGROUP_' . Mage::getSingleton('customer/session')->getCustomerGroupId();
}
return $this->_stateKey;
}
public function getStateTags(array $additionalTags = array())
{
$additionalTags = array_merge($additionalTags, array('new_products'));
return $additionalTags;
}
public function getProductCollection()
{
if (isset($this->_productCollections['new_products'])) {
$collection = $this->_productCollections['new_products'];
} else {
$collection = $this->_getCollection();
$this->prepareProductCollection($collection);
$this->_productCollections['new_products'] = $collection;
}
return $collection;
}
public function prepareProductCollection($collection)
{
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addFinalPrice()
->addTaxPercents()
->addUrlRewrite();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
return $this;
}
protected function _getCollection()
{
$todayStartOfDayDate = Mage::app()->getLocale()->date()
->setTime('00:00:00')
->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$todayEndOfDayDate = Mage::app()->getLocale()->date()
->setTime('23:59:59')
->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
$collection = Mage::getModel('catalog/product')->getCollection()
->addStoreFilter()
->addAttributeToFilter('news_from_date', array('or'=> array(
0 => array('date' => true, 'to' => $todayEndOfDayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter('news_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayStartOfDayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
->addAttributeToFilter(
array(
array('attribute' => 'news_from_date', 'is'=>new Zend_Db_Expr('not null')),
array('attribute' => 'news_to_date', 'is'=>new Zend_Db_Expr('not null'))
)
)
->addAttributeToSort('news_from_date', 'desc');
return $collection;
}
}
Wie jedes Attribut einen Block für Filter benötigt, benötigt es auch ein Modell für die Behandlung von Filtern:
app/code/local/StackExchange/NewProducts/Model/Layer/Filter/Attribute.php
- das allgemeine Attributfiltermodell
<?php
class StackExchange_NewProducts_Model_Layer_Filter_Attribute extends Mage_Catalog_Model_Layer_Filter_Attribute
{
protected function _createItem($label, $value, $count = 0)
{
return Mage::getModel('stackexchange_newproducts/layer_filter_item')
->setFilter($this)
->setLabel($label)
->setValue($value)
->setCount($count);
}
}
app/code/local/StackExchange/NewProducts/Model/Layer/Filter/Decimal.php
- das Filtermodell für Dezimalattribute
<?php
class StackExchange_NewProducts_Model_Layer_Filter_Decimal extends Mage_Catalog_Model_Layer_Filter_Attribute
{
protected function _createItem($label, $value, $count = 0)
{
return Mage::getModel('stackexchange_newproducts/layer_filter_item')
->setFilter($this)
->setLabel($label)
->setValue($value)
->setCount($count);
}
}
app/code/local/StackExchange/NewProducts/Model/Layer/Filter/Price.php
- das Preisattributfiltermodell
<?php
class StackExchange_NewProducts_Model_Layer_Filter_Price extends Mage_Catalog_Model_Layer_Filter_Price
{
protected function _createItem($label, $value, $count = 0)
{
return Mage::getModel('stackexchange_newproducts/layer_filter_item')
->setFilter($this)
->setLabel($label)
->setValue($value)
->setCount($count);
}
}
app/code/local/StackExchange/NewProducts/Model/Layer/Filter/Item.php
- Die Filter erfordern eine Sammlung von Objektobjekten. Dies ist das Objekt Objekt - nicht sicher, ob dies benötigt wird. Ich denke, dass das Standard-Katalogelementmodell verwendet werden kann.
<?php
class StackExchange_NewProducts_Model_Layer_Filter_Item extends Mage_Catalog_Model_Layer_Filter_Item
{
}
app/design/frontend/base/default/template/stackexchange_newproducts/container.phtml
- Eine Vorlagendatei, die als Container für die neuen Produkte fungiert, sodass Sie einen Titel festlegen und Sitzungsnachrichten anzeigen können.
<?php if ($this->getTitle()) : ?>
<div class="page-title category-title">
<h1><?php echo $this->getTitle() ?></h1>
</div>
<?php endif;?>
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php echo $this->getChildHtml();?>
Das ist es. Leeren Sie den Cache, nachdem Sie alle Dateien erstellt und die Kompilierung deaktiviert haben.
Hier ist ein Screenshot, wie es auf meiner Seite aussieht
. (unter Verwendung von ce 1.7 mit Beispieldaten)