[+] classes : New method ->attachProduct($id_product)

// Fix #PSTEST-699
// now new attachment are automatically linked to the current product
This commit is contained in:
mMarinetti
2012-02-21 10:03:32 +00:00
parent 8603a4fce0
commit f57e2b1cba
3 changed files with 36 additions and 9 deletions
@@ -94,9 +94,7 @@
<script type="text/javascript">
//displayFlags(languages, id_language, allowEmployeeFormLang);
$(document).ready(function() {
$(document).ready(function(){
$("#addAttachment").live('click', function() {
$("#selectAttachment2 option:selected").each(function(){
var val = $('#arrayAttachments').val();
+20 -1
View File
@@ -88,8 +88,10 @@ class AttachmentCore extends ObjectModel
}
/**
* deassociate $id_product from the current object
*
* @static
* @param $id_product
* @param $id_product int
* @return bool
*/
public static function deleteProductAttachments($id_product)
@@ -100,6 +102,23 @@ class AttachmentCore extends ObjectModel
}
/**
* associate $id_product to the current object.
*
* @param int $id_product id of the product to associate
* @return boolean true if succed
*/
public function attachProduct($id_product)
{
return Db::getInstance()->execute('
INSERT INTO '._DB_PREFIX_.'product_attachment
(id_attachment, id_product) VALUES
('.(int)$this->id.', '.(int)$id_product.')');
}
/**
* associate an array of id_attachment $array to the product $id_product
* and remove eventual previous association
*
* @static
* @param $id_product
* @param $array
+15 -5
View File
@@ -371,11 +371,20 @@ class AdminProductsControllerCore extends AdminController
if (Tools::strlen($attachment->file_name) > 128)
$this->errors[] = Tools::displayError('File name too long');
if (empty($this->errors))
$attachment->add();
{
$res = $attachment->add();
if (!$res)
$this->errors[] = Tools::displayError('Unable to add this attachment in the database');
else
{
$id_product = (int)Tools::getValue($this->identifier);
$res = $attachment->attachProduct($id_product);
if (!$res)
$this->errors[] = Tools::displayErrors('Unable to associate this attachment to product');
}
}
else
$this->errors[] = Tools::displayError('Invalid file');
if (Validate::isLoadedObject($attachment))
$this->redirect_after = self::$currentIndex.'&id_product='.Tools::getValue('id_product').(isset($_POST['id_category']) ? '&id_category='.(int)$_POST['id_category'] : '').'&conf=4&add'.$this->table.'&action=Attachments&token='.($token ? $token : $this->token);
}
}
}
@@ -902,6 +911,7 @@ class AdminProductsControllerCore extends AdminController
{
$this->action = 'addAttachments';
$this->tab_display = 'attachments';
$this->display = 'edit';
}
else
$this->errors[] = Tools::displayError('You do not have permission to add here.');
@@ -3005,8 +3015,8 @@ class AdminProductsControllerCore extends AdminController
$attachment_description = array();
foreach ($languages as $language)
{
$attachment_name[$language['id_lang']] = $this->getFieldValue($obj, 'attachment_name', (int)$language['id_lang']);
$attachment_description[$language['id_lang']] = $this->getFieldValue($obj, 'attachment_description', (int)$language['id_lang']);
$attachment_name[$language['id_lang']] = '';
$attachment_description[$language['id_lang']] = '';
}
$data->assign(array(