PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/data/class/pages/admin/products/LC_Page_Admin_Products_ProductSelect.php

https://gitlab.com/raku.takayama/eccube-2_13
PHP | 166 lines | 84 code | 20 blank | 62 comment | 6 complexity | 920241e558ea66f147063c80f8954fea MD5 | raw file
  1. <?php
  2. /*
  3. * This file is part of EC-CUBE
  4. *
  5. * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved.
  6. *
  7. * http://www.lockon.co.jp/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
  24. /**
  25. * 商品選択 のページクラス.
  26. *
  27. * @package Page
  28. * @author LOCKON CO.,LTD.
  29. * @version $Id$
  30. */
  31. class LC_Page_Admin_Products_ProductSelect extends LC_Page_Admin_Ex
  32. {
  33. /**
  34. * Page を初期化する.
  35. *
  36. * @return void
  37. */
  38. public function init()
  39. {
  40. parent::init();
  41. $this->tpl_mainpage = 'products/product_select.tpl';
  42. $this->tpl_mainno = 'products';
  43. $this->tpl_subno = '';
  44. $this->tpl_maintitle = '商品管理';
  45. $this->tpl_subtitle = '商品選択';
  46. $masterData = new SC_DB_MasterData_Ex();
  47. $this->arrPRODUCTSTATUS_COLOR = $masterData->getMasterData('mtb_product_status_color');
  48. }
  49. /**
  50. * Page のプロセス.
  51. *
  52. * @return void
  53. */
  54. public function process()
  55. {
  56. $this->action();
  57. $this->sendResponse();
  58. }
  59. /**
  60. * Page のアクション.
  61. *
  62. * @return void
  63. */
  64. public function action()
  65. {
  66. $objDb = new SC_Helper_DB_Ex();
  67. $objFormParam = new SC_FormParam_Ex();
  68. $this->lfInitParam($objFormParam);
  69. $objFormParam->setParam($_POST);
  70. $objFormParam->convParam();
  71. $this->arrForm = $objFormParam->getHashArray();
  72. switch ($this->getMode()) {
  73. case 'search':
  74. $this->arrProducts = $this->lfGetProducts($objDb);
  75. break;
  76. default:
  77. break;
  78. }
  79. // カテゴリ取得
  80. $this->arrCatList = $objDb->sfGetCategoryList();
  81. $this->setTemplate($this->tpl_mainpage);
  82. }
  83. /**
  84. * パラメーター情報の初期化を行う.
  85. *
  86. * @param SC_FormParam $objFormParam SC_FormParam インスタンス
  87. * @return void
  88. */
  89. public function lfInitParam(&$objFormParam)
  90. {
  91. $objFormParam->addParam('カテゴリ', 'search_category_id', STEXT_LEN, 'n');
  92. $objFormParam->addParam('商品名', 'search_name', STEXT_LEN, 'KVa');
  93. $objFormParam->addParam('商品コード', 'search_product_code', STEXT_LEN, 'KVa');
  94. }
  95. /* 商品検索結果取得 */
  96. /**
  97. * @param SC_Helper_DB_Ex $objDb
  98. */
  99. public function lfGetProducts(&$objDb)
  100. {
  101. $where = 'del_flg = 0';
  102. $arrWhereVal = array();
  103. /* 入力エラーなし */
  104. foreach ($this->arrForm AS $key=>$val) {
  105. if ($val == '') continue;
  106. switch ($key) {
  107. case 'search_name':
  108. $where .= ' AND name ILIKE ?';
  109. $arrWhereVal[] = "%$val%";
  110. break;
  111. case 'search_category_id':
  112. list($tmp_where, $arrTmp) = $objDb->sfGetCatWhere($val);
  113. if ($tmp_where != '') {
  114. $where.= ' AND product_id IN (SELECT product_id FROM dtb_product_categories WHERE ' . $tmp_where . ')';
  115. $arrWhereVal = array_merge((array) $arrWhereVal, (array) $arrTmp);
  116. }
  117. break;
  118. case 'search_product_code':
  119. $where .= ' AND product_id IN (SELECT product_id FROM dtb_products_class WHERE product_code LIKE ?)';
  120. $arrWhereVal[] = "$val%";
  121. break;
  122. default:
  123. break;
  124. }
  125. }
  126. $order = 'update_date DESC, product_id DESC ';
  127. $objQuery =& SC_Query_Ex::getSingletonInstance();
  128. // 行数の取得
  129. $linemax = $objQuery->count('dtb_products', $where, $arrWhereVal);
  130. $this->tpl_linemax = $linemax; // 何件が該当しました。表示用
  131. // ページ送りの処理
  132. $page_max = SC_Utils_Ex::sfGetSearchPageMax($_POST['search_page_max']);
  133. // ページ送りの取得
  134. $objNavi = new SC_PageNavi_Ex($_POST['search_pageno'], $linemax, $page_max, 'eccube.moveSearchPage', NAVI_PMAX);
  135. $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列
  136. $startno = $objNavi->start_row;
  137. // 取得範囲の指定(開始行番号、行数のセット)
  138. $objQuery->setLimitOffset($page_max, $startno);
  139. // 表示順序
  140. $objQuery->setOrder($order);
  141. // 検索結果の取得
  142. // FIXME 商品コードの表示
  143. $arrProducts = $objQuery->select('*', SC_Product_Ex::alldtlSQL(), $where, $arrWhereVal);
  144. return $arrProducts;
  145. }
  146. }