Magento中的畅销书列表和catalog_product_flat_1

时间:2014-02-18 16:09:55

标签: magento

在Magento 1.8中将Use Flat Catalog Product设置为Yes时出错。我的一个模块似乎与此功能不兼容。请参阅以下错误:

  

a:5:{i:0; s:1852:“SELECT SUM(order_items.qty_ordered)AS ordered_qty,   order_itemsname AS order_items_nameorder_itemsproduct_id   AS entity_ideentity_type_ideattribute_set_id,   etype_ideskuehas_optionserequired_options,   ecreated_ateupdated_atflatnameflatimage AS   small_imageflatpriceflatminimal_price,   flatspecial_priceflatspecial_from_date,   flatspecial_to_datecat_indexposition AS   cat_index_positionat_inventory_in_stockis_in_stock AS   inventory_in_stock FROM sales_flat_order_item AS order_items   INNER JOIN sales_flat_order AS order ON order。entity_id =   order_items.order_id AND order。state<> '取消'和   (order。created_at BETWEEN'2014-01-18'''2014-02-17')LEFT JOIN   catalog_product_entity AS e ON(e.type_id NOT IN('groups',   'configurable','bundle'))和e.entity_id = order_items.product_id   AND e.entity_type_id = 4 LEFT JOIN catalog_product_flat_1 AS flat   ON(e.entity_id = flat.entity_id)INNER JOIN   catalog_category_product_index AS cat_index ON   cat_index.product_id = e.entity_id AND cat_index.store_id ='1'AND   cat_index.visibility IN(2,4)AND cat_index.category_id ='2'INNER   加入cataloginventory_stock_item AS at_inventory_in_stock ON   (at_inventory_in_stock。product_id = e.entity_id)AND   ((at_inventory_in_stock.use_config_manage_stock = 0 AND   at_inventory_in_stock.manage_stock = 1 AND   at_inventory_in_stock.is_in_stock = 1)或   (at_inventory_in_stock.use_config_manage_stock = 0 AND   at_inventory_in_stock.manage_stock = 0)或   (at_inventory_in_stock.use_config_manage_stock = 1 AND   at_inventory_in_stock.is_in_stock = 1))WHERE(parent_item_id IS NULL)   GROUP BY order_itemsproduct_id HAVING   (SUM(order_items.qty_ordered)> 0)ORDER BY ordered_qty desc,   ordered_qty desc LIMIT 1

     

“; I:1; S:4869:” #0   /home2/icast.sajtpro.se/www/mxfoto/magento/includes/src/Varien_Db_Statement_Pdo_Mysql.php(110):   Zend_Db_Statement_Pdo-> _execute(阵列)

在list.phtml文件中,我有以下代码:

class Tatva_Catalogextensions_Block_Bestsellers_List extends Mage_Catalog_Block_Product_List {
    protected function _getProductCollection()
    {
        parent::__construct();
        $storeId    = Mage::app()->getStore()->getId();
        $products = Mage::getResourceModel('reports/product_collection')
            ->addAttributeToSelect('*')             ->addOrderedQty()
            ->setStoreId($storeId)
            ->addStoreFilter($storeId)
            //->setOrder('ordered_qty', 'desc')
            ->setPageSize($this->get_prod_count())
            ->setOrder($this->get_order(), $this->get_order_dir())
            ->setCurPage($this->get_cur_page());
                    $productFlatData = Mage::getStoreConfig('catalog/frontend/flat_catalog_product');       if($productFlatData == "1")         {           $products->getSelect()->joinLeft(
                    array('flat' => 'catalog_product_flat_1'),
                    "(e.entity_id = flat.entity_id ) ",
                    array(
                       'flat.name AS name','flat.image AS small_image','flat.price AS price','flat.minimal_price as minimal_price','flat.special_price as special_price','flat.special_from_date AS special_from_date','flat.special_to_date AS special_to_date'
                    )
                );      }

        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($products);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($products);
        Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($products);

        $this->_productCollection = $products;

        return $this->_productCollection;
    }

    function get_prod_count()   {       //unset any saved limits
        Mage::getSingleton('catalog/session')->unsLimitPage();
        return (isset($_REQUEST['limit'])) ? intval($_REQUEST['limit']) : 9;    }// get_prod_count

    function get_cur_page()     {       return (isset($_REQUEST['p'])) ? intval($_REQUEST['p']) : 1;    }// get_cur_page

    function get_order()    {       return (isset($_REQUEST['order'])) ? ($_REQUEST['order']) : 'ordered_qty';  }// get_order

    function get_order_dir()    {       return (isset($_REQUEST['dir'])) ? ($_REQUEST['dir']) : 'desc';     }// get_direction }

?>

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

你应该改变

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

为:

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