[-] BO : #PSTEST-400 - Change the working of the button "Save and stay" for attributes and features
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@12386 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -701,7 +701,7 @@ class AdminControllerCore extends Controller
|
|||||||
$this->errors[] = Tools::displayError('An error occurred while updating object.').
|
$this->errors[] = Tools::displayError('An error occurred while updating object.').
|
||||||
' <b>'.$this->table.'</b> ('.Db::getInstance()->getMsgError().')';
|
' <b>'.$this->table.'</b> ('.Db::getInstance()->getMsgError().')';
|
||||||
}
|
}
|
||||||
else if ($this->postImage($object->id) && !count($this->errors))
|
else if ($this->postImage($object->id) && !count($this->errors) && $this->_redirect)
|
||||||
{
|
{
|
||||||
$parent_id = (int)Tools::getValue('id_parent', 1);
|
$parent_id = (int)Tools::getValue('id_parent', 1);
|
||||||
// Specific back redirect
|
// Specific back redirect
|
||||||
|
|||||||
@@ -357,6 +357,30 @@ class AdminAttributesGroupsControllerCore extends AdminController
|
|||||||
parent::init();
|
parent::init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override processAdd to change SaveAndStay button action
|
||||||
|
* @see classes/AdminControllerCore::processUpdate()
|
||||||
|
*/
|
||||||
|
public function processAdd($token)
|
||||||
|
{
|
||||||
|
parent::processAdd($token);
|
||||||
|
|
||||||
|
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay') && !count($this->errors))
|
||||||
|
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'=&conf=3&update'.$this->table.'&token='.$token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override processUpdate to change SaveAndStay button action
|
||||||
|
* @see classes/AdminControllerCore::processUpdate()
|
||||||
|
*/
|
||||||
|
public function processUpdate($token)
|
||||||
|
{
|
||||||
|
parent::processUpdate($token);
|
||||||
|
|
||||||
|
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay') && !count($this->errors))
|
||||||
|
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'=&conf=3&update'.$this->table.'&token='.$token;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AdminController::initContent() override
|
* AdminController::initContent() override
|
||||||
* @see AdminController::initContent()
|
* @see AdminController::initContent()
|
||||||
@@ -483,9 +507,8 @@ class AdminAttributesGroupsControllerCore extends AdminController
|
|||||||
*/
|
*/
|
||||||
public function processSave($token)
|
public function processSave($token)
|
||||||
{
|
{
|
||||||
if ((int)Tools::getValue('id_attribute') <= 0 && $this->display != 'add'
|
if ((int)Tools::getValue('id_attribute') <= 0 && $this->display == 'add'
|
||||||
|| (int)Tools::getValue('id_attribute_group') <= 0 && $this->display == 'add'
|
|| (int)Tools::getValue('id_attribute_group') <= 0 && $this->display != 'add')
|
||||||
)
|
|
||||||
return $this->processAdd($token);
|
return $this->processAdd($token);
|
||||||
else
|
else
|
||||||
return $this->processUpdate($token);
|
return $this->processUpdate($token);
|
||||||
|
|||||||
@@ -199,11 +199,19 @@ class AdminFeaturesControllerCore extends AdminController
|
|||||||
switch ($this->display)
|
switch ($this->display)
|
||||||
{
|
{
|
||||||
case 'editFeatureValue':
|
case 'editFeatureValue':
|
||||||
|
case 'add':
|
||||||
|
case 'edit':
|
||||||
$this->toolbar_btn['save'] = array(
|
$this->toolbar_btn['save'] = array(
|
||||||
'href' => '#',
|
'href' => '#',
|
||||||
'desc' => $this->l('Save')
|
'desc' => $this->l('Save')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->toolbar_btn['save-and-stay'] = array(
|
||||||
|
'short' => 'SaveAndStay',
|
||||||
|
'href' => '#',
|
||||||
|
'desc' => $this->l('Save and stay'),
|
||||||
|
);
|
||||||
|
|
||||||
// Default cancel button - like old back link
|
// Default cancel button - like old back link
|
||||||
$back = Tools::safeOutput(Tools::getValue('back', ''));
|
$back = Tools::safeOutput(Tools::getValue('back', ''));
|
||||||
if (empty($back))
|
if (empty($back))
|
||||||
@@ -226,6 +234,10 @@ class AdminFeaturesControllerCore extends AdminController
|
|||||||
*/
|
*/
|
||||||
public function initFormFeatureValue()
|
public function initFormFeatureValue()
|
||||||
{
|
{
|
||||||
|
$this->table = 'feature_value';
|
||||||
|
$this->className = 'FeatureValue';
|
||||||
|
$this->identifier = 'id_feature_value';
|
||||||
|
|
||||||
$this->fields_form[0]['form'] = array(
|
$this->fields_form[0]['form'] = array(
|
||||||
'legend' => array(
|
'legend' => array(
|
||||||
'title' => $this->l('Feature value'),
|
'title' => $this->l('Feature value'),
|
||||||
@@ -368,8 +380,12 @@ class AdminFeaturesControllerCore extends AdminController
|
|||||||
else
|
else
|
||||||
$this->errors[] = Tools::displayError('You do not have permission to delete here.');
|
$this->errors[] = Tools::displayError('You do not have permission to delete here.');
|
||||||
}
|
}
|
||||||
else if (Tools::isSubmit('submitAddfeature_value'))
|
else if (Tools::isSubmit('submitAddfeature_value') || Tools::isSubmit('submitAddfeature_valueAndStay'))
|
||||||
{
|
{
|
||||||
|
$this->table = 'feature_value';
|
||||||
|
$this->className = 'FeatureValue';
|
||||||
|
$this->identifier = 'id_feature_value';
|
||||||
|
|
||||||
$id = (int)Tools::getValue('id_feature_value');
|
$id = (int)Tools::getValue('id_feature_value');
|
||||||
$feature_value = new FeatureValue($id);
|
$feature_value = new FeatureValue($id);
|
||||||
$feature_value->value = array();
|
$feature_value->value = array();
|
||||||
@@ -383,12 +399,17 @@ class AdminFeaturesControllerCore extends AdminController
|
|||||||
$feature_value->id_feature = Tools::getValue('id_feature');
|
$feature_value->id_feature = Tools::getValue('id_feature');
|
||||||
|
|
||||||
if (count($this->errors) > 0)
|
if (count($this->errors) > 0)
|
||||||
return false;
|
{
|
||||||
|
$this->display = 'editFeatureValue';
|
||||||
|
parent::postProcess();
|
||||||
|
}
|
||||||
else if (isset($id) && !empty($id))
|
else if (isset($id) && !empty($id))
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
if (!$feature_value->update())
|
if (!$feature_value->update())
|
||||||
$this->errors[] = Tools::displayError('An error has occured: Can\'t save the current feature value');
|
$this->errors[] = Tools::displayError('An error has occured: Can\'t save the current feature value');
|
||||||
|
else if (Tools::isSubmit('submitAdd'.$this->table.'AndStay') && !count($this->errors))
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'=&conf=3&update'.$this->table.'&token='.$this->token);
|
||||||
else
|
else
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token);
|
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token);
|
||||||
}
|
}
|
||||||
@@ -397,6 +418,8 @@ class AdminFeaturesControllerCore extends AdminController
|
|||||||
// Create
|
// Create
|
||||||
if (!$feature_value->add())
|
if (!$feature_value->add())
|
||||||
$this->errors[] = Tools::displayError('An error has occured: Can\'t save the current feature value');
|
$this->errors[] = Tools::displayError('An error has occured: Can\'t save the current feature value');
|
||||||
|
else if (Tools::isSubmit('submitAdd'.$this->table.'AndStay') && !count($this->errors))
|
||||||
|
Tools::redirectAdmin(self::$currentIndex.'&'.$this->identifier.'=&conf=3&update'.$this->table.'&token='.$this->token);
|
||||||
else
|
else
|
||||||
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token);
|
Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token);
|
||||||
}
|
}
|
||||||
@@ -451,4 +474,43 @@ class AdminFeaturesControllerCore extends AdminController
|
|||||||
parent::postProcess();
|
parent::postProcess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override processAdd to change SaveAndStay button action
|
||||||
|
* @see classes/AdminControllerCore::processAdd()
|
||||||
|
*/
|
||||||
|
public function processAdd($token)
|
||||||
|
{
|
||||||
|
parent::processAdd($token);
|
||||||
|
|
||||||
|
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay') && !count($this->errors))
|
||||||
|
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'=&conf=3&update'.$this->table.'&token='.$token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Override processUpdate to change SaveAndStay button action
|
||||||
|
* @see classes/AdminControllerCore::processUpdate()
|
||||||
|
*/
|
||||||
|
public function processUpdate($token)
|
||||||
|
{
|
||||||
|
parent::processUpdate($token);
|
||||||
|
|
||||||
|
if (Tools::isSubmit('submitAdd'.$this->table.'AndStay') && !count($this->errors))
|
||||||
|
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'=&conf=3&update'.$this->table.'&token='.$token;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call the right method for creating or updating object
|
||||||
|
*
|
||||||
|
* @param $token
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function processSave($token)
|
||||||
|
{
|
||||||
|
if ((int)Tools::getValue('id_feature_value') <= 0 && $this->display == 'add'
|
||||||
|
|| (int)Tools::getValue('id_feature') <= 0 && $this->display != 'add')
|
||||||
|
return $this->processAdd($token);
|
||||||
|
else
|
||||||
|
return $this->processUpdate($token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user