本文整理汇总了PHP中Varien_Data_Collection::getResource方法的典型用法代码示例。如果您正苦于以下问题:PHP Varien_Data_Collection::getResource方法的具体用法?PHP Varien_Data_Collection::getResource怎么用?PHP Varien_Data_Collection::getResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Varien_Data_Collection
的用法示例。
在下文中一共展示了Varien_Data_Collection::getResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setCollection
/**
* set collection object
*
* @param Varien_Data_Collection $collection
*/
public function setCollection($collection)
{
if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
$select = $collection->getSelect();
$fromParts = $select->getPart(Zend_Db_Select::FROM);
if (isset($fromParts['at_qty'])) {
unset($fromParts['at_qty']);
$select->reset(Zend_Db_Select::FROM);
$select->setPart(Zend_Db_Select::FROM, $fromParts);
$subquery = $collection->getConnection()->select()->from(array('at_sub_qty' => $collection->getResource()->getTable('cataloginventory/stock_item')), array('product_id'))->columns(new Zend_Db_Expr("SUM(at_sub_qty.qty) AS qty"))->group('at_sub_qty.product_id');
$select->joinLeft(array('at_qty' => $subquery), 'at_qty.product_id=e.entity_id', array());
}
}
parent::setCollection($collection);
}
示例2: setCollection
/**
* Set collection to pager
*
* @param Varien_Data_Collection $collection
* @return Mage_Catalog_Block_Product_List_Toolbar
*/
public function setCollection($collection)
{
$this->_collection = $collection;
$this->_collection->setCurPage($this->getCurrentPage());
// we need to set pagination only if passed value integer and more that 0
$limit = (int) $this->getLimit();
if ($limit) {
$this->_collection->setPageSize($limit);
}
if ($this->getCurrentOrder() && $this->getRequest()->getParam('order')) {
if ($this->getCurrentOrder() == 'new' && Mage::registry('current_category')) {
$this->_collection->setOrder('entity_id', 'desc');
} else {
if ($this->getCurrentOrder() == 'popular' && Mage::registry('current_category')) {
$this->getCollection()->getSelect()->joinLeft(array('sfoi' => $collection->getResource()->getTable('sales/order_item')), 'e.entity_id = sfoi.product_id', array('qty_ordered' => 'SUM(sfoi.qty_ordered)'))->group('e.entity_id')->order('qty_ordered ' . $this->getCurrentDirection());
} else {
if ($this->getCurrentOrder() == 'price' && Mage::registry('current_category')) {
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
} else {
$this->_collection->setOrder('position', 'asc');
}
}
}
} else {
if (Mage::registry('current_category')) {
$this->_collection->setOrder('position', 'asc');
}
}
return $this;
}