Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将Magento New Product New.php更改为基于id,而不是&;从日期开始_Php_Magento_Magento 1.5 - Fatal编程技术网

将Magento New Product New.php更改为基于id,而不是&;从日期开始

将Magento New Product New.php更改为基于id,而不是&;从日期开始,php,magento,magento-1.5,Php,Magento,Magento 1.5,我想改变Magento核心文件New.php在块中调用新产品的方式 该文件位于app/code/core/Mage/Catalog/Block/Product/New.php——我已将该文件复制到本地目录,以防止更新 关注的内容包括: protected function _beforeToHtml() { $todayDate = Mage::app()->getLocale()->date()->toString(Varien_Date::DATE

我想改变Magento核心文件New.php在块中调用新产品的方式

该文件位于app/code/core/Mage/Catalog/Block/Product/New.php——我已将该文件复制到本地目录,以防止更新

关注的内容包括:

protected function _beforeToHtml()
    {
        $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);

        $collection = Mage::getResourceModel('catalog/product_collection');
        $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()
            ->addAttributeToFilter('news_from_date', array('or'=> array(
                0 => array('date' => true, 'to' => $todayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
            ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayDate),
                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')
            ->setPageSize($this->getProductsCount())
            ->setCurPage(1)
        ;

        $this->setProductCollection($collection);

        return parent::_beforeToHtml();
    }
该文件通过从产品管理员中拉出
新产品的可选字段和
新产品的日期字段来工作。考虑到我的目录的大小和更新这些字段所需的手动管理,这很不方便。因此,基本上,我希望将功能更改为获取最大产品id(即添加的最新产品),并在此之前运行到100。这将列出商店里最近的100种产品

我试过这样的方法,但没用

        $collection = $this->_addProductAttributesAndPrices($collection)
            ->addStoreFilter()
            ->addAttributeToFilter ('entity_id')
            ->addAttributeToSort('entity_id', 'desc')
            ->setPageSize($this->getProductsCount())
            ->setCurPage(1)
        ;

        $this->setProductCollection($collection);

        return parent::_beforeToHtml();
    }
这只是尝试根据产品id(实体id)返回产品,但没有返回任何内容(也没有给出任何php错误)。

Try(remove->addAttributeToFilter(“实体id”)…在v1.7上测试)


是的,这奏效了!谢谢这总是最简单的事情。我在只返回5个产品时遇到了一些问题,但我正在用一些XML更改对其进行排序。谢谢!
....
$collection = $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addAttributeToSort('entity_id', 'desc')
        ->setPageSize($this->getProductsCount())
        ->setCurPage(1);
...