Add new product image in PrestaShop by core development
// add product image...
if(count($_FILES['files']['tmp_name']) > 1){
for($i=0;$i < count($_FILES['files']['tmp_name']);$i++ ){
$image = new Image();
$url = $_FILES['files']['tmp_name'][$i];
$shops = Shop::getShops(true, null, true);
$image->id_product = $id_product;
$image->position = Image::getHighestPosition($id_product) +1 ;
if($i==0){
$image->cover = true; // or false;
} else {
$image->cover = false; // or false;
}
if (($image->validateFields(false, true)) === true &&($image->validateFieldsLang(false, true)) === true && $image->add()) {
$image->associateTo($shops);
if (!$this->copyImg($id_product, $image->id, $url)){
$image->delete();
}
//$combination = new Combination((int)$idProductAttribute);
//$combination->setImages($image->id);
}
}
} else {
$image = new Image();
$url = $_FILES['files']['tmp_name'][0];
$shops = Shop::getShops(true, null, true);
$image->id_product = $id_product;
$image->position = Image::getHighestPosition($id_product) + 1;
$image->cover = true; // or false;
if (($image->validateFields(false, true)) === true &&($image->validateFieldsLang(false, true)) === true && $image->add()) {
$image->associateTo($shops);
if(!$this->copyImg($id_product, $image->id, $url)){
$image->delete();
}
//$combination = new Combination((int)$idProductAttribute);
//$combination->setImages($image->id);
}
}
// add product image...
if(count($_FILES['files']['tmp_name']) > 1){
for($i=0;$i < count($_FILES['files']['tmp_name']);$i++ ){
$image = new Image();
$url = $_FILES['files']['tmp_name'][$i];
$shops = Shop::getShops(true, null, true);
$image->id_product = $id_product;
$image->position = Image::getHighestPosition($id_product) +1 ;
if($i==0){
$image->cover = true; // or false;
} else {
$image->cover = false; // or false;
}
if (($image->validateFields(false, true)) === true &&($image->validateFieldsLang(false, true)) === true && $image->add()) {
$image->associateTo($shops);
if (!$this->copyImg($id_product, $image->id, $url)){
$image->delete();
}
//$combination = new Combination((int)$idProductAttribute);
//$combination->setImages($image->id);
}
}
} else {
$image = new Image();
$url = $_FILES['files']['tmp_name'][0];
$shops = Shop::getShops(true, null, true);
$image->id_product = $id_product;
$image->position = Image::getHighestPosition($id_product) + 1;
$image->cover = true; // or false;
if (($image->validateFields(false, true)) === true &&($image->validateFieldsLang(false, true)) === true && $image->add()) {
$image->associateTo($shops);
if(!$this->copyImg($id_product, $image->id, $url)){
$image->delete();
}
//$combination = new Combination((int)$idProductAttribute);
//$combination->setImages($image->id);
}
}
// add product image...
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment