diff --git a/controllers/admin/AdminStockInstantStateController.php b/controllers/admin/AdminStockInstantStateController.php
index f0778133f..97f6a739e 100644
--- a/controllers/admin/AdminStockInstantStateController.php
+++ b/controllers/admin/AdminStockInstantStateController.php
@@ -25,80 +25,127 @@
* International Registered Trademark & Property of PrestaShop SA
*/
-class AdminStockInstantStateControllerCore extends AdminController
+class AdminStockInstantStateControllerCore extends AdminController
{
private $_default_order_by = 'id_product';
-
+
public function __construct()
{
- $this->table = 'stock';
- $this->className = 'Stock';
- $this->lang = false;
- $this->requiredDatabase = true;
-
- $this->deleted = 0;
-
$this->context = Context::getContext();
+ $this->table = 'stock';
+ $this->lang = false;
$this->fieldsDisplay = array(
- 'ean13' => array('title' => $this->l('EAN13'), 'width' => 110, 'widthColumn' => 110),
- 'reference' => array('title' => $this->l('Reference'), 'width' => 110, 'widthColumn' => 110, 'filter_key' => 'p!reference'),
- 'designation' => array('title' => $this->l('Product name'), 'filter_key' => 'designation', 'havingFilter' => true, 'width' => 300),
- 'physical_quantity' => array('title' => $this->l('Physical quantity'), 'align' => 'center', 'width' => 25, 'widthColumn' => 25, 'havingFilter' => true),
- 'price_te' => array('title' => $this->l('Price'), 'align' => 'center', 'width' => 45, 'widthColumn' => 45, 'havingFilter' => true),
- 'usable_quantity' => array('title' => $this->l('Usable quantity'), 'align' => 'center', 'width' => 25, 'widthColumn' => 25, 'havingFilter' => true),
- 'real_quantity' => array('title' => $this->l('Real quantity'), 'align' => 'center', 'width' => 25, 'widthColumn' => 25, 'filter' => false, 'search' => false, 'orderby' => false)
+ 'ean13' => array(
+ 'title' => $this->l('EAN13'),
+ 'width' => 110,
+ 'widthColumn' => 110
+ ),
+ 'reference' => array(
+ 'title' => $this->l('Reference'),
+ 'width' => 110,
+ 'widthColumn' => 110,
+ 'filter_key' => 'p!reference'
+ ),
+ 'designation' => array(
+ 'title' => $this->l('Product name'),
+ 'filter_key' => 'designation',
+ 'havingFilter' => true,
+ 'width' => 300
+ ),
+ 'price_te' => array(
+ 'title' => $this->l('Price'),
+ 'align' => 'center',
+ 'width' => 45,
+ 'widthColumn' => 45,
+ 'havingFilter' => true
+ ),
+ 'physical_quantity' => array(
+ 'title' => $this->l('Physical quantity'),
+ 'align' => 'center',
+ 'width' => 25,
+ 'widthColumn' => 25,
+ 'havingFilter' => true
+ ),
+ 'usable_quantity' => array(
+ 'title' => $this->l('Usable quantity'),
+ 'align' => 'center',
+ 'width' => 25,
+ 'widthColumn' => 25,
+ 'havingFilter' => true
+ ),
+ 'real_quantity' => array(
+ 'title' => $this->l('Real quantity'),
+ 'align' => 'center',
+ 'width' => 25,
+ 'widthColumn' => 25,
+ 'filter' => false,
+ 'search' => false,
+ 'orderby' => false
+ ),
);
- $this->display = 'list';
-
- $enabled = '
';
- $disabled = '
';
-
- $this->addRowAction('details');
-
parent::__construct();
}
-
+
+ /**
+ * AdminController::initList() override
+ * @see AdminController::initList()
+ */
+ public function initList()
+ {
+ $this->addRowAction('details');
+
+ //no link on list rows
+ $this->list_no_link = true;
+
+ $this->context->smarty->assign('list_warehouses', Warehouse::getWarehouseList(true));
+ $this->context->smarty->assign('current_warehouse', $this->getCurrentWarehouseId());
+
+ return parent::initList();
+ }
+
+ /**
+ * method call when ajax request is made with the details row action
+ * @see AdminController::postProcess()
+ */
public function ajaxProcess()
{
+ // get current lang id
+ $lang_id = (int)$this->context->language->id;
+
$query = 'SELECT physical_quantity, usable_quantity, s.price_te
- FROM '._DB_PREFIX_.'stock s
- INNER JOIN '._DB_PREFIX_.'product p
- ON (p.id_product = s.id_product)
- INNER JOIN '._DB_PREFIX_.'product_lang pl
- ON (pl.id_product = p.id_product AND pl.id_lang = 1)
- LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac
- ON (pac.id_product_attribute = s.id_product_attribute)
- LEFT JOIN '._DB_PREFIX_.'attribute a
- ON (a.id_attribute = pac.id_attribute)
- LEFT JOIN '._DB_PREFIX_.'attribute_lang al
- ON (al.id_attribute = a.id_attribute AND al.id_lang = 1)
- LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl
- ON (agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = 1)
- WHERE s.id_product = (SELECT id_product FROM '._DB_PREFIX_.'stock WHERE id_stock = '.(int)Tools::getValue('id').')
- AND s.id_product_attribute = (SELECT id_product_attribute FROM '._DB_PREFIX_.'stock WHERE id_stock = '.(int)Tools::getValue('id').')
- AND s.id_warehouse = (SELECT id_warehouse FROM '._DB_PREFIX_.'stock WHERE id_stock = '.(int)Tools::getValue('id').')
- GROUP BY id_stock';
-
+ FROM '._DB_PREFIX_.'stock s
+ INNER JOIN '._DB_PREFIX_.'product p
+ ON (p.id_product = s.id_product)
+ INNER JOIN '._DB_PREFIX_.'product_lang pl
+ ON (pl.id_product = p.id_product AND pl.id_lang = '.$lang_id.')
+ LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac
+ ON (pac.id_product_attribute = s.id_product_attribute)
+ LEFT JOIN '._DB_PREFIX_.'attribute a
+ ON (a.id_attribute = pac.id_attribute)
+ LEFT JOIN '._DB_PREFIX_.'attribute_lang al
+ ON (al.id_attribute = a.id_attribute AND al.id_lang = '.$lang_id.')
+ LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl
+ ON (agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = '.$lang_id.')
+ WHERE s.id_product = (SELECT id_product FROM '._DB_PREFIX_.'stock WHERE id_stock = '.(int)Tools::getValue('id').')
+ AND s.id_product_attribute = (SELECT id_product_attribute FROM '._DB_PREFIX_.'stock WHERE id_stock = '.(int)Tools::getValue('id').')
+ AND s.id_warehouse = (SELECT id_warehouse FROM '._DB_PREFIX_.'stock WHERE id_stock = '.(int)Tools::getValue('id').')
+ GROUP BY id_stock';
+
$data = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
+
foreach ($data as &$row)
$row['price_te'] = Tools::displayPrice($row['price_te'], $this->getCurrency());
+
echo Tools::jsonEncode(array(
- 'data'=> $data,
- 'fields_display' => $this->fieldsDisplay
+ 'data'=> $data,
+ 'fields_display' => $this->fieldsDisplay,
));
+
die();
}
-
- public function initContent()
- {
- $this->context->smarty->assign('warehouse_list', Warehouse::getWarehouseList());
- $this->context->smarty->assign('current_warehouse', $this->getCurrentWarehouseId());
-
- parent::initContent();
- }
-
+
protected function getCurrentWarehouseId()
{
static $warehouse = 0;
@@ -108,9 +155,10 @@ class AdminStockInstantStateControllerCore extends AdminController
if ((int)Tools::getValue('warehouse'))
$warehouse = (int)Tools::getValue('warehouse');
}
+
return $warehouse;
}
-
+
protected function getCurrency()
{
static $currency = null;
@@ -121,63 +169,83 @@ class AdminStockInstantStateControllerCore extends AdminController
}
return $currency;
}
+
+ /**
+ * AdminController::getList() override
+ * @see AdminController::getList()
+ */
public function getList($id_lang, $order_by = null, $order_way = null, $start = 0, $limit = null, $id_lang_shop = false)
{
- /* Manage default params values */
+ $id_lang = (int)$id_lang;
+
+ // Manage default params values
if (empty($limit))
- $limit = ((!isset($this->context->cookie->{$this->table.'_pagination'})) ? $this->_pagination[1] : $limit = $this->context->cookie->{$this->table.'_pagination'});
- $limit = (int)(Tools::getValue('pagination', $limit));
+ {
+ if (!isset($this->context->cookie->{$this->table.'_pagination'}))
+ $limit = $this->_pagination[1];
+ else
+ $limit = $this->context->cookie->{$this->table.'_pagination'};
+ }
+
+ $limit = (int)Tools::getValue('pagination', $limit);
$this->context->cookie->{$this->table.'_pagination'} = $limit;
-
-
+
if (!Validate::isTableOrIdentifier($this->table))
die (Tools::displayError('Table name is invalid:').' "'.$this->table.'"');
- if (empty($orderBy))
+ if (empty($order_by))
$order_by = $this->context->cookie->__get($this->table.'Orderby') ? $this->context->cookie->__get($this->table.'Orderby') : $this->_default_order_by;
- if (empty($orderWay))
+
+ if (empty($order_way))
$order_way = $this->context->cookie->__get($this->table.'Orderway') ? $this->context->cookie->__get($this->table.'Orderway') : 'ASC';
-
$query = 'SELECT SQL_CALC_FOUND_ROWS
- IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as designation,
- id_stock, p.id_product, s.id_product_attribute, ean13, p.reference,
- IF((count(DISTINCT id_stock)=1), s.price_te, \'--\') as price_te,
- IF((count(DISTINCT id_stock)=1), 0, 1) as need_details,
- CAST((SUM(physical_quantity) / (count(id_stock) - count(DISTINCT id_stock) + 1)) AS SIGNED INTEGER) AS physical_quantity,
- CAST((SUM(usable_quantity) / (count(id_stock) - count(DISTINCT id_stock) + 1)) AS SIGNED INTEGER) AS usable_quantity
- FROM '._DB_PREFIX_.'stock s
- INNER JOIN '._DB_PREFIX_.'product p
- ON (p.id_product = s.id_product)
- INNER JOIN '._DB_PREFIX_.'product_lang pl
- ON (pl.id_product = p.id_product AND pl.id_lang = 1)
- LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac
- ON (pac.id_product_attribute = s.id_product_attribute)
- LEFT JOIN '._DB_PREFIX_.'attribute a
- ON (a.id_attribute = pac.id_attribute)
- LEFT JOIN '._DB_PREFIX_.'attribute_lang al
- ON (al.id_attribute = a.id_attribute AND al.id_lang = 1)
- LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl
- ON (agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = 1)
- WHERE id_warehouse = '.$this->getCurrentWarehouseId().' '.(isset($this->_where) ? $this->_where.' ' : '').($this->deleted ? 'AND a.`deleted` = 0 ' : '').
- (isset($this->_filter) ? $this->_filter : '').'
- GROUP BY pac.id_product_attribute
- '.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').(isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').
- (isset($this->_having) ? $this->_having.' ' : '').'
- ORDER BY `'.pSQL($order_by).'` '.pSQL($order_way).'
- LIMIT '.(int)$start.','.(int)$limit;
+ IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as designation,
+ id_stock, p.id_product, s.id_product_attribute, ean13, p.reference,
+ IF((count(DISTINCT id_stock)=1), s.price_te, \'--\') as price_te,
+ IF((count(DISTINCT id_stock)=1), 0, 1) as need_details,
+ CAST((SUM(physical_quantity) / (count(id_stock) - count(DISTINCT id_stock) + 1)) AS SIGNED INTEGER) AS physical_quantity,
+ CAST((SUM(usable_quantity) / (count(id_stock) - count(DISTINCT id_stock) + 1)) AS SIGNED INTEGER) AS usable_quantity
+ FROM '._DB_PREFIX_.'stock s
+ INNER JOIN '._DB_PREFIX_.'product p
+ ON (p.id_product = s.id_product)
+ INNER JOIN '._DB_PREFIX_.'product_lang pl
+ ON (pl.id_product = p.id_product AND pl.id_lang = '.$id_lang.')
+ LEFT JOIN '._DB_PREFIX_.'product_attribute_combination pac
+ ON (pac.id_product_attribute = s.id_product_attribute)
+ LEFT JOIN '._DB_PREFIX_.'attribute a
+ ON (a.id_attribute = pac.id_attribute)
+ LEFT JOIN '._DB_PREFIX_.'attribute_lang al
+ ON (al.id_attribute = a.id_attribute AND al.id_lang = '.$id_lang.')
+ LEFT JOIN '._DB_PREFIX_.'attribute_group_lang agl
+ ON (agl.id_attribute_group = a.id_attribute_group AND agl.id_lang = '.$id_lang.')
+ WHERE id_warehouse = '.$this->getCurrentWarehouseId().' '.(isset($this->_where) ? $this->_where.' ' : '').
+ ($this->deleted ? 'AND a.`deleted` = 0 ' : '').
+ (isset($this->_filter) ? $this->_filter : '').'
+ GROUP BY pac.id_product_attribute
+ '.((isset($this->_filterHaving) || isset($this->_having)) ? 'HAVING ' : '').
+ (isset($this->_filterHaving) ? ltrim($this->_filterHaving, ' AND ') : '').
+ (isset($this->_having) ? $this->_having.' ' : '').'
+ ORDER BY `'.pSQL($order_by).'` '.pSQL($order_way).'
+ LIMIT '.(int)$start.','.(int)$limit;
$this->_list = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
$manager = StockManagerFactory::getManager();
-
+
foreach ($this->_list as &$row)
{
if (is_numeric($row['price_te']))
$row['price_te'] = Tools::displayPrice($row['price_te'], $this->getCurrency());
if (!$row['need_details'])
$this->addRowActionSkipList('details', $row['id_stock']);
- $row['real_quantity'] = $manager->getProductRealQuantities($row['id_product'], $row['id_product_attribute'], array($this->getCurrentWarehouseId()), true);
+ $row['real_quantity'] = $manager->getProductRealQuantities(
+ $row['id_product'],
+ $row['id_product_attribute'],
+ array($this->getCurrentWarehouseId()),
+ true
+ );
}
+
$this->_listTotal = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT FOUND_ROWS()');
}
}