试图在magento上更改资源模型

时间:2016-05-19 07:20:17

标签: php magento magento-1.9

抱歉这个问题,但是我正在改变一些事情并且一片空白 几乎每次页面,或根本没有变化!,

我正在尝试更改浏览次数最多的产品:

<?php
  class Mage_Catalog_Block_Product_Mostviewed extends Mage_Catalog_Block_Product_Abstract{
      public function __construct(){
        parent::__construct();
        $storeId    = Mage::app()->getStore()->getId();
        // get today and last 30 days time
        $today = time();
        $last = $today - (60*60*24*5);
        $from = date("Y-m-d", $last);
        $to = date("Y-m-d", $today);
        $products = Mage::getResourceModel('reports/product_collection')
                ->addOrderedQty()
                ->addAttributeToSelect('*')
                ->addAttributeToSelect(array('name', 'price', 'small_image'))
                ->setStoreId($storeId)
                ->addStoreFilter($storeId)
                ->addViewsCount()
                ->addViewsCount($from, $to);
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
        Mage::getSingleton('cataloginventory/stock')
            ->addInStockFilterToCollection($products);   
        $products->setPageSize(20)->setCurPage(1);
        $this->setProductCollection($products);
      }
  }

使用md精选过滤器(https://www.magentocommerce.com/magento-connect/md-featured-products.html?_ga=1.40864226.192476984.1462507802

这个给了我与前一个相同的结果,就像它没有得到eav

<?php
  class Mage_Catalog_Block_Product_Mostviewed extends Mage_Catalog_Block_Product_Abstract{
      public function __construct(){
        parent::__construct();
        $products = Mage::getResourceModel('catalog/product_collection')
                ->addOrderedQty()
                ->addAttributeToSelect(array('name', 'price', 'small_image'))
                ->addAttributeToFilter('md_featured_product', 1)
                ->addViewsCount();
        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
        Mage::getSingleton('cataloginventory/stock')
            ->addInStockFilterToCollection($products);   
        $products->setPageSize(4)->setCurPage(1);
        $this->setProductCollection($products);
      }
  }

这是来自md-featured-call的原始内容:

       if (is_null($this->_productCollection)) {
            $collection = Mage::getModel('catalog/product')->getCollection();

                $attributes = Mage::getSingleton('catalog/config')
                        ->getProductAttributes();

                $collection->addAttributeToSelect($attributes)
                        ->addMinimalPrice()
                        ->addFinalPrice()
                        ->addTaxPercents()
                        ->addAttributeToFilter('md_featured_product', 1, 'left')
                        ->addStoreFilter();

                Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
                Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($c$
                $this->_productCollection = $collection;
        }
        return $this->_productCollection;

我也尝试过改变

$products = Mage::getResourceModel('reports/product_collection')

使用:     $ products = Mage :: getResourceModel('catalog / product') 和     $ products = Mage :: getResourceModel('catalog / product_collection')

但两个案件都有白屏,

我不确定还有什么可以尝试:(任何帮助都会有很多帮助

0 个答案:

没有答案