// Changes to AdminProducts workflow
This commit is contained in:
@@ -35,6 +35,10 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
protected $max_image_size;
|
protected $max_image_size;
|
||||||
|
|
||||||
private $_category;
|
private $_category;
|
||||||
|
/**
|
||||||
|
* @var string name of the tab to display
|
||||||
|
*/
|
||||||
|
protected $tab_display;
|
||||||
|
|
||||||
protected $available_tabs = array(
|
protected $available_tabs = array(
|
||||||
'Informations',
|
'Informations',
|
||||||
@@ -305,6 +309,12 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
return $product_download->deleteFile((int)$id_product_download);
|
return $product_download->deleteFile((int)$id_product_download);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Upload new attachment
|
||||||
|
*
|
||||||
|
* @param $token
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
public function processAddAttachments($token)
|
public function processAddAttachments($token)
|
||||||
{
|
{
|
||||||
$languages = Language::getLanguages(false);
|
$languages = Language::getLanguages(false);
|
||||||
@@ -347,6 +357,8 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$upload_mb = min($max_upload, $max_post);
|
$upload_mb = min($max_upload, $max_post);
|
||||||
$this->_errors[] = $this->l('the File').' <b>'.$_FILES['attachment_file']['name'].'</b> '.$this->l('exceeds the size allowed by the server, this limit is set to').' <b>'.$upload_mb.$this->l('Mb').'</b>';
|
$this->_errors[] = $this->l('the File').' <b>'.$_FILES['attachment_file']['name'].'</b> '.$this->l('exceeds the size allowed by the server, this limit is set to').' <b>'.$upload_mb.$this->l('Mb').'</b>';
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
$this->_errors[] = Tools::displayError('File is missing');
|
||||||
|
|
||||||
if (empty($this->_errors) && isset($uniqid))
|
if (empty($this->_errors) && isset($uniqid))
|
||||||
{
|
{
|
||||||
@@ -370,7 +382,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
if (!count($this->_errors))
|
if (!count($this->_errors))
|
||||||
{
|
{
|
||||||
$attachment->add();
|
$attachment->add();
|
||||||
$this->redirect_after = self::$currentIndex.'&id_product='.(int)(Tools::getValue($this->identifier)).'&id_category='.(int)(Tools::getValue('id_category')).'&addproduct&conf=4&action=Attachments&token='.($token ? $token : $this->token);
|
$this->confirmations[] = $this->l('Attachment successfully added');
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('Invalid file');
|
$this->_errors[] = Tools::displayError('Invalid file');
|
||||||
@@ -378,6 +390,20 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attach an existing attachment to the product
|
||||||
|
*
|
||||||
|
* @param $token
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function processAttachment($token)
|
||||||
|
{
|
||||||
|
if ($this->action == 'attachments')
|
||||||
|
if ($id = (int)Tools::getValue($this->identifier))
|
||||||
|
if (Attachment::attachToProduct($id, Tools::getValue('attachments')))
|
||||||
|
$this->redirect_after = self::$currentIndex.'&id_product='.(int)$id.(isset($_POST['id_category']) ? '&id_category='.(int)$_POST['id_category'] : '').'&conf=4&add'.$this->table.'&action=Attachments&token='.($token ? $token : $this->token);
|
||||||
|
}
|
||||||
|
|
||||||
public function processDuplicate($token)
|
public function processDuplicate($token)
|
||||||
{
|
{
|
||||||
if (Validate::isLoadedObject($product = new Product((int)(Tools::getValue('id_product')))))
|
if (Validate::isLoadedObject($product = new Product((int)(Tools::getValue('id_product')))))
|
||||||
@@ -866,14 +892,20 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
else if (Tools::isSubmit('submitAddAttachments'))
|
else if (Tools::isSubmit('submitAddAttachments'))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['add'] === '1')
|
if ($this->tabAccess['add'] === '1')
|
||||||
|
{
|
||||||
$this->action = 'addAttachments';
|
$this->action = 'addAttachments';
|
||||||
|
$this->tab_display = 'attachments';
|
||||||
|
}
|
||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
$this->_errors[] = Tools::displayError('You do not have permission to add here.');
|
||||||
}
|
}
|
||||||
else if (Tools::isSubmit('submitAttachments'))
|
else if (Tools::isSubmit('submitAttachments'))
|
||||||
{
|
{
|
||||||
if ($this->tabAccess['edit'] === '1')
|
if ($this->tabAccess['edit'] === '1')
|
||||||
|
{
|
||||||
$this->action = 'attachments';
|
$this->action = 'attachments';
|
||||||
|
$this->tab_display = 'attachments';
|
||||||
|
}
|
||||||
else
|
else
|
||||||
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
$this->_errors[] = Tools::displayError('You do not have permission to edit here.');
|
||||||
}
|
}
|
||||||
@@ -957,12 +989,31 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
if (!$this->action)
|
if (!$this->action)
|
||||||
parent::initProcess();
|
parent::initProcess();
|
||||||
|
|
||||||
|
// Set tab to display
|
||||||
if ($this->action)
|
if ($this->action)
|
||||||
{
|
{
|
||||||
if ($this->action == 'new')
|
if (in_array($this->action, $this->available_tabs))
|
||||||
$this->action = 'Informations';
|
$this->tab_display = $this->action;
|
||||||
return;
|
elseif ($this->action == 'new' || $this->action == 'save')
|
||||||
|
$this->tab_display = 'Informations';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set type of display (edit-add-list)
|
||||||
|
if (Tools::getValue('id_product')
|
||||||
|
|| ((Tools::isSubmit('submitAddproduct')
|
||||||
|
|| Tools::isSubmit('submitAddproductAndPreview')
|
||||||
|
|| Tools::isSubmit('submitAddproductAndStay')
|
||||||
|
|| Tools::isSubmit('submitSpecificPricePriorities')
|
||||||
|
|| Tools::isSubmit('submitPriceAddition')
|
||||||
|
|| Tools::isSubmit('submitPricesModification'))
|
||||||
|
&& count($this->_errors))
|
||||||
|
|| Tools::isSubmit('updateproduct')
|
||||||
|
|| Tools::isSubmit('addproduct'))
|
||||||
|
$this->display = 'edit';
|
||||||
|
elseif ($this->action == 'new')
|
||||||
|
$this->display = 'add';
|
||||||
|
else
|
||||||
|
$this->display = 'list';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -973,11 +1024,6 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
*/
|
*/
|
||||||
public function postProcess($token = null)
|
public function postProcess($token = null)
|
||||||
{
|
{
|
||||||
if ($this->action == 'attachments')
|
|
||||||
if ($id = (int)Tools::getValue($this->identifier))
|
|
||||||
if (Attachment::attachToProduct($id, Tools::getValue('attachments')))
|
|
||||||
$this->redirect_after = self::$currentIndex.'&id_product='.(int)$id.(isset($_POST['id_category']) ? '&id_category='.(int)$_POST['id_category'] : '').'&conf=4&add'.$this->table.'&action=Attachments&token='.($token ? $token : $this->token);
|
|
||||||
|
|
||||||
if (!$this->redirect_after)
|
if (!$this->redirect_after)
|
||||||
parent::postProcess(true);
|
parent::postProcess(true);
|
||||||
}
|
}
|
||||||
@@ -1763,42 +1809,27 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
|
|
||||||
public function initContent($token = null)
|
public function initContent($token = null)
|
||||||
{
|
{
|
||||||
if ($this->action == 'save')
|
|
||||||
$this->action = '';
|
|
||||||
|
|
||||||
// this is made to "save and stay" feature
|
// this is made to "save and stay" feature
|
||||||
$this->tpl_form_vars['show_product_tab_content'] = Tools::getValue('action');
|
$this->tpl_form_vars['show_product_tab_content'] = Tools::getValue('action');
|
||||||
if (Tools::getValue('id_product')
|
|
||||||
|| ((Tools::isSubmit('submitAddproduct')
|
if ($this->display == 'edit' || $this->display == 'add')
|
||||||
|| Tools::isSubmit('submitAddproductAndPreview')
|
|
||||||
|| Tools::isSubmit('submitAddproductAndStay')
|
|
||||||
|| Tools::isSubmit('submitSpecificPricePriorities')
|
|
||||||
|| Tools::isSubmit('submitPriceAddition')
|
|
||||||
|| Tools::isSubmit('submitPricesModification'))
|
|
||||||
&& count($this->_errors))
|
|
||||||
|| Tools::isSubmit('updateproduct')
|
|
||||||
|| Tools::isSubmit('addproduct'))
|
|
||||||
{
|
{
|
||||||
$this->addJS(_PS_JS_DIR_.'admin-products.js');
|
$this->addJS(_PS_JS_DIR_.'admin-products.js');
|
||||||
$this->fields_form = array();
|
$this->fields_form = array();
|
||||||
if (empty($this->action))
|
if (empty($this->tab_display))
|
||||||
$this->action = 'Informations';
|
$this->tab_display = 'Informations';
|
||||||
|
|
||||||
if(method_exists($this, 'initForm'.$this->action))
|
if(method_exists($this, 'initForm'.$this->tab_display))
|
||||||
$this->tpl_form = 'products/'.strtolower($this->action).'.tpl';
|
$this->tpl_form = 'products/'.strtolower($this->tab_display).'.tpl';
|
||||||
|
|
||||||
if ($this->ajax)
|
if ($this->ajax)
|
||||||
{
|
|
||||||
$this->display = 'edit';
|
|
||||||
$this->content_only = true;
|
$this->content_only = true;
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$product_tabs = array();
|
$product_tabs = array();
|
||||||
// action defines which tab to display first
|
// tab_display defines which tab to display first
|
||||||
$action = $this->action;
|
if (empty($this->tab_display) || !method_exists($this, 'initForm'.$this->tab_display))
|
||||||
if (empty($action) || !method_exists($this, 'initForm'.$action))
|
$this->tab_display = 'Informations';
|
||||||
$action = 'Informations';
|
|
||||||
|
|
||||||
// i is used as product_tab id
|
// i is used as product_tab id
|
||||||
$i = 0;
|
$i = 0;
|
||||||
@@ -1817,7 +1848,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
|
|
||||||
$product_tabs[$product_tab] = array(
|
$product_tabs[$product_tab] = array(
|
||||||
'id' => ++$i.'-'.$product_tab,
|
'id' => ++$i.'-'.$product_tab,
|
||||||
'selected' => (strtolower($product_tab) == strtolower($action)),
|
'selected' => (strtolower($product_tab) == strtolower($this->tab_display)),
|
||||||
'name' => $this->available_tabs_lang[$product_tab],
|
'name' => $this->available_tabs_lang[$product_tab],
|
||||||
'href' => $this->context->link->getAdminLink('AdminProducts').'&id_product='.Tools::getValue('id_product').'&action='.$product_tab,
|
'href' => $this->context->link->getAdminLink('AdminProducts').'&id_product='.Tools::getValue('id_product').'&action='.$product_tab,
|
||||||
);
|
);
|
||||||
@@ -1826,12 +1857,11 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$this->tpl_form_vars['product_tabs'] = $product_tabs;
|
$this->tpl_form_vars['product_tabs'] = $product_tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
$languages = Language::getLanguages(false);
|
/*$languages = Language::getLanguages(false);
|
||||||
$default_language = (int)Configuration::get('PS_LANG_DEFAULT');
|
$default_language = (int)Configuration::get('PS_LANG_DEFAULT');*/
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->display = 'list';
|
|
||||||
if ($id_category = (int)Tools::getValue('id_category'))
|
if ($id_category = (int)Tools::getValue('id_category'))
|
||||||
self::$currentIndex .= '&id_category='.$id_category;
|
self::$currentIndex .= '&id_category='.$id_category;
|
||||||
$this->getList($this->context->language->id, !$this->context->cookie->__get($this->table.'Orderby') ? 'position' : null, !$this->context->cookie->__get($this->table.'Orderway') ? 'ASC' : null, 0, null, $this->context->shop->getID(true));
|
$this->getList($this->context->language->id, !$this->context->cookie->__get($this->table.'Orderby') ? 'position' : null, !$this->context->cookie->__get($this->table.'Orderway') ? 'ASC' : null, 0, null, $this->context->shop->getID(true));
|
||||||
@@ -2000,7 +2030,7 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
$this->toolbar_btn['stats'] = array(
|
$this->toolbar_btn['stats'] = array(
|
||||||
'short' => 'Statistics',
|
'short' => 'Statistics',
|
||||||
'href' => $this->context->link->getAdminLink('AdminStats').'&module=statsproduct&id_product='.$product->id,
|
'href' => $this->context->link->getAdminLink('AdminStats').'&module=statsproduct&id_product='.$product->id,
|
||||||
'desc' => $this->l('View product sales'),
|
'desc' => $this->l('Product sales'),
|
||||||
);
|
);
|
||||||
|
|
||||||
// adding button for adding a new combination in Combinaition tab
|
// adding button for adding a new combination in Combinaition tab
|
||||||
@@ -2043,13 +2073,13 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initForm contains all necessary initialization needed for all tabs
|
* renderForm contains all necessary initialization needed for all tabs
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function renderForm()
|
public function renderForm()
|
||||||
{
|
{
|
||||||
if(!method_exists($this, 'initForm'.$this->action))
|
if(!method_exists($this, 'initForm'.$this->tab_display))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$this->addJqueryUI('ui.datepicker');
|
$this->addJqueryUI('ui.datepicker');
|
||||||
@@ -2076,11 +2106,11 @@ class AdminProductsControllerCore extends AdminController
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->_displayDraftWarning($this->object->active);
|
$this->_displayDraftWarning($this->object->active);
|
||||||
$this->{'initForm'.$this->action}($this->object, $languages, $default_language);
|
$this->{'initForm'.$this->tab_display}($this->object, $languages, $default_language);
|
||||||
$this->tpl_form_vars['product'] = $this->object;
|
$this->tpl_form_vars['product'] = $this->object;
|
||||||
if ($this->ajax)
|
if ($this->ajax)
|
||||||
if (!isset($this->tpl_form_vars['custom_form']))
|
if (!isset($this->tpl_form_vars['custom_form']))
|
||||||
throw new PrestashopException('custom_form empty for action '.$this->action);
|
throw new PrestashopException('custom_form empty for action '.$this->tab_display);
|
||||||
else
|
else
|
||||||
return $this->tpl_form_vars['custom_form'];
|
return $this->tpl_form_vars['custom_form'];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user