首页 文章

Magento:展示新产品

提问于
浏览
1

我无法找到解决问题的方法:我有一个由我创建的layout.phtml类别 . 在此类别中,我只想显示此类别的新产品(由新的日期和新日期字段设置) . 我不明白怎么做(xml或php无论如何) . 有人可以帮帮我吗?

2 回答

  • 1

    请尝试按此类别获取所有新产品按类别划分 -

    public function getProductCollection($catIds) {
    $productIds = $this->getProductIdsByCategories($catIds);
    $todayDate  = Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
        $storeId    = Mage::app()->getStore()->getId();
        $collection = Mage::getResourceModel('catalog/product_collection')
                            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
                            ->setStoreId($storeId)
                            ->addStoreFilter($storeId)
                            ->addMinimalPrice()
                            ->addTaxPercents()
                            ;
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
    
        $collection
            ->addAttributeToFilter('news_from_date', array('date' => true, 'to' => $todayDate))
            ->addAttributeToFilter('news_to_date', array('or'=> array(
                0 => array('date' => true, 'from' => $todayDate),
                1 => array('is' => new Zend_Db_Expr('null')))
            ), 'left')
            // ->addAttributeToSort('news_from_date', 'desc')
    
            ;
    
        if(count($productIds)) {
            $collection->addFieldToFilter('entity_id', array('in'=>$productIds));
        }
    
        return $collection;
    }
    

    希望它会有所帮助 .

    谢谢!

  • 0

    不起作用,但我已经以这种方式解决了(希望它可以帮助某人):

    • 首先,转到CMS - > WIDGETS,然后创建目录新产品列表的小部件 . 在里面,进行新的布局更新:显示锚类别,主要内容,产品网格 .

    • 秒,转到template / catalog / product / widget / new / content / new_grid.phtml,然后添加:

    $currentCategory = Mage::registry('current_category');
            $category_model = Mage::getModel('catalog/category');
            $all_child_categories = $category_model->getResource()->getAllChildren($currentCategory);
    
    • 第三,在foreach($ _products-> getItems()为$ _product之后)添加:
    $visualizzo="";
    
            $diff = array_diff($all_child_categories, $_product->getCategoryIds());
            if(count($diff)==count($all_child_categories)){
                $visualizzo="display:none;";
            }
    
    • 最后,在li class =“item”中有一个样式,把它放在:

相关问题