500内部服务器错误。第一个参数应该是一个数组

时间:2012-09-30 20:49:49

标签: php zend-framework magento

我在一个网站(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

1 个答案:

答案 0 :(得分:1)

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

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

但这可能(可能)是使用array_filter的错误方法。如果没有第二个参数,它将过滤任何评估为false的数组元素,例如,如果元素是nullfalseempty arrayempty string。但我怀疑Mage::getModel(...)->getProducts(...);是否会返回这些元素(对特定情况没有任何了解)。但如果它确实返回带有这些元素的数组,则表明它背后的设计很糟糕。