[-] Classes : fix return value when updating product attachment

This commit is contained in:
tDidierjean
2012-03-09 14:49:22 +00:00
parent d94c19ab73
commit 92191e72f4
+7 -5
View File
@@ -127,12 +127,14 @@ class AttachmentCore extends ObjectModel
public static function attachToProduct($id_product, $array)
{
$result1 = Attachment::deleteProductAttachments($id_product);
if (is_array($array))
{
$ids = array();
foreach ($array as $id_attachment)
if ((int)$id_attachment > 0)
$ids[] = '('.(int)$id_product.','.(int)$id_attachment.')';
$ids[] = array('id_product' => (int)$id_product, 'id_attachment' => (int)$id_attachment);
Db::getInstance()->execute('
UPDATE '._DB_PREFIX_.'product
SET cache_has_attachments = '.(count($ids) ? '1' : '0').'
@@ -140,10 +142,10 @@ class AttachmentCore extends ObjectModel
LIMIT 1
');
return ($result1 && count($ids) && Db::getInstance()->execute('
INSERT INTO '._DB_PREFIX_.'product_attachment (id_product, id_attachment)
VALUES '.implode(',', $ids))
);
if (!empty($ids))
$result2 = Db::getInstance()->insert('product_attachment', $ids);
return ($result1 && (!isset($result2) || $result2));
}
return $result1;
}