Exemplo n.º 1
0
 /**
  * @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);
 }
Exemplo n.º 2
0
 /**
  * Get resource instance
  *
  * @return \Magento\Mtf\Util\Generate\Repository\RepositoryResource
  */
 public function getResource()
 {
     return parent::getResource();
 }