简体   繁体   English

如何通过在list.phtml上创建来获取magento集合

[英]how to get magento collection by created at on list.phtml

I tried to get new product ...bt this was not coming if ...i didn't place product new from date in magento.. 我试图获取新产品...如果我没有从magento放置新产品的话,这不会来。

I code something for getting new product in magento...bt its not coming on base of created at.. 我在magento中编写了一些用于获取新产品的代码...它不是基于创建的..

i need to know that what should i change in my code for new product... 我需要知道我应该如何更改新产品的代码...

I need to show new product on list.phtml in magento product listing page 我需要在magento产品列表页面的list.phtml上显示新产品

my code is bellow. 我的代码在下面。

 $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)
    ;

Step 1 : Rewrite Block associated with .phtml you want to overwrite. 步骤1:重写与要覆盖的.phtml关联的块。

Step 2 : add block related xml and associate a .phtml to this block. 第2步:添加与块相关的xml,并将.phtml与此块相关联。

Step 3 : Now create this .phtml file and use your new block call to fill dynamic part of that .phtml file part. 步骤3:现在创建此.phtml文件,并使用新的块调用填充该.phtml文件部分的动态部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM