// Fixed bug #PSTEST-136, Attachement works correctly after any changements
This commit is contained in:
1 parent
ed368bf2f0
commit
ba4c954ab8
2 files changed
+27
-7
No files matched your search
+23
-3
@@ -87,21 +87,41 @@ class AttachmentCore extends ObjectModel
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @static
|
||||||
|
* @param $id_product
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function deleteProductAttachments($id_product)
|
||||||
|
{
|
||||||
|
return Db::getInstance()->execute('
|
||||||
|
DELETE FROM '._DB_PREFIX_.'product_attachment
|
||||||
|
WHERE id_product = '.(int)$id_product);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @static
|
||||||
|
* @param $id_product
|
||||||
|
* @param $array
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
public static function attachToProduct($id_product, $array)
|
public static function attachToProduct($id_product, $array)
|
||||||
{
|
{
|
||||||
$result1 = Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'product_attachment WHERE id_product = '.(int)$id_product);
|
$result1 = Attachment::deleteProductAttachments($id_product);
|
||||||
if (is_array($array))
|
if (is_array($array))
|
||||||
{
|
{
|
||||||
$ids = array();
|
$ids = array();
|
||||||
foreach ($array as $id_attachment)
|
foreach ($array as $id_attachment)
|
||||||
$ids[] = '('.(int)$id_product.','.(int)$id_attachment.')';
|
if ((int)$id_attachment > 0)
|
||||||
|
$ids[] = '('.(int)$id_product.','.(int)$id_attachment.')';
|
||||||
Db::getInstance()->execute('
|
Db::getInstance()->execute('
|
||||||
UPDATE '._DB_PREFIX_.'product
|
UPDATE '._DB_PREFIX_.'product
|
||||||
SET cache_has_attachments = '.(count($ids) ? '1' : '0').'
|
SET cache_has_attachments = '.(count($ids) ? '1' : '0').'
|
||||||
WHERE id_product = '.(int)$id_product.'
|
WHERE id_product = '.(int)$id_product.'
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
');
|
');
|
||||||
return ($result1 && Db::getInstance()->execute('
|
|
||||||
|
return ($result1 && count($ids) && Db::getInstance()->execute('
|
||||||
INSERT INTO '._DB_PREFIX_.'product_attachment (id_product, id_attachment)
|
INSERT INTO '._DB_PREFIX_.'product_attachment (id_product, id_attachment)
|
||||||
VALUES '.implode(',', $ids))
|
VALUES '.implode(',', $ids))
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ class ProductControllerCore extends FrontController
|
|||||||
{
|
{
|
||||||
if (!$this->errors)
|
if (!$this->errors)
|
||||||
{
|
{
|
||||||
// Assign to the tempate the id of the virtuale product. "0" if the product is not downloadable.
|
// Assign to the template the id of the virtual product. "0" if the product is not downloadable.
|
||||||
$this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int)$this->product->id));
|
$this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int)$this->product->id));
|
||||||
|
|
||||||
// If the product is not active, it's the admin preview mode
|
// If the product is not active, it's the admin preview mode
|
||||||
@@ -129,7 +129,7 @@ class ProductControllerCore extends FrontController
|
|||||||
$this->textRecord($this->product, $this->context->cart);
|
$this->textRecord($this->product, $this->context->cart);
|
||||||
$this->formTargetFormat();
|
$this->formTargetFormat();
|
||||||
}
|
}
|
||||||
else if (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct((int)$this->product->id, (int)Tools::getValue('deletePicture')))
|
else if (Tools::getIsset('deletePicture') && !$this->context->cart->deletePictureToProduct($this->product->id, Tools::getValue('deletePicture')))
|
||||||
$this->errors[] = Tools::displayError('An error occurred while deleting the selected picture');
|
$this->errors[] = Tools::displayError('An error occurred while deleting the selected picture');
|
||||||
|
|
||||||
$files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true);
|
$files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true);
|
||||||
@@ -470,7 +470,7 @@ class ProductControllerCore extends FrontController
|
|||||||
|
|
||||||
$product_picture_width = (int)Configuration::get('PS_PRODUCT_PICTURE_WIDTH');
|
$product_picture_width = (int)Configuration::get('PS_PRODUCT_PICTURE_WIDTH');
|
||||||
$product_picture_height = (int)Configuration::get('PS_PRODUCT_PICTURE_HEIGHT');
|
$product_picture_height = (int)Configuration::get('PS_PRODUCT_PICTURE_HEIGHT');
|
||||||
if ($error || (!$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS') OR !move_uploaded_file($file['tmp_name'], $tmp_name)))
|
if ($error || (!$tmp_name = tempnam(_PS_TMP_IMG_DIR_, 'PS') || !move_uploaded_file($file['tmp_name'], $tmp_name)))
|
||||||
return false;
|
return false;
|
||||||
/* Original file */
|
/* Original file */
|
||||||
else if (!imageResize($tmp_name, _PS_UPLOAD_DIR_.$file_name))
|
else if (!imageResize($tmp_name, _PS_UPLOAD_DIR_.$file_name))
|
||||||
@@ -485,7 +485,7 @@ class ProductControllerCore extends FrontController
|
|||||||
// Store customization in database
|
// Store customization in database
|
||||||
$cart->addPictureToProduct($this->product->id, $indexes[$field_name], Product::CUSTOMIZE_FILE, $file_name);
|
$cart->addPictureToProduct($this->product->id, $indexes[$field_name], Product::CUSTOMIZE_FILE, $file_name);
|
||||||
}
|
}
|
||||||
@unlink($tmp_name);
|
unlink($tmp_name);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user