[17162] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[22206] | 5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
[17162] | 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 | |
---|
| 24 | // {{{ requires |
---|
[20534] | 25 | require_once CLASS_EX_REALDIR . 'page_extends/mypage/LC_Page_AbstractMypage_Ex.php'; |
---|
[17162] | 26 | |
---|
| 27 | /** |
---|
| 28 | * MyPage のページクラス. |
---|
| 29 | * |
---|
| 30 | * @package Page |
---|
| 31 | * @author LOCKON CO.,LTD. |
---|
[20116] | 32 | * @version $Id$ |
---|
[17162] | 33 | */ |
---|
[22056] | 34 | class LC_Page_MyPage_Favorite extends LC_Page_AbstractMypage_Ex { |
---|
[17162] | 35 | |
---|
| 36 | // {{{ properties |
---|
| 37 | |
---|
| 38 | /** ページナンバー */ |
---|
| 39 | var $tpl_pageno; |
---|
| 40 | |
---|
| 41 | // }}} |
---|
| 42 | // {{{ functions |
---|
| 43 | |
---|
| 44 | /** |
---|
| 45 | * Page を初期化する. |
---|
| 46 | * |
---|
| 47 | * @return void |
---|
| 48 | */ |
---|
| 49 | function init() { |
---|
| 50 | parent::init(); |
---|
[17519] | 51 | $this->tpl_subtitle = 'お気に入り一覧'; |
---|
[17162] | 52 | $this->tpl_mypageno = 'favorite'; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | /** |
---|
| 56 | * Page のプロセス. |
---|
| 57 | * |
---|
| 58 | * @return void |
---|
| 59 | */ |
---|
| 60 | function process() { |
---|
[19661] | 61 | parent::process(); |
---|
| 62 | } |
---|
[17162] | 63 | |
---|
[19661] | 64 | /** |
---|
| 65 | * Page のAction. |
---|
| 66 | * |
---|
| 67 | * @return void |
---|
| 68 | */ |
---|
| 69 | function action() { |
---|
[21596] | 70 | |
---|
[21131] | 71 | $objProduct = new SC_Product_Ex(); |
---|
[20490] | 72 | $objCustomer = new SC_Customer_Ex(); |
---|
[20146] | 73 | $customer_id = $objCustomer->getValue('customer_id'); |
---|
[20041] | 74 | |
---|
[20044] | 75 | switch ($this->getMode()) { |
---|
[21047] | 76 | case 'delete_favorite': |
---|
| 77 | // お気に入り削除 |
---|
[21128] | 78 | $this->lfDeleteFavoriteProduct($customer_id, intval($_POST['product_id'])); |
---|
[21047] | 79 | break; |
---|
| 80 | case 'getList': |
---|
| 81 | // スマートフォン版のもっと見るボタン用 |
---|
| 82 | // ページ送り用 |
---|
[21128] | 83 | if (isset($_POST['pageno'])) { |
---|
| 84 | $this->tpl_pageno = intval($_POST['pageno']); |
---|
| 85 | } |
---|
| 86 | $this->arrFavorite = $this->lfGetFavoriteProduct($customer_id, $this); |
---|
[21131] | 87 | $this->arrFavorite = $objProduct->setPriceTaxTo($this->arrFavorite); |
---|
[21596] | 88 | |
---|
| 89 | |
---|
[21128] | 90 | echo SC_Utils_Ex::jsonEncode($this->arrFavorite); |
---|
[21743] | 91 | SC_Response_Ex::actionExit(); |
---|
[21047] | 92 | break; |
---|
[17162] | 93 | } |
---|
| 94 | |
---|
[18069] | 95 | // ページ送り用 |
---|
[17162] | 96 | if (isset($_POST['pageno'])) { |
---|
[21128] | 97 | $this->tpl_pageno = intval($_POST['pageno']); |
---|
[17162] | 98 | } |
---|
[20146] | 99 | $this->arrFavorite = $this->lfGetFavoriteProduct($customer_id, $this); |
---|
[21047] | 100 | // 1ページあたりの件数 |
---|
| 101 | $this->dispNumber = SEARCH_PMAX; |
---|
[21596] | 102 | |
---|
[21743] | 103 | |
---|
[20146] | 104 | } |
---|
[17162] | 105 | |
---|
[20146] | 106 | /** |
---|
| 107 | * デストラクタ. |
---|
| 108 | * |
---|
| 109 | * @return void |
---|
| 110 | */ |
---|
| 111 | function destroy() { |
---|
| 112 | parent::destroy(); |
---|
| 113 | } |
---|
[20041] | 114 | |
---|
[20146] | 115 | /** |
---|
| 116 | * お気に入りを取得する |
---|
| 117 | * |
---|
| 118 | * @param mixed $customer_id |
---|
| 119 | * @param mixed $objPage |
---|
| 120 | * @access private |
---|
| 121 | * @return array お気に入り商品一覧 |
---|
| 122 | */ |
---|
| 123 | function lfGetFavoriteProduct($customer_id, &$objPage) { |
---|
[20507] | 124 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
---|
[20487] | 125 | $objProduct = new SC_Product_Ex(); |
---|
[17162] | 126 | |
---|
[20146] | 127 | $objQuery->setOrder('create_date DESC'); |
---|
[22025] | 128 | $where = 'customer_id = ?'; |
---|
| 129 | if (NOSTOCK_HIDDEN) { |
---|
| 130 | $where .= ' AND EXISTS(SELECT * FROM dtb_products_class WHERE product_id = dtb_customer_favorite_products.product_id AND del_flg = 0 AND (stock >= 1 OR stock_unlimited = 1))'; |
---|
| 131 | } |
---|
| 132 | $arrProductId = $objQuery->getCol('product_id', 'dtb_customer_favorite_products', $where, array($customer_id)); |
---|
[17162] | 133 | |
---|
[20507] | 134 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[21256] | 135 | $objQuery->setWhere($this->lfMakeWhere('alldtl.', $arrProductId)); |
---|
[20146] | 136 | $linemax = $objProduct->findProductCount($objQuery); |
---|
| 137 | |
---|
| 138 | $objPage->tpl_linemax = $linemax; // 何件が該当しました。表示用 |
---|
| 139 | |
---|
[17162] | 140 | // ページ送りの取得 |
---|
[20538] | 141 | $objNavi = new SC_PageNavi_Ex($objPage->tpl_pageno, $linemax, SEARCH_PMAX, 'fnNaviPage', NAVI_PMAX); |
---|
[20562] | 142 | $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列 |
---|
[20146] | 143 | $startno = $objNavi->start_row; |
---|
[17162] | 144 | |
---|
[20507] | 145 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[20146] | 146 | //$objQuery->setLimitOffset(SEARCH_PMAX, $startno); |
---|
[17162] | 147 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
[21256] | 148 | $arrProductId = array_slice($arrProductId, $startno, SEARCH_PMAX); |
---|
[17162] | 149 | |
---|
[21256] | 150 | $where = $this->lfMakeWhere('', $arrProductId); |
---|
[21223] | 151 | $where .= ' AND del_flg = 0'; |
---|
[21256] | 152 | $objQuery->setWhere($where, $arrProductId); |
---|
| 153 | $arrProducts = $objProduct->lists($objQuery); |
---|
[17162] | 154 | |
---|
[20146] | 155 | //取得している並び順で並び替え |
---|
| 156 | $arrProducts2 = array(); |
---|
[21441] | 157 | foreach ($arrProducts as $item) { |
---|
[21708] | 158 | $arrProducts2[$item['product_id']] = $item; |
---|
[20146] | 159 | } |
---|
| 160 | $arrProductsList = array(); |
---|
[21441] | 161 | foreach ($arrProductId as $product_id) { |
---|
[20146] | 162 | $arrProductsList[] = $arrProducts2[$product_id]; |
---|
| 163 | } |
---|
[17162] | 164 | |
---|
[21708] | 165 | // 税込金額を設定する |
---|
| 166 | SC_Product_Ex::setIncTaxToProducts($arrProductsList); |
---|
| 167 | |
---|
[20146] | 168 | return $arrProductsList; |
---|
[17162] | 169 | } |
---|
| 170 | |
---|
[20146] | 171 | /* 仕方がない処理。。 */ |
---|
[21479] | 172 | function lfMakeWhere($tablename, $arrProductId) { |
---|
[17162] | 173 | |
---|
[20146] | 174 | // 取得した表示すべきIDだけを指定して情報を取得。 |
---|
[21514] | 175 | $where = ''; |
---|
[21256] | 176 | if (is_array($arrProductId) && !empty($arrProductId)) { |
---|
| 177 | $where = $tablename . 'product_id IN (' . implode(',', $arrProductId) . ')'; |
---|
[20146] | 178 | } else { |
---|
| 179 | // 一致させない |
---|
| 180 | $where = '0<>0'; |
---|
| 181 | } |
---|
| 182 | return $where; |
---|
[17162] | 183 | } |
---|
| 184 | |
---|
| 185 | // お気に入り商品削除 |
---|
| 186 | function lfDeleteFavoriteProduct($customer_id, $product_id) { |
---|
[21376] | 187 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
[17162] | 188 | |
---|
[21514] | 189 | $exists = $objQuery->exists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $product_id)); |
---|
[21376] | 190 | |
---|
| 191 | if ($exists) { |
---|
[21514] | 192 | $objQuery->delete('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $product_id)); |
---|
[17162] | 193 | } |
---|
| 194 | } |
---|
| 195 | } |
---|