/** * Add TAG to PRODUCT relations * * @param Mage_Tag_Model_Tag $model * @param array $productIds * @return Mage_Tag_Model_Tag_Relation */ public function addRelations(Mage_Tag_Model_Tag $model, $productIds = array()) { $this->setAddedProductIds($productIds); $this->setTagId($model->getTagId()); $this->setCustomerId(null); $this->setStoreId($model->getStore()); $this->_getResource()->addRelations($this); return $this; }
/** * Getting statistics data into buffer. * Replacing our buffer array with new statistics and incoming data. * * @deprecated after 1.4.0.0 * * @param Mage_Tag_Model_Tag $object * @return Mage_Tag_Model_Tag */ public function aggregate($object) { $tagId = (int) $object->getId(); $storeId = (int) $object->getStore(); // create final summary from existing data and add specified base popularity $finalSummary = $this->_getExistingBasePopularity($tagId); if ($object->hasBasePopularity() && $storeId) { $finalSummary[$storeId]['store_id'] = $storeId; $finalSummary[$storeId]['base_popularity'] = $object->getBasePopularity(); } // calculate aggregation data $summaries = $this->_getAggregationPerStoreView($tagId); $summariesGlobal = $this->_getGlobalAggregation($tagId); if ($summariesGlobal) { $summaries[] = $summariesGlobal; } // override final summary with aggregated data foreach ($summaries as $row) { $storeId = (int) $row['store_id']; foreach ($row as $key => $value) { $finalSummary[$storeId][$key] = $value; } } // prepare static parameters to final summary for insertion foreach ($finalSummary as $key => $row) { $finalSummary[$key]['tag_id'] = $tagId; foreach (array('base_popularity', 'popularity', 'historical_uses', 'uses', 'products', 'customers') as $k) { if (!isset($row[$k])) { $finalSummary[$key][$k] = 0; } } $finalSummary[$key]['popularity'] = $finalSummary[$key]['historical_uses']; } // remove old and insert new data $write = $this->_getWriteAdapter(); $write->delete($this->getTable('tag/summary'), array('tag_id = ?' => $tagId)); $write->insertMultiple($this->getTable('tag/summary'), $finalSummary); return $object; }