2017-07-10 14:11:35 +02:00

65 lines
2.6 KiB
PHP

<?php
class Image extends ImageCore
{
/**
* @Override Antadis
* Fill image legend when it doesn't exist in every languages
*/
public static function duplicateProductImages($id_product_old, $id_product_new, $combinationImages)
{
$imagesTypes = ImageType::getImagesTypes('products');
$result = Db::getInstance()->ExecuteS('
SELECT `id_image`
FROM `'._DB_PREFIX_.'image`
WHERE `id_product` = '.(int)($id_product_old));
$product_name = DB::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'product_lang`
WHERE `id_product` = '.(int)($id_product_new).'
AND `id_lang` = 2
');
foreach ($result as $row)
{
$imageOld = new Image($row['id_image']);
$imageNew = clone $imageOld;
$imageNew->id_product = (int)($id_product_new);
// @Override
foreach(Language::getLanguages(FALSE) as $language) {
if(empty($imageNew->legend[$language['id_lang']])){
$imageNew->legend[$language['id_lang']] = $product_name;
}
}
// @End Override
if($imageNew->add()) {
$new_path = $imageNew->getPathForCreation();
if(file_exists(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'.jpg')) {
copy(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'.jpg', $new_path.'.jpg');
}
foreach($imagesTypes AS $imageType) {
if(file_exists(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'-'.$imageType['name'].'.jpg')) {
if(!Configuration::get('PS_LEGACY_IMAGES')) {
$imageNew->createImgFolder();
}
copy(_PS_PROD_IMG_DIR_.$imageOld->getExistingImgPath().'-'.$imageType['name'].'.jpg', $new_path.'-'.$imageType['name'].'.jpg');
} else {
if(!Configuration::get('PS_LEGACY_IMAGES')) {
$imageNew->createImgFolder();
}
imageResize($new_path.'.jpg', _PS_PROD_IMG_DIR_.$imageNew->getExistingImgPath().'-'.$imageType['name'].'.jpg', (int) $imageType['width'], (int) $imageType['height']);
}
}
self::replaceAttributeImageAssociationId($combinationImages, (int)($imageOld->id), (int)($imageNew->id));
} else {
return FALSE;
}
}
return self::duplicateAttributeImageAssociations($combinationImages);
}
}