0

我在一个站点(www.theprinterdepo.com)上遇到了一个非常奇怪的问题,在谷歌浏览器中我看到了 500 个内部服务器错误。但是在 IE 和 firefox 上它可以正常工作)。我注意到的是,如果我转到 chrome 并单击历史记录并删除所有缓存、cookie 等,那么它会再次正常工作。

我删除了 system.log 并再次检查,唯一记录的是这个:

第一个参数应该是 /xxx/xxx/public_html/app/code/local/Mf/Searchterms/Model/Layer.php 中的一个数组

这是我从未接触过的标准 magento 文件,但这里是代码:

<?php


class Mf_Searchterms_Model_Layer extends Mage_Catalog_Model_Layer
{
    const XML_PATH_DISPLAY_LAYER_COUNT = 'catalog/search/use_layered_navigation_count';

    /**
     * Get current layer product collection
     *
     * @return Mage_Catalog_Model_Resource_Eav_Resource_Product_Collection
     */
    public function getProductCollection()
    {
        if (isset($this->_productCollections[$this->getCurrentCategory()->getId()])) {
            $collection = $this->_productCollections[$this->getCurrentCategory()->getId()];
        } else {
            $collection = Mage::getResourceModel('catalogsearch/fulltext_collection');
            $this->prepareProductCollection($collection);
            $this->_productCollections[$this->getCurrentCategory()->getId()] = $collection;
        }
        return $collection;
    }

    /**
     * Prepare product collection
     *
     * @param Mage_Catalog_Model_Resource_Eav_Resource_Product_Collection $collection
     * @return Mage_Catalog_Model_Layer
     */
    public function prepareProductCollection($collection)
    {

        $params = Mage::app()->getRequest()->getParams();

        $collection
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());
        $query = Mage::helper('catalogsearch')->getQuery();
        $productIds = Mage::getModel('searchterms/searchterms')->getProducts($query->getId());
        $productIds = array_filter($productIds);
        //var_dump($productIds);

        if(is_array($productIds) && sizeof($productIds) > 0){
            //echo "asd";
            $productIdArray = $productIds;
            $collection->addFieldToFilter('entity_id', array('in'=>$productIdArray));
            $collection->joinField('position',
                'searchterms_product',
                'position',
                'product_id=entity_id',
                'searchterms_id='.$query->getId(), 
                'left')
                ;

                if(isset($params['order']) && $params['order'] != ""){
                    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
                    Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
                }else{
                    $collection->setOrder(`searchterms_product`.'position','ASC');
                    Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
                }
        }
        else 
        {
            $collection->addSearchFilter(Mage::helper('catalogsearch')->getQuery()->getQueryText());
            $collection->setStore(Mage::app()->getStore())
                ->addMinimalPrice()
                ->addFinalPrice()
                ->addTaxPercents()
                ->addStoreFilter()
                ->addUrlRewrite();
            Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
            Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($collection);
        }


        return $this;
    }

    /**
     * Get layer state key
     *
     * @return string
     */
    public function getStateKey()
    {
        if ($this->_stateKey === null) {
            $this->_stateKey = 'Q_' . Mage::helper('catalogsearch')->getQuery()->getId()
                . '_'. parent::getStateKey();
        }
        return $this->_stateKey;
    }

    /**
     * Get default tags for current layer state
     *
     * @param   array $additionalTags
     * @return  array
     */
    public function getStateTags(array $additionalTags = array())
    {
        $additionalTags = parent::getStateTags($additionalTags);
        $additionalTags[] = Mage_CatalogSearch_Model_Query::CACHE_TAG;
        return $additionalTags;
    }

    /**
     * Add filters to attribute collection
     *
     * @param   Mage_Catalog_Model_Resource_Eav_Resource_Product_Attribute_Collection $collection
     * @return  Mage_Catalog_Model_Resource_Eav_Resource_Product_Attribute_Collection
     */
    protected function _prepareAttributeCollection($collection)
    {
        $collection->addIsFilterableInSearchFilter()
            ->addVisibleFilter();
        return $collection;
    }

    /**
     * Prepare attribute for use in layered navigation
     *
     * @param   Mage_Eav_Model_Entity_Attribute $attribute
     * @return  Mage_Eav_Model_Entity_Attribute
     */
    protected function _prepareAttribute($attribute)
    {
        $attribute = parent::_prepareAttribute($attribute);
        $attribute->setIsFilterable(Mage_Catalog_Model_Layer_Filter_Attribute::OPTIONS_ONLY_WITH_RESULTS);
        return $attribute;
    }
}

更新1: 我设法清理了apache错误日志,刷新了浏览器,然后这是日志上的新文本:[client 83.134.115.127]脚本头过早结束:index.php

4

1 回答 1

1

可能第一行 ( Mage::..) 返回NULLFALSE结果集为空且 array_filter 需要数组,而不是 null/false 值!尝试这个:

$productIds = Mage::getModel('searchterms/searchterms')->getProducts($query->getId());
if (!$productIds) {
    $productIds = array();
}
$productIds = array_filter($productIds);

但这(可能)是一种错误的使用方式array_filter。如果没有第二个参数,它将过滤任何评估为 的数组元素false,例如,如果一个元素是null, false, empty array, empty string。但我怀疑这Mage::getModel(...)->getProducts(...);是否会返回这些元素(对特定情况没有任何了解)。但是,如果它确实返回包含此类元素的数组,则表明其背后的设计不佳。

于 2012-09-30T20:55:47.800 回答