// Add currency to the warehouse - optimisation of form, list and option init in AdminController - list bug fix on StockManager

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9448 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
dSevere
2011-10-19 11:11:30 +00:00
parent af8cac9d64
commit 382f4678bf
3 changed files with 295 additions and 24 deletions
+30
View File
@@ -1014,6 +1014,9 @@ class AdminControllerCore extends Controller
if (!($obj = $this->loadObject(true)))
return;
// init form declaration
$this->initForm();
if (isset($this->fields_form))
{
$this->getlanguages();
@@ -1045,6 +1048,9 @@ class AdminControllerCore extends Controller
}
else if ($this->display == 'list')
{
// init list declaration
$this->initList();
$this->getList($this->context->language->id);
$helper = new HelperList();
@@ -1084,6 +1090,9 @@ class AdminControllerCore extends Controller
}
else if ($this->display == 'options')
{
// init options declaration
$this->initOptions();
$helper = new HelperOptions();
$this->content .= $helper->generateOptions();
}
@@ -1109,6 +1118,27 @@ class AdminControllerCore extends Controller
));
}
/**
* Function used to initialise the list to display for this controller
*/
public function initList()
{
}
/**
* Function used to initialise the form to display for this controller
*/
public function initForm()
{
}
/**
* Function used to initialise the options to display for this controller
*/
public function initOptions()
{
}
public function setMedia()
{
$this->addCSS(_PS_CSS_DIR_.'admin.css', 'all');
@@ -43,19 +43,57 @@ class AdminStockManagementController extends AdminController
$this->addRowAction('transferstock');
$this->fieldsDisplay = array(
'reference' => array('title' => $this->l('Reference'), 'align' => 'center', 'width' => 100, 'widthColumn' => 150),
'ean13' => array('title' => $this->l('EAN13'), 'align' => 'center', 'width' => 75, 'widthColumn' => 100),
'name' => array('title' => $this->l('Name'), 'width' => 350, 'widthColumn' => 'auto', 'filter_key' => 'b!name'),
'stock' => array('title' => $this->l('Total quantities in stock'), 'width' => 50, 'widthColumn' => 60),
'reference' => array(
'title' => $this->l('Reference'),
'align' => 'center',
'width' => 100,
'widthColumn' => 150
),
'ean13' => array(
'title' => $this->l('EAN13'),
'align' => 'center',
'width' => 75,
'widthColumn' => 100
),
'name' => array(
'title' => $this->l('Name'),
'width' => 350,
'widthColumn' => 'auto',
'filter_key' => 'b!name'
),
'stock' => array(
'title' => $this->l('Total quantities in stock'),
'width' => 50,
'widthColumn' => 60,
'orderby' => false,
'filter' => false,
'search' => false,
),
);
$this->_select = 'a.id_product as id, COUNT(pa.id_product_attribute) as variations';
$this->_join = 'LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.id_product = a.id_product)';
// Manage specific forms for stock management
$this->declareStockManagementForms();
parent::__construct();
}
/**
* init override
*/
public function init()
{
parent::init();
if (isset($_GET['addstock']))
{
$this->action = 'addstock';
$this->display = 'addstock';
}
}
/**
* method call when ajax request is made with the details row action
*/
@@ -64,10 +102,10 @@ class AdminStockManagementController extends AdminController
// test if an id is submit
if (Tools::isSubmit('id'))
{
// desactivate lang gestion
// desactivate native lang gestion of the controller
$this->lang = false;
// get lang id
// get current lang id
$lang_id = (int)$this->context->language->id;
// Get product id
@@ -159,7 +197,7 @@ class AdminStockManagementController extends AdminController
/**
* Check stock for a given product or product attribute
* and manage action available in consequence
* and manage available actions in consequence
*
* @param array $item reference to the current item
* @param bool $is_product_attribute specify if it's a product or a product variation
@@ -185,15 +223,198 @@ class AdminStockManagementController extends AdminController
}
}
private function declareStockManagementForms() {
$this->stock_management_forms['addstock'] = array(
'legend' => array(
'title' => $this->l('Warehouse'),
'image' => '../img/admin/tab.gif'
),
'input' => array(
array(
'type' => 'hidden',
'name' => 'id_address',
),
array(
'type' => 'text',
'label' => $this->l('Reference:'),
'name' => 'reference',
'size' => 30,
'maxlength' => 32,
'required' => true,
'p' => $this->l('Code / Reference of this warehouse'),
),
array(
'type' => 'text',
'label' => $this->l('Name:'),
'name' => 'name',
'size' => 40,
'maxlength' => 45,
'required' => true,
'p' => $this->l('Name of this warehouse')
),
array(
'type' => 'text',
'label' => $this->l('Phone:'),
'name' => 'phone',
'size' => 15,
'maxlength' => 16,
'p' => $this->l('Phone number of this warehouse')
),
array(
'type' => 'text',
'label' => $this->l('Adress:'),
'name' => 'address',
'size' => 100,
'maxlength' => 128,
'required' => true
),
array(
'type' => 'text',
'label' => $this->l('Adress:').' (2)',
'name' => 'address2',
'size' => 100,
'maxlength' => 128,
),
array(
'type' => 'text',
'label' => $this->l('Postcode/ Zip Code:'),
'name' => 'postcode',
'size' => 10,
'maxlength' => 12,
'required' => true,
),
array(
'type' => 'text',
'label' => $this->l('City:'),
'name' => 'city',
'size' => 10,
'maxlength' => 12,
'required' => true,
),
array(
'type' => 'select',
'label' => $this->l('Country:'),
'name' => 'id_country',
'required' => true,
'options' => array(
'query' => Country::getCountries($this->context->language->id, false),
'id' => 'id_country',
'name' => 'name'
),
'p' => $this->l('Country where state, region or city is located')
),
array(
'type' => 'select',
'label' => $this->l('State'),
'name' => 'id_state',
'required' => true,
'options' => array(
'id' => 'id_state',
'name' => 'name'
)
),
array(
'type' => 'select',
'label' => $this->l('Management type:'),
'name' => 'management_type',
'required' => true,
'options' => array(
'query' => array(
array(
'id' => 'WA',
'name' => $this->l('Weight Average')
),
array(
'id' => 'FIFO',
'name' => $this->l('First In, First Out')
),
array(
'id' => 'LIFO',
'name' => $this->l('Last In, First Out')
),
),
'id' => 'id',
'name' => 'name'
),
'p' => $this->l('Onventory valuation method'),
'hint' => $this->l('Do not change this value before the end of the accounting period for this Warehouse.'),
),
array(
'type' => 'select',
'label' => $this->l('Associated shops:'),
'name' => 'ids_shops[]',
'required' => true,
'multiple' => true,
'options' => array(
'query' => Shop::getShops(),
'id' => 'id_shop',
'name' => 'name'
),
'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'),
),
array(
'type' => 'select',
'label' => $this->l('Associated carriers:'),
'name' => 'ids_carriers[]',
'required' => true,
'multiple' => true,
'options' => array(
'query' => Carrier::getCarriers($this->context->language->id, true),
'id' => 'id_carrier',
'name' => 'name'
),
'p' => $this->l('Associated carrier'),
'hint' => $this->l('You can specifiy the carriers availables for shipping orders from this warehouse'),
),
),
'submit' => array(
'title' => $this->l(' Save '),
'class' => 'button'
)
);
}
/**
* initContent override
*/
public function initContent()
{
if ($this->display != 'edit' && $this->display != 'add')
if ($this->display != 'addstock')
$this->display = 'list';
parent::initContent();
if ($this->display == 'addstock')
{
$this->fields_form = $this->stock_management_forms['addstock'];
$this->getlanguages();
$helper = new HelperForm();
// Check if form template has been overriden
if (file_exists($this->context->smarty->template_dir.'/'.$this->tpl_folder.'form.tpl'))
$helper->tpl = $this->tpl_folder.'form.tpl';
$helper->currentIndex = self::$currentIndex;
$helper->token = $this->token;
$helper->table = $this->table;
$helper->id = $obj->id;
$helper->languages = $this->_languages;
$helper->default_form_language = $this->default_form_language;
$helper->allow_employee_form_lang = $this->allow_employee_form_lang;
$helper->fields_value = $this->getFieldsValue($obj);
$this->content .= $helper->generateForm($this->fields_form);
if ($this->tabAccess['view'])
{
if (Tools::getValue('back'))
$this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue('back')));
else
$this->context->smarty->assign('back', Tools::safeOutput(Tools::getValue(self::$currentIndex.'&token='.$this->token)));
}
}
}
/**
+35 -15
View File
@@ -37,6 +37,11 @@ class AdminWarehousesControllerCore extends AdminController
$this->context = Context::getContext();
$this->lang = false;
parent::__construct();
}
public function initList()
{
$this->addRowAction('edit');
$this->fieldsDisplay = array(
@@ -74,7 +79,10 @@ class AdminWarehousesControllerCore extends AdminController
$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_.'country` c ON (c.id_country = ad.id_country)';
}
public function initForm()
{
// Get employee list for warehouse manager
$query = new DbQuery();
$query->select('id_employee, CONCAT(lastname," ",firstname) as name');
@@ -181,7 +189,6 @@ class AdminWarehousesControllerCore extends AdminController
'id' => 'id_employee',
'name' => 'name'
),
'p' => $this->l('Manager of this warehouse')
),
array(
'type' => 'select',
@@ -206,7 +213,19 @@ class AdminWarehousesControllerCore extends AdminController
'id' => 'id',
'name' => 'name'
),
'p' => $this->l('Onventory valuation method'),
'p' => $this->l('Inventory valuation method'),
'hint' => $this->l('Do not change this value before the end of the accounting period for this Warehouse.'),
),
array(
'type' => 'select',
'label' => $this->l('Stock valuation currency:'),
'name' => 'id_currency',
'required' => true,
'options' => array(
'query' => Currency::getCurrencies(),
'id' => 'id_currency',
'name' => 'name'
),
'hint' => $this->l('Do not change this value before the end of the accounting period for this Warehouse.'),
),
array(
@@ -243,8 +262,6 @@ class AdminWarehousesControllerCore extends AdminController
'class' => 'button'
)
);
parent::__construct();
}
public function postProcess()
@@ -306,6 +323,7 @@ class AdminWarehousesControllerCore extends AdminController
return;
//load current address for this warehouse if possible
$address = null;
if ($obj->id_address > 0)
$address = new Address($obj->id_address);
@@ -316,17 +334,19 @@ class AdminWarehousesControllerCore extends AdminController
$carriers = $obj->getCarriers();
//force specific fields values
$this->fields_value = array(
'phone' => $address->phone,
'address' => $address->address1,
'address2' => $address->address2,
'postcode' => $address->postcode,
'city' => $address->city,
'id_country' => $address->id_country,
'id_state' => $address->id_state,
'ids_shops[]' => $shops,
'ids_carriers[]' => $carriers,
);
if ($address != null)
$this->fields_value = array(
'phone' => $address->phone,
'address' => $address->address1,
'address2' => $address->address2,
'postcode' => $address->postcode,
'city' => $address->city,
'id_country' => $address->id_country,
'id_state' => $address->id_state,
);
$this->fields_value['ids_shops[]'] = $shops;
$this->fields_value['ids_carriers[]'] = $carriers;
}
parent::initContent();