From 13f16490a7a43de0ea0d9d7378bfffb44fc8c49d Mon Sep 17 00:00:00 2001 From: lLefevre Date: Tue, 10 Apr 2012 16:23:37 +0000 Subject: [PATCH] [*] BO : #PSFV-696 : add attachment when we duplicate a product git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@14560 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Product.php | 22 +++++++++++++++++++ controllers/admin/AdminProductsController.php | 1 + 2 files changed, 23 insertions(+) diff --git a/classes/Product.php b/classes/Product.php index ea9db4172..ac7e890e2 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -3282,6 +3282,28 @@ class ProductCore extends ObjectModel return Db::getInstance()->insert('product_download', $data); } + public static function duplicateAttachments($id_product_old, $id_product_new) + { + // Get all ids attachments of the old product + $sql = 'SELECT `id_attachment` FROM `'._DB_PREFIX_.'product_attachment` WHERE `id_product` = '.(int)$id_product_old; + $results = Db::getInstance()->executeS($sql); + + if (!$results) + return true; + + $data = array(); + + // Prepare data of table product_attachment + foreach ($results as $row) + $data[] = array( + 'id_product' => (int)$id_product_new, + 'id_attachment' => (int)$row['id_attachment'] + ); + + // Duplicate product attachement + return Db::getInstance()->insert('product_attachment', $data); + } + /** * Duplicate features when duplicating a product * diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 8cf6916a2..1c0f83fa5 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -438,6 +438,7 @@ class AdminProductsControllerCore extends AdminController && Product::duplicateTags($id_product_old, $product->id) && Product::duplicateDownload($id_product_old, $product->id) && Product::duplicateTaxRulesGroup((int)$id_product_old, (int)$product->id) + && Product::duplicateAttachments((int)$id_product_old, (int)$product->id) && $product->duplicateShops($id_product_old)) { if ($product->hasAttributes())