我在管理员中创建了一个股票报告,并且到目前为止所有工作都在运行,除了我似乎无法在已加入的列上进行过滤.
我已经加入了股票信息,使用以下内容来获取我的收藏.
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('name')
->addAttributeToSelect('sku')
->addAttributeToSelect('price')
->setStoreId($storeId);
$collection->addFieldToFilter('type_id', 'simple');
// Add on the stock qty information
$collection->getSelect()->join( array('stock'=>'ccmg_cataloginventory_stock_item'), 'e.entity_id = stock.item_id', array('stock.qty'));
Run Code Online (Sandbox Code Playgroud)
这导致它显示,但您无法对列进行过滤或排序.我假设因为选项没有被传递回连接.但是,可以对其他列进行排序和过滤,并拉回和显示匹配数据.
我一直在寻找,但大多数帖子都在2008年的Magento论坛上,而我正在使用1.6!任何指针都会很棒!
kia*_*tng 15
在连接之后,您需要将连接字段添加到_map
声明的数组中Varien_Data_Collection_Db
,例如:
$this->_map['fields']['stock_qty'] = 'stock.qty';
Run Code Online (Sandbox Code Playgroud)
[编辑]正如@ sh4dydud3_88指出的那样,你可以这样做:
$collection->addFilterToMap('stock_qty', 'stock.qty');
Run Code Online (Sandbox Code Playgroud)
这将添加字段stock_qty进行过滤.然后你可以过滤
$collection->addFieldToFilter('stock_qty', array('gt', 10));
Run Code Online (Sandbox Code Playgroud)
另一个例子:
class Company_Mohe_Model_Resource_Im_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
protected function _construct()
{
$this->_init('mohe/im');
}
public function joinIhe()
{
$this->getSelect()->join(array('ihe' => $this->getTable('mohe/ihe')),
'main_table.mic_inst_id = ihe.im_id',
array('ihe_name'=>'name', 'ihe_ifms_id'=>'ifms_id'));
//$this->_map['fields'] = array('ihe_name'=>'ihe.name', 'ihe_ifms_id'=>'ihe.ifms_id'); //incorrect method
$this->addFilterToMap('ihe_name', 'ihe.name'); //correct method, see comment by @sh4dydud3_88
return $this;
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8193 次 |
最近记录: |