[17162] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
[18701] | 5 | * Copyright(c) 2000-2010 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 |
---|
[20162] | 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 | */ |
---|
[20162] | 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() { |
---|
| 70 | |
---|
[20490] | 71 | $objCustomer = new SC_Customer_Ex(); |
---|
[20146] | 72 | $customer_id = $objCustomer->getValue('customer_id'); |
---|
[20041] | 73 | |
---|
[20044] | 74 | switch ($this->getMode()) { |
---|
| 75 | case 'delete_favorite': |
---|
[20146] | 76 | // お気に入り削除 |
---|
[17162] | 77 | $this->lfDeleteFavoriteProduct($customer_id, $_POST['product_id']); |
---|
[20044] | 78 | break; |
---|
[17162] | 79 | } |
---|
| 80 | |
---|
[18069] | 81 | // ページ送り用 |
---|
[17162] | 82 | if (isset($_POST['pageno'])) { |
---|
| 83 | $this->tpl_pageno = htmlspecialchars($_POST['pageno'], ENT_QUOTES, CHAR_CODE); |
---|
| 84 | } |
---|
[20146] | 85 | $this->arrFavorite = $this->lfGetFavoriteProduct($customer_id, $this); |
---|
| 86 | } |
---|
[17162] | 87 | |
---|
[20146] | 88 | /** |
---|
| 89 | * デストラクタ. |
---|
| 90 | * |
---|
| 91 | * @return void |
---|
| 92 | */ |
---|
| 93 | function destroy() { |
---|
| 94 | parent::destroy(); |
---|
| 95 | } |
---|
[20041] | 96 | |
---|
[17509] | 97 | |
---|
[20146] | 98 | /** |
---|
| 99 | * お気に入りを取得する |
---|
| 100 | * |
---|
| 101 | * @param mixed $customer_id |
---|
| 102 | * @param mixed $objPage |
---|
| 103 | * @access private |
---|
| 104 | * @return array お気に入り商品一覧 |
---|
| 105 | */ |
---|
| 106 | function lfGetFavoriteProduct($customer_id, &$objPage) { |
---|
| 107 | $objQuery = SC_Query::getSingletonInstance(); |
---|
[20487] | 108 | $objProduct = new SC_Product_Ex(); |
---|
[17162] | 109 | |
---|
[20146] | 110 | $objQuery->setOrder('create_date DESC'); |
---|
| 111 | $arrProduct_id = $objQuery->getCol('product_id', 'dtb_customer_favorite_products', 'customer_id = ?', array($customer_id)); |
---|
[17162] | 112 | |
---|
[20146] | 113 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 114 | $objQuery->setWhere($this->lfMakeWhere('alldtl.', $arrProduct_id)); |
---|
| 115 | $linemax = $objProduct->findProductCount($objQuery); |
---|
| 116 | |
---|
| 117 | $objPage->tpl_linemax = $linemax; // 何件が該当しました。表示用 |
---|
| 118 | |
---|
[17162] | 119 | // ページ送りの取得 |
---|
[20491] | 120 | $objNavi = new SC_PageNavi_Ex($objPage->tpl_pageno, $linemax, SEARCH_PMAX, "fnNaviPage", NAVI_PMAX); |
---|
[17162] | 121 | $this->tpl_strnavi = $objNavi->strnavi; // 表示文字列 |
---|
[20146] | 122 | $startno = $objNavi->start_row; |
---|
[17162] | 123 | |
---|
[20146] | 124 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
| 125 | //$objQuery->setLimitOffset(SEARCH_PMAX, $startno); |
---|
[17162] | 126 | // 取得範囲の指定(開始行番号、行数のセット) |
---|
[20146] | 127 | $arrProduct_id = array_slice($arrProduct_id, $startno, SEARCH_PMAX); |
---|
[17162] | 128 | |
---|
[20146] | 129 | $objQuery->setWhere($this->lfMakeWhere('', $arrProduct_id)); |
---|
| 130 | $objProduct->setProductsOrder('create_date', 'dtb_customer_favorite_products', 'DESC'); |
---|
| 131 | $arrProducts = $objProduct->lists($objQuery, $arrProduct_id); |
---|
[17162] | 132 | |
---|
[20146] | 133 | //取得している並び順で並び替え |
---|
| 134 | $arrProducts2 = array(); |
---|
| 135 | foreach($arrProducts as $item) { |
---|
| 136 | $arrProducts2[ $item['product_id'] ] = $item; |
---|
| 137 | } |
---|
| 138 | $arrProductsList = array(); |
---|
| 139 | foreach($arrProduct_id as $product_id) { |
---|
| 140 | $arrProductsList[] = $arrProducts2[$product_id]; |
---|
| 141 | } |
---|
[17162] | 142 | |
---|
[20146] | 143 | return $arrProductsList; |
---|
[17162] | 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
[20146] | 147 | /* 仕方がない処理。。 */ |
---|
| 148 | function lfMakeWhere ($tablename, $arrProduct_id) { |
---|
[17162] | 149 | |
---|
[20146] | 150 | // 取得した表示すべきIDだけを指定して情報を取得。 |
---|
| 151 | $where = ""; |
---|
| 152 | if (is_array($arrProduct_id) && !empty($arrProduct_id)) { |
---|
| 153 | $where = $tablename . 'product_id IN (' . implode(',', $arrProduct_id) . ')'; |
---|
| 154 | } else { |
---|
| 155 | // 一致させない |
---|
| 156 | $where = '0<>0'; |
---|
| 157 | } |
---|
| 158 | // 在庫無し商品の非表示 |
---|
| 159 | if (NOSTOCK_HIDDEN === true) { |
---|
| 160 | $where .= ' AND (stock_max >= 1 OR stock_unlimited_max = 1)'; |
---|
| 161 | } |
---|
| 162 | return $where; |
---|
[17162] | 163 | } |
---|
| 164 | |
---|
[20146] | 165 | |
---|
[17162] | 166 | // お気に入り商品削除 |
---|
| 167 | function lfDeleteFavoriteProduct($customer_id, $product_id) { |
---|
[20146] | 168 | $objQuery = new SC_Query(); |
---|
| 169 | $count = $objQuery->count("dtb_customer_favorite_products", "customer_id = ? AND product_id = ?", array($customer_id, $product_id)); |
---|
[17162] | 170 | |
---|
| 171 | if ($count > 0) { |
---|
| 172 | $objQuery->begin(); |
---|
[18770] | 173 | $objQuery->delete('dtb_customer_favorite_products', "customer_id = ? AND product_id = ?", array($customer_id, $product_id)); |
---|
[17162] | 174 | $objQuery->commit(); |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | } |
---|