From 47dba548cce8ffca31c3fefe3200d045f0c34837 Mon Sep 17 00:00:00 2001 From: rMalie Date: Tue, 28 Feb 2012 15:03:51 +0000 Subject: [PATCH] // Fix product images association for multishop #PSTEST-745 git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13697 b9a71923-0436-4b27-9f14-aed3839534dd --- .../default/template/controllers/products/images.tpl | 6 +++--- controllers/admin/AdminProductsController.php | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/admin-dev/themes/default/template/controllers/products/images.tpl b/admin-dev/themes/default/template/controllers/products/images.tpl index da91bb2cc..0ce46b101 100644 --- a/admin-dev/themes/default/template/controllers/products/images.tpl +++ b/admin-dev/themes/default/template/controllers/products/images.tpl @@ -123,6 +123,7 @@ { assoc = assoc.slice(0, -1); assoc += {literal}"}"{/literal}; + assoc = jQuery.parseJSON(assoc); } else assoc = false; @@ -188,7 +189,7 @@ cover = "forbbiden"; if (responseJSON.cover == "1") cover = "enabled"; - imageLine(responseJSON.id, responseJSON.path, responseJSON.position, cover, false) + imageLine(responseJSON.id, responseJSON.path, responseJSON.position, cover, responseJSON.shops) $("#imageTable tr:last").after(responseJSON.html); $("#countImage").html(parseInt($("#countImage").html()) + 1); $("#img" + id).remove(); @@ -318,8 +319,7 @@ line = line.replace("", ""); if (shops != false) { - tmp = jQuery.parseJSON(shops); - $.each(tmp, function(key, value){ + $.each(shops, function(key, value){ if (value == 1) line = line.replace('id="' + key + '' + id + '"','id="' + key + '' + id + '" checked=checked'); }); diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 76e034818..a04aa4c46 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -1072,6 +1072,14 @@ class AdminProductsControllerCore extends AdminController if (isset($result['success'])) { $obj = new Image((int)$result['success']['id_image']); + + // Associate image to shop from context + $shops = Shop::getContextListShopID(); + $obj->associateTo($shops); + $json_shops = array(); + foreach ($shops as $id_shop) + $json_shops[$id_shop] = true; + $json = array( 'name' => $result['success']['name'], 'status' => 'ok', @@ -1079,6 +1087,7 @@ class AdminProductsControllerCore extends AdminController 'path' => $obj->getExistingImgPath(), 'position' => $obj->position, 'cover' => $obj->cover, + 'shops' => $json_shops, ); @unlink(_PS_TMP_IMG_DIR_.'product_'.(int)$obj->id_product.'.jpg'); @unlink(_PS_TMP_IMG_DIR_.'product_mini_'.(int)$obj->id_product.'.jpg');