/** * Save data for attachment-product relation * @access public * @param Web4pro_Attachments_Model_Attachment $attachment * @return Web4pro_Attachments_Model_Attachment_Product * @author WEB4PRO <*****@*****.**> */ public function saveAttachmentRelation($attachment) { $data = $attachment->getProductsData(); if (!is_null($data)) { $this->_getResource()->saveAttachmentRelation($attachment, $data); } return $this; }
/** * Save attachment - product relations * * @access public * @param Web4pro_Attachments_Model_Attachment $attachment * @param array $data * @return Web4pro_Attachments_Model_Resource_Attachment_Product * @author WEB4PRO <*****@*****.**> */ public function saveAttachmentRelation($attachment, $data) { if (!is_array($data)) { $data = array(); } $deleteCondition = $this->_getWriteAdapter()->quoteInto('attachment_id=?', $attachment->getId()); $this->_getWriteAdapter()->delete($this->getMainTable(), $deleteCondition); foreach ($data as $productId => $info) { $this->_getWriteAdapter()->insert($this->getMainTable(), array('attachment_id' => $attachment->getId(), 'product_id' => $productId, 'position' => @$info['position'])); } return $this; }