/** * associate an array of id_attachment $array to the product $id_product * and remove eventual previous association * * @static * @param $product_id * @param $array * @return bool */ public static function attachToProduct($product_id, $array) { $result1 = JeproshopAttachmentModelAttachment::deleteProductAttachments($product_id); if (is_array($array)) { $attachment_ids = array(); foreach ($array as $attachment_id) { if ((int) $attachment_id > 0) { $attachment_ids[] = array('product_id' => (int) $product_id, 'attachment_id' => (int) $attachment_id); } } if (!empty($attachment_ids)) { $result2 = Db::getInstance()->insert('product_attachment', $attachment_ids); } } JeproshopProductModelProduct::updateCacheAttachment((int) $product_id); if (is_array($array)) { return $result1 && (!isset($result2) || $result2); } return $result1; }