// edit form debug (address creation/update) and adaptations for new adminController initList system

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9560 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dSevere committed 2011-10-21 15:10:23 +00:00
1 parent ec4b71b2b7
commit ba09ad8613
1 file changed
+75 -67
+75 -67
View File
@@ -37,13 +37,6 @@ class AdminWarehousesControllerCore extends AdminController
$this->context = Context::getContext(); $this->context = Context::getContext();
$this->lang = false; $this->lang = false;
parent::__construct();
}
public function initList()
{
$this->addRowAction('edit');
$this->fieldsDisplay = array( $this->fieldsDisplay = array(
'reference' => array( 'reference' => array(
'title' => $this->l('Reference'), 'title' => $this->l('Reference'),
@@ -73,8 +66,19 @@ class AdminWarehousesControllerCore extends AdminController
), ),
); );
parent::__construct();
}
/**
* AdminController::initList() override
* @see AdminController::initList()
*/
public function initList()
{
$this->addRowAction('edit');
$this->_select = 'reference, name, management_type, CONCAT(e.lastname, \' \', e.firstname) AS employee, $this->_select = 'reference, name, management_type, CONCAT(e.lastname, \' \', e.firstname) AS employee,
ad.phone AS contact, CONCAT(ad.city, \' \', c.iso_code) location'; ad.phone AS contact, CONCAT(ad.city, \' - \', c.iso_code) location';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee) $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = a.id_employee)
LEFT JOIN `'._DB_PREFIX_.'address` ad ON (ad.id_address = a.id_address) LEFT JOIN `'._DB_PREFIX_.'address` ad ON (ad.id_address = a.id_address)
@@ -83,6 +87,10 @@ class AdminWarehousesControllerCore extends AdminController
return parent::initList(); return parent::initList();
} }
/**
* AdminController::initForm() override
* @see AdminController::initForm()
*/
public function initForm() public function initForm()
{ {
// Get employee list for warehouse manager // Get employee list for warehouse manager
@@ -242,7 +250,8 @@ class AdminWarehousesControllerCore extends AdminController
'name' => 'name' 'name' => 'name'
), ),
'p' => $this->l('Associated shops'), 'p' => $this->l('Associated shops'),
'hint' => $this->l('By associating a shop to a warehouse, all products in this warehouse will be available for sale in the associated shop. Shipment of an order of this shop is also possible from this warehouse'), 'hint' => $this->l('By associating a shop to a warehouse, all products in this warehouse will be available
for sale in the associated shop. Shipment of an order of this shop is also possible from this warehouse'),
), ),
array( array(
'type' => 'select', 'type' => 'select',
@@ -265,63 +274,6 @@ class AdminWarehousesControllerCore extends AdminController
) )
); );
return parent::initForm();
}
public function postProcess()
{
if (Tools::isSubmit('submitAdd'.$this->table))
{
if (!($obj = $this->loadObject(true)))
return;
//handle shops associations
if (Tools::isSubmit('ids_shops'))
$obj->setShops(Tools::getValue('ids_shops'));
//handle carriers associations
if (Tools::isSubmit('ids_carriers'))
$obj->setCarriers(Tools::getValue('ids_carriers'));
// update/create address if not exists
if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0)
//update address
$address = new Address((int)Tools::getValue('id_address'));
else
//create address
$address = new Address();
$address->alias = Tools::getValue('name');
$address->lastname = Tools::getValue('name');
$address->firstname = Tools::getValue('name');
$address->address1 = Tools::getValue('address');
$address->address2 = Tools::getValue('address2');
$address->postcode = Tools::getValue('postcode');
$address->phone = Tools::getValue('phone');
$address->id_country = Tools::getValue('id_country');
$address->id_state = Tools::getValue('id_state');
$address->city = Tools::getValue('city');
if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0)
{
//update address
$address->update();
}
else {
$address->save();
$_POST['id_address'] = $address->id;
}
}
return parent::postProcess();
}
public function initContent()
{
if ($this->display != 'edit' && $this->display != 'add')
$this->display = 'list';
else
{
//loas current warehouse //loas current warehouse
if (!($obj = $this->loadObject(true))) if (!($obj = $this->loadObject(true)))
return; return;
@@ -351,8 +303,64 @@ class AdminWarehousesControllerCore extends AdminController
$this->fields_value['ids_shops[]'] = $shops; $this->fields_value['ids_shops[]'] = $shops;
$this->fields_value['ids_carriers[]'] = $carriers; $this->fields_value['ids_carriers[]'] = $carriers;
return parent::initForm();
} }
parent::initContent(); /**
* AdminController::postProcess() override
* @see AdminController::postProcess()
*/
public function postProcess()
{
if (Tools::isSubmit('submitAdd'.$this->table))
{
if (!($obj = $this->loadObject(true)))
return;
//handle shops associations
if (Tools::isSubmit('ids_shops'))
$obj->setShops(Tools::getValue('ids_shops'));
//handle carriers associations
if (Tools::isSubmit('ids_carriers'))
$obj->setCarriers(Tools::getValue('ids_carriers'));
// update/create address if not exists
if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0)
//update address
$address = new Address((int)Tools::getValue('id_address'));
else
//create address
$address = new Address();
$address->alias = Tools::getValue('name', null);
$address->lastname = Tools::getValue('name', null);
$address->firstname = Tools::getValue('name', null);
$address->address1 = Tools::getValue('address', null);
$address->address2 = Tools::getValue('address2', null);
$address->postcode = Tools::getValue('postcode', null);
$address->phone = Tools::getValue('phone', null);
$address->id_country = Tools::getValue('id_country', null);
$address->id_state = Tools::getValue('id_state', null);
$address->city = Tools::getValue('city', null);
// check address validity
if (!$address->validateFields(false))
$this->_errors[] = Tools::displayError('The address is not correct. Check if all required fields are filled.');
else
{
if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0)
$address->update();
else
{
$address->save();
$_POST['id_address'] = $address->id;
} }
}
}
return parent::postProcess();
}
} }