Beispiel #1
0
 /**
  * Load attributes from MongoDB after main data are loaded from MySQL
  *
  * @param bool $printQuery If the SQL query should be printed or not
  * @param bool $logQuery   If the SQL query should be logegd or not
  *
  * @return Smile_MongoCore_Model_Resource_Override_Catalog_Product_Collection Self reference
  */
 public function _loadAttributes($printQuery = false, $logQuery = false)
 {
     parent::_loadAttributes($printQuery, $logQuery);
     if (!empty($this->_itemsById)) {
         $storeFilter = array_unique(array('attr_' . $this->getDefaultStoreId(), 'attr_' . $this->getStoreId()));
         if (is_null($this->_loadedDocuments)) {
             $documentIds = $this->getLoadedIds();
             foreach ($documentIds as $key => $value) {
                 $documentIds[$key] = new MongoInt32($value);
             }
             $idFilter = array('_id' => array('$in' => $documentIds));
             $cursor = $this->_getDocumentCollection()->find($idFilter, $storeFilter);
             $this->_loadedDocuments = array();
             while ($cursor->hasNext()) {
                 $document = $cursor->getNext();
                 $this->_loadedDocuments[] = $document;
             }
         }
         foreach ($this->_loadedDocuments as $document) {
             $loadedData = array();
             //$document = $cursor->getNext();
             foreach ($storeFilter as $storeId) {
                 if (isset($document[$storeId])) {
                     if (!is_array($document[$storeId])) {
                         $document[$storeId] = array($storeId => $document[$storeId]);
                     }
                     foreach ($document[$storeId] as $attributeCode => $attributeValue) {
                         $loadedData[$attributeCode] = $attributeValue;
                     }
                 }
             }
             $this->_items[$document['_id']]->addData($loadedData);
         }
     }
     return $this;
 }