0

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();
    }

New Product Fromこのファイルは、製品管理者からオプションフィールドとNew Product To日付フィールドをプルすることで機能します。カタログのサイズとこれらのフィールドを更新するために必要な手動管理を考えると、これは不便です。したがって、基本的には、機能を変更して、MAX製品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(entity_id)に基づいて製品を返そうとしただけで、何も返されませんでした(phpエラーも発生しませんでした)。

4

1 に答える 1

1

試してみてください(remove-> addAttributeToFilter('entity_id')... v1.7でテスト済み)

....
$collection = $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addAttributeToSort('entity_id', 'desc')
        ->setPageSize($this->getProductsCount())
        ->setCurPage(1);
...
于 2012-11-23T01:36:10.557 に答える