Magento - $ _orders = Mage :: getResourceModel输出SQL字符串 - Recent.php

时间:2015-10-02 18:53:56

标签: php magento

我试图在/ customer / account Recent Orders网格的前端输出更多订单。

/Mage/Sales/Order/Block/Recent.php中的代码说明了

<?php  $_orders = Mage::getResourceModel('sales/order_collection')
        ->addAttributeToSelect('*')            
        ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
        ->addAttributeToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
        ->addAttributeToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
        ->addAttributeToSort('created_at', 'desc')
        ->setPageSize(5)        
        ->load();
?>  

当我编辑数字 - > gt;加载(10)时,它会输出一个创建的查询字符串。在Recent.php中没有任何回声

它也不会添加10个订单,只保留默认值5.我缺少什么?

我尝试将此直接放入recent.phtml

<?php  $_orders = Mage::getResourceModel('sales/order_collection')
        ->addAttributeToSelect('*')            
        ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
        ->addAttributeToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
        ->addAttributeToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
        ->addAttributeToSort('created_at', 'desc')
        ->setPageSize('10')        
        ->load('10');
?>  

它将订单数量更改为10,但仍然输出SQL查询。

查询

SELECT `main_table`.* FROM `sales_flat_order` AS `main_table` WHERE (main_table.customer_id = '1') AND (state IN('new', 'processing', 'complete', 'closed', 'canceled', 'holded', 'payment_review')) ORDER BY created_at DESC LIMIT 10 10 

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

<?php  $_orders = Mage::getResourceModel('sales/order_collection')
        ->addAttributeToSelect('*')            
        ->joinAttribute('shipping_firstname', 'order_address/firstname', 'shipping_address_id', null, 'left')
        ->joinAttribute('shipping_lastname', 'order_address/lastname', 'shipping_address_id', null, 'left')
        ->addAttributeToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
        ->addAttributeToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
        ->addAttributeToSort('created_at', 'desc')
        ->setPageSize('10')        
        ->load(0);
?> 

添加:0 - &gt; load()