本文整理汇总了PHP中Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection::getResource方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractCollection::getResource方法的具体用法?PHP AbstractCollection::getResource怎么用?PHP AbstractCollection::getResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
的用法示例。
在下文中一共展示了AbstractCollection::getResource方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _prepareCache
/**
* @param \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection
*/
protected function _prepareCache($collection)
{
$stmt = $collection->getSelect()->query();
$ids = array();
foreach ($stmt as $item) {
$ids = array_merge($ids, array_map('intval', explode('/', $item['path'])));
}
$ids = array_unique($ids);
if (empty($ids)) {
return;
}
/* @var $attribute \Magento\Eav\Model\Attribute */
$attribute = $collection->getFirstItem()->getResource()->getAttribute('name');
$resource = $collection->getResource();
$tableName = \Magento\Catalog\Model\Category::ENTITY . '_entity_' . $attribute->getBackendType();
$dbSelect1 = $resource->getConnection()->select()->from($resource->getTable($tableName), new \Zend_Db_Expr('MAX(`store_id`)'))->where("`entity_id` = `ccev`.`entity_id`")->where("`attribute_id` = `ccev`.`attribute_id`")->where("`store_id` = 0 OR `store_id` = ?", $this->getStoreId());
$dbSelect2 = $resource->getConnection()->select()->from(array('ccev' => $resource->getTable($tableName)), array('name' => 'value', 'category_id' => 'entity_id'))->where('ccev.entity_id IN (' . implode(',', $ids) . ')')->where('ccev.attribute_id = ?', $attribute->getAttributeId())->where('ccev.store_id = (' . $dbSelect1->__toString() . ')');
$cacheData = array();
foreach ($resource->getConnection()->fetchAll($dbSelect2) as $row) {
$cacheData[$row['category_id']] = $row['name'];
}
$this->setData('categories_cache', $cacheData);
}
示例2: getResource
/**
* Get resource instance
*
* @return \Magento\Mtf\Util\Generate\Repository\RepositoryResource
*/
public function getResource()
{
return parent::getResource();
}