我已将此代码添加到Custom Design>特别优惠类别的自定义布局更新:
<reference name="content">
<remove name="product_list"/>
<block type="catalog/product_sale" name="product_sale" alias="sale" 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="setLimit"><limit>9</limit></action>
<action method="setColumnCount"><columns>3</columns></action>
<action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
<action method="addPriceBlockType">
<type>bundle</type>
<block>bundle/catalog_product_price</block>
<template>bundle/catalog/product/price.phtml</template>
</action>
</block>
</reference>
<reference name="product_list_toolbar">
<action method="setDefaultGridPerPage">
<limit>9</limit>
</action>
</reference>
这使特殊优惠类别从以下php文件中读取:
/app/code/local/Mage/Catalog/Block/Product/Sale.php
其中包含以下内容:
<?php
class Mage_Catalog_Block_Product_Sale extends Mage_Catalog_Block_Product_List
{
//public $_collection;
public function getProductsLimit()
{
if ($this->getData('limit')) {
return intval($this->getData('limit'));
} else {
return 32;
}
}
public function __construct()
{
parent::__construct();
$collection = $this->_getProductCollection();
$this->setCollection($collection);
}
protected function _getProductCollection()
{
$page = Mage::getBlockSingleton('page/html_pager')->getCurrentPage();
date_default_timezone_set(Mage::getStoreConfig('general/locale/timezone'));
$todayDate = strftime("%Y-%m-%d",Mage::app()->getLocale()->storeTimeStamp(Mage::app()->getStore()->getId()));
$storeId = Mage::app()->getStore()->getId();
$product = Mage::getModel('catalog/product');
$this->_productCollection = $product->setStoreId($storeId)
->getCollection()
->addAttributeToSelect(array('name','status', 'price', 'special_price', 'small_image','required_options','special_from_date', 'special_to_date'), 'inner')
->joinField('stock_status','cataloginventory/stock_status','stock_status',
'product_id=entity_id', array(
'stock_status' => Mage_CatalogInventory_Model_Stock_Status::STATUS_IN_STOCK,
'website_id' => Mage::app()->getWebsite()->getWebsiteId(),
))
->addAttributeToFilter('special_price', array('gt' => 0), 'left')
->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $todayDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left')
//->setOrder('created_at', 'desc')
->addAttributeToSort('created_at', 'desc')
->addFinalPrice()
->addStoreFilter()
->setPageSize($this->getProductsLimit())
->setCurPage($page)
->addAttributeToFilter('status', 1)
->addUrlRewrite();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
//Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);
$checkedProducts = new Varien_Data_Collection();
foreach ($this->_productCollection as $k => $p) {
$p = $p->loadParentProductIds();
$parentIds = $p->getData('parent_product_ids');
if (is_array($parentIds) && !empty($parentIds)) {
if (!$checkedProducts->getItemById($parentIds[0])) {
$parentProduct = Mage::getModel('catalog/product')->setStoreId($storeId)->load($parentIds[0]);
if ($parentProduct->isVisibleInCatalog()) {
$checkedProducts->addItem($parentProduct);
}
}
} else {
if (!$checkedProducts->getItemById($k)) {
$checkedProducts->addItem($p);
}
}
if (count($checkedProducts) >= $this->getProductsLimit()) {
break;
}
}
return $this->_productCollection;
}
}
结果是一个抓住所有具有特价的产品的页面。然而问题是它引起了某种AJAX冲突,现在分页/过滤器不起作用。
错误是:
GET http://www.yourhealthfoodstore.co.uk/special-offers.html?p=2&isLayerAjax=1 500 Internal Server Error 869ms prototype.js (line 1530)
与prototype.js中的以下函数有关:
request: function(url) {
this.url = url;
this.method = this.options.method;
var params = Object.isString(this.options.parameters) ?
this.options.parameters :
Object.toQueryString(this.options.parameters);
if (!['get', 'post'].include(this.method)) {
params += (params ? '&' : '') + "_method=" + this.method;
this.method = 'post';
}
if (params && this.method === 'get') {
this.url += (this.url.include('?') ? '&' : '?') + params;
}
this.parameters = params.toQueryParams();
try {
var response = new Ajax.Response(this);
if (this.options.onCreate) this.options.onCreate(response);
Ajax.Responders.dispatch('onCreate', this, response);
this.transport.open(this.method.toUpperCase(), this.url,
this.options.asynchronous);
if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
this.transport.onreadystatechange = this.onStateChange.bind(this);
this.setRequestHeaders();
this.body = this.method == 'post' ? (this.options.postBody || params) : null;
this.transport.send(this.body);
/* Force Firefox to handle ready state 4 for synchronous requests */
if (!this.options.asynchronous && this.transport.overrideMimeType)
this.onStateChange();
}
catch (e) {
this.dispatchException(e);
}
},
特别是第1530行:
this.transport.send(this.body);
我对原型/ AJAX没有太多了解,有什么想法可以解决这个问题吗?
由于