diff --git a/module/product/control.php b/module/product/control.php
index 9a42ce8a53..c2b475cd9d 100644
--- a/module/product/control.php
+++ b/module/product/control.php
@@ -47,7 +47,7 @@ class product extends control
* @access public
* @return void
*/
- public function index($locate = 'yes', $productID = 0, $orderBy = 'code_asc', $recTotal = 0, $recPerPage = 10, $pageID = 1)
+ public function index($locate = 'yes', $productID = 0, $orderBy = 'order_asc', $recTotal = 0, $recPerPage = 10, $pageID = 1)
{
if($locate == 'yes') $this->locate($this->createLink($this->moduleName, 'browse'));
@@ -529,7 +529,7 @@ class product extends control
$this->view->module = $module;
$this->view->method = $method;
$this->view->extra = $extra;
- $this->view->products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('id')->in(array_keys($this->products))->orderBy('code')->fetchAll();
+ $this->view->products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('id')->in(array_keys($this->products))->orderBy('`order`')->fetchAll();
$this->display();
}
@@ -545,7 +545,7 @@ class product extends control
*/
public function ajaxGetMatchedItems($keywords, $module, $method, $extra)
{
- $products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('deleted')->eq(0)->andWhere('name')->like("%$keywords%")->orderBy('code')->fetchAll();
+ $products = $this->dao->select('*')->from(TABLE_PRODUCT)->where('deleted')->eq(0)->andWhere('name')->like("%$keywords%")->orderBy('`order`')->fetchAll();
foreach($products as $key => $product)
{
if(!$this->product->checkPriv($product)) unset($products[$key]);
@@ -556,4 +556,25 @@ class product extends control
$this->view->keywords = $keywords;
$this->display();
}
+
+ /**
+ * Ajax order.
+ *
+ * @access public
+ * @return void
+ */
+ public function ajaxOrder()
+ {
+ $idList = explode(',', trim($this->post->products, ','));
+ $orderBy = $this->post->orderBy;
+ if(strpos($orderBy, 'order') === false) return false;
+
+ $products = $this->dao->select('id,`order`')->from(TABLE_PRODUCT)->where('id')->in($idList)->orderBy($orderBy)->fetchPairs('order', 'id');
+ foreach($products as $order => $id)
+ {
+ $newID = array_shift($idList);
+ if($id == $newID) continue;
+ $this->dao->update(TABLE_PRODUCT)->set('`order`')->eq($order)->where('id')->eq($newID)->exec();
+ }
+ }
}
diff --git a/module/product/js/index.js b/module/product/js/index.js
index df7cd88c73..db9a024a2b 100644
--- a/module/product/js/index.js
+++ b/module/product/js/index.js
@@ -3,5 +3,8 @@ $(function()
$('#productTableList').on('sort.sortable', function(e, data)
{
// TODO: save order to server.
+ var list = '';
+ for(i = 0; i < data.list.length; i++) list += $(data.list[i]).find('td').eq(1).find('input').val() + ',';
+ $.post(createLink('product', 'ajaxOrder'), {'products' : list, 'orderBy' : orderBy});
});
});
diff --git a/module/product/model.php b/module/product/model.php
index 9c4ea820c2..59b3685928 100644
--- a/module/product/model.php
+++ b/module/product/model.php
@@ -135,7 +135,7 @@ class productModel extends model
->beginIF($status = 'noclosed')->andWhere('status')->ne('closed')->fi()
->beginIF($status != 'all' and $status != 'noclosed')->andWhere('status')->in($status)->fi()
->beginIF($limit > 0)->limit($limit)->fi()
- ->orderBy('code')
+ ->orderBy('`order`')
->fetchAll('id');
}
@@ -461,7 +461,7 @@ class productModel extends model
* @access public
* @return array
*/
- public function getStats($orderBy = 'code_asc', $pager = null)
+ public function getStats($orderBy = 'order_asc', $pager = null)
{
$this->loadModel('report');
$this->loadModel('story');
diff --git a/module/product/view/index.html.php b/module/product/view/index.html.php
index 2c9926a05c..1088f7b276 100644
--- a/module/product/view/index.html.php
+++ b/module/product/view/index.html.php
@@ -36,7 +36,9 @@
recTotal}&recPerPage={$pager->recPerPage}&pageID={$pager->pageID}";?>
- ');?>
+
+ ');?>
+
idAB);?>
product->name);?>
story->statusList['active'] . $lang->story->common;?>
@@ -54,7 +56,9 @@