/** * Retrieve Tagged Products * * @param Mage_Tag_Model_Tag_Relation $model * @return array */ public function getProductIds($model) { $select = $this->_getReadAdapter()->select()->from($this->getMainTable(), 'product_id')->where("tag_id=?", $model->getTagId())->where('customer_id=?', $model->getCustomerId())->where('active=1'); if ($model->hasStoreId()) { $select->where('store_id = ?', $model->getStoreId()); } return $this->_getReadAdapter()->fetchCol($select); }
protected function _afterSave() { parent::_afterSave(); foreach ($this->getProductIds() as $productId) { Mage::app()->cleanCache(Mage_Catalog_Model_Product::CACHE_TAG . '_' . $productId); } }
/** * Get relation model for product marked in store with tag by customer * * @param Mage_Tag_Model_Tag_Relation $relationModel * @return Mage_Tag_Model_Tag_Relation */ protected function _getLinkBetweenTagCustomerProduct($relationModel) { return Mage::getModel('tag/tag_relation')->loadByTagCustomer($relationModel->getProductId(), $this->getId(), $relationModel->getCustomerId(), $relationModel->getStoreId()); }
/** * Add TAG to PRODUCT relations * * @param Mage_Tag_Model_Tag_Relation $model * @return Mage_Tag_Model_Resource_Tag_Relation */ public function addRelations($model) { $addedIds = $model->getAddedProductIds(); $bind = array('tag_id' => $model->getTagId(), 'store_id' => $model->getStoreId()); $write = $this->_getWriteAdapter(); $select = $write->select()->from($this->getMainTable(), 'product_id')->where('tag_id = :tag_id')->where('store_id = :store_id'); $oldRelationIds = $write->fetchCol($select, $bind); $insert = array_diff($addedIds, $oldRelationIds); $delete = array_diff($oldRelationIds, $addedIds); if (!empty($insert)) { $insertData = array(); foreach ($insert as $value) { $insertData[] = array('tag_id' => $model->getTagId(), 'store_id' => $model->getStoreId(), 'product_id' => $value, 'customer_id' => $model->getCustomerId(), 'created_at' => $this->formatDate(time())); } $write->insertMultiple($this->getMainTable(), $insertData); } if (!empty($delete)) { $write->delete($this->getMainTable(), array('product_id IN (?)' => $delete, 'store_id = ?' => $model->getStoreId())); } return $this; }
/** * Processing object after save data * * @return Mage_Core_Model_Abstract */ protected function _afterSave() { $ret = parent::_afterSave(); Mage::dispatchEvent('searchanise_tag_relation_save_after', array('object' => $this)); return $ret; }
/** * Checks whether the already marked this product in this store by this tag and by this customer. * * @param Mage_Tag_Model_Tag_Relation $tagRelationModel * @param Mage_Tag_Model_Tag $tagModel * @return boolean */ protected function _checkLinkBetweenTagCustomerProduct($tagRelationModel, $tagModel) { return count(Mage::getModel('tag/tag_relation')->loadByTagCustomer($tagRelationModel->getProductId(), $tagModel->getId(), $tagRelationModel->getCustomerId(), $tagRelationModel->getStoreId())->getProductIds()) > 0; }