/** * Copy images from a product to another * * @param integer $id_smart_blog_post_old Source product ID * @param boolean $id_smart_blog_post_new Destination product ID */ public static function duplicateProductImages($id_smart_blog_post_old, $id_smart_blog_post_new, $combination_images) { $images_types = BlogImageType::getImagesTypes('post'); $result = Db::getInstance()->executeS(' SELECT `id_image` FROM `' . _DB_PREFIX_ . 'smart_blog_gallary_images` WHERE `id_smart_blog_post` = ' . (int) $id_smart_blog_post_old); foreach ($result as $row) { $image_old = new Image($row['id_image']); $image_new = clone $image_old; unset($image_new->id); $image_new->id_smart_blog_post = (int) $id_smart_blog_post_new; // A new id is generated for the cloned image when calling add() if ($image_new->add()) { $new_path = $image_new->getPathForCreation(); foreach ($images_types as $image_type) { if (file_exists(_MODULE_SMARTBLOG_GALLARY_DIR_ . $image_old->getExistingImgPath() . '-' . $image_type['name'] . '.jpg')) { if (!Configuration::get('PS_LEGACY_IMAGES')) { $image_new->createImgFolder(); } copy(_MODULE_SMARTBLOG_GALLARY_DIR_ . $image_old->getExistingImgPath() . '-' . $image_type['name'] . '.jpg', $new_path . '-' . $image_type['name'] . '.jpg'); } } if (file_exists(_MODULE_SMARTBLOG_GALLARY_DIR_ . $image_old->getExistingImgPath() . '.jpg')) { copy(_MODULE_SMARTBLOG_GALLARY_DIR_ . $image_old->getExistingImgPath() . '.jpg', $new_path . '.jpg'); } SmartBlogGallaryImage::replaceAttributeImageAssociationId($combination_images, (int) $image_old->id, (int) $image_new->id); // Duplicate shop associations for images $image_new->duplicateShops($id_smart_blog_post_old); } else { return false; } } return SmartBlogGallaryImage::duplicateAttributeImageAssociations($combination_images); }