Refactoring image system

This commit is contained in:
rMontagne committed 2011-11-22 09:34:25 +00:00
1 parent 415619f50e
commit b53d2ff9c9
1 file changed
+39 -12
+39 -12
View File
@@ -930,15 +930,15 @@ class AdminProductsControllerCore extends AdminController
$result = $uploader->handleUpload(); $result = $uploader->handleUpload();
if (isset($result['success'])) if (isset($result['success']))
{ {
$shops = false; $obj = new Image($result['success']['id_image']);
if (Shop::isFeatureActive()) $json = array(
$shops = Shop::getShops(); 'status' => 'ok',
$obj = new Product((int)Tools::getValue('id_product')); 'id'=>$obj->id,
$countImages = (int)Db::getInstance()->getValue('SELECT COUNT(id_product) FROM '._DB_PREFIX_.'image WHERE id_product = '.(int)$obj->id); 'path' => $obj->getExistingImgPath(),
$images = Image::getImages($this->context->language->id, $obj->id); 'position' => $obj->position,
$imagesTotal = Image::getImagesTotal($obj->id); 'cover' => $obj->cover,
$html = $this->getLineTableImage($result['success'], $imagesTotal + 1, $this->token, $shops); );
die($html); die(Tools::jsonEncode($json));
} }
else else
die(Tools::jsonEncode($result)); die(Tools::jsonEncode($result));
@@ -947,15 +947,42 @@ class AdminProductsControllerCore extends AdminController
public function ajaxPreProcess() public function ajaxPreProcess()
{ {
$this->action = Tools::getValue('action'); $this->action = Tools::getValue('action');
}
if (Tools::getValue('updateProductImageShopAsso')) public function ajaxProcessUpdateProductImageShopAsso()
{ {
if ($id_image = (int)Tools::getValue('id_image') && $id_shop = (int)Tools::getValue('id_shop')) if (($id_image = $_GET['id_image']) && ($id_shop = (int)$_GET['id_shop']))
if (Tools::getValue('active') == "true") if (Tools::getValue('active') == "true")
die(Db::getInstance()->execute('INSERT INTO '._DB_PREFIX_.'image_shop (`id_image`, `id_shop`) VALUES('.(int)$id_image.', '.(int)$id_shop.')')); die('INSERT INTO '._DB_PREFIX_.'image_shop (`id_image`, `id_shop`) VALUES('.(int)$id_image.', '.(int)$id_shop.')');
else else
die(Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'image_shop WHERE `id_image`='.(int)$id_image.' && `id_shop`='.(int)$id_shop)); die(Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'image_shop WHERE `id_image`='.(int)$id_image.' && `id_shop`='.(int)$id_shop));
} }
public function ajaxProcessUpdateImagePosition()
{
if ($json = Tools::getValue('json'))
{
$json = stripslashes($json);
$images = Tools::jsonDecode($json, true);
foreach ($images as $id => $position)
{
$img = new Image((int)$id);
$img->position = (int)$position;
$img->update();
}
}
exit();
}
public function ajaxProcessUpdateCover()
{
if ($this->action == 'UpdateCover')
{
Image::deleteCover((int)$_GET['id_product']);
$img = new Image((int)$_GET['id_image']);
$img->cover = 1;
$img->update();
}
} }
public function ajaxProcessDeleteProductImage() public function ajaxProcessDeleteProductImage()