/** * Load attributes values with single query * * @param ResultSet $rows * @param ResultSet $attributes * @return array */ public function loadAttributes($rows, $attributes) { if (!$rows->valid()) { return; } $this->cacheAttributes($attributes); $entityIds = array(); foreach ($rows as $row) { array_push($entityIds, $this->getEntityId($row)); } $typeTables = $this->getTypeTables($attributes); $queries = array(); foreach ($typeTables as $type => $typeTable) { $select = $typeTable->getSql()->select(); $select->where(array('entity_id' => $entityIds)); $attributeIds = array(); foreach ($attributes as $attribute) { if ($type == $this->getAttributeType($attribute)) { $attributeIds[] = $this->getAttributeId($attribute); } } $select->where(array('attribute_id' => $attributeIds)); $queries[] = $select->getSqlString($typeTable->getAdapter()->getPlatform()); } /* build query */ $query = '(' . implode(') UNION ALL (', $queries) . ')'; $db = $this->_entitiesTable->getAdapter(); $valuesRows = $db->query($query, Adapter::QUERY_MODE_EXECUTE); $result = new ValuesCache(); foreach ($valuesRows as $row) { $result->setAttributeValue($row['entity_id'], $row['attribute_id'], $row['value']); } return $result; }