| 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
| 5 | * Copyright(c) 2000-2013 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 | |
---|
| 24 | require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php'; |
---|
| 25 | |
---|
| 26 | if (file_exists(MODULE_REALDIR . 'mdl_gmopg/inc/function.php')) { |
---|
| 27 | require_once MODULE_REALDIR . 'mdl_gmopg/inc/function.php'; |
---|
| 28 | } |
---|
| 29 | /** |
---|
| 30 | * 商品詳細 のページクラス. |
---|
| 31 | * |
---|
| 32 | * @package Page |
---|
| 33 | * @author LOCKON CO.,LTD. |
---|
| 34 | * @version $Id:LC_Page_Products_Detail.php 15532 2007-08-31 14:39:46Z nanasess $ |
---|
| 35 | */ |
---|
| 36 | class LC_Page_Products_Detail extends LC_Page_Ex |
---|
| 37 | { |
---|
| 38 | /** 商品ステータス */ |
---|
| 39 | public $arrSTATUS; |
---|
| 40 | |
---|
| 41 | /** 商品ステータス画像 */ |
---|
| 42 | public $arrSTATUS_IMAGE; |
---|
| 43 | |
---|
| 44 | /** 発送予定日 */ |
---|
| 45 | public $arrDELIVERYDATE; |
---|
| 46 | |
---|
| 47 | /** おすすめレベル */ |
---|
| 48 | public $arrRECOMMEND; |
---|
| 49 | |
---|
| 50 | /** @var SC_FormParam フォームパラメーター */ |
---|
| 51 | public $objFormParam; |
---|
| 52 | |
---|
| 53 | /** @var SC_UploadFile アップロードファイル */ |
---|
| 54 | public $objUpFile; |
---|
| 55 | |
---|
| 56 | /** @var string モード */ |
---|
| 57 | public $mode; |
---|
| 58 | |
---|
| 59 | /** @var array 商品情報 */ |
---|
| 60 | public $arrProduct; |
---|
| 61 | |
---|
| 62 | /** @var string 規格1クラス名 */ |
---|
| 63 | public $tpl_class_name1; |
---|
| 64 | |
---|
| 65 | /** @var string 規格2クラス名 */ |
---|
| 66 | public $tpl_class_name2; |
---|
| 67 | |
---|
| 68 | /** @var bool 在庫があるかどうか */ |
---|
| 69 | public $tpl_stock_find; |
---|
| 70 | |
---|
| 71 | /** @var array 規格1の規格分類 */ |
---|
| 72 | public $arrClassCat1; |
---|
| 73 | |
---|
| 74 | /** @var bool 規格1が設定されている */ |
---|
| 75 | public $tpl_classcat_find1; |
---|
| 76 | |
---|
| 77 | /** @var bool 規格2が設定されている */ |
---|
| 78 | public $tpl_classcat_find2; |
---|
| 79 | |
---|
| 80 | /** @var int デフォルトの商品規格ID */ |
---|
| 81 | public $tpl_product_class_id; |
---|
| 82 | |
---|
| 83 | /** @var int デフォルトの商品タイプ */ |
---|
| 84 | public $tpl_product_type; |
---|
| 85 | |
---|
| 86 | /** @var string ページ表示時に実行するJavaScript */ |
---|
| 87 | public $js_lnOnload; |
---|
| 88 | |
---|
| 89 | /** @var int 商品ID */ |
---|
| 90 | public $tpl_product_id; |
---|
| 91 | |
---|
| 92 | /** @var array フォーム情報 */ |
---|
| 93 | public $arrForm; |
---|
| 94 | |
---|
| 95 | /** @var string サブタイトル */ |
---|
| 96 | public $tpl_subtitle; |
---|
| 97 | |
---|
| 98 | /** @var array 関連カテゴリー */ |
---|
| 99 | public $arrRelativeCat; |
---|
| 100 | |
---|
| 101 | /** @var array 商品ステータス(アイコン) */ |
---|
| 102 | public $productStatus; |
---|
| 103 | |
---|
| 104 | /** @var bool サブ画像が存在するか */ |
---|
| 105 | public $subImageFlag; |
---|
| 106 | |
---|
| 107 | /** @var array レビュー情報 */ |
---|
| 108 | public $arrReview; |
---|
| 109 | |
---|
| 110 | /** @var array 関連商品情報 */ |
---|
| 111 | public $arrRecommend; |
---|
| 112 | |
---|
| 113 | /** @var array ファイル情報 */ |
---|
| 114 | public $arrFile; |
---|
| 115 | |
---|
| 116 | /** @var bool ログイン状態かどうか */ |
---|
| 117 | public $tpl_login; |
---|
| 118 | |
---|
| 119 | /** @var bool お気に入りに登録済みか */ |
---|
| 120 | public $is_favorite; |
---|
| 121 | |
---|
| 122 | /** @var bool お気に入りに登録したことを示すフラグ */ |
---|
| 123 | public $just_added_favorite; |
---|
| 124 | |
---|
| 125 | /** @var array エラー情報 */ |
---|
| 126 | public $arrErr; |
---|
| 127 | |
---|
| 128 | /** |
---|
| 129 | * Page を初期化する. |
---|
| 130 | * |
---|
| 131 | * @return void |
---|
| 132 | */ |
---|
| 133 | public function init() |
---|
| 134 | { |
---|
| 135 | parent::init(); |
---|
| 136 | $masterData = new SC_DB_MasterData_Ex(); |
---|
| 137 | $this->arrSTATUS = $masterData->getMasterData('mtb_status'); |
---|
| 138 | $this->arrSTATUS_IMAGE = $masterData->getMasterData('mtb_status_image'); |
---|
| 139 | $this->arrDELIVERYDATE = $masterData->getMasterData('mtb_delivery_date'); |
---|
| 140 | $this->arrRECOMMEND = $masterData->getMasterData('mtb_recommend'); |
---|
| 141 | |
---|
| 142 | // POST に限定する mode |
---|
| 143 | $this->arrLimitPostMode[] = 'cart'; |
---|
| 144 | $this->arrLimitPostMode[] = 'add_favorite'; |
---|
| 145 | $this->arrLimitPostMode[] = 'add_favorite_sphone'; |
---|
| 146 | $this->arrLimitPostMode[] = 'select'; |
---|
| 147 | $this->arrLimitPostMode[] = 'select2'; |
---|
| 148 | $this->arrLimitPostMode[] = 'selectItem'; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | /** |
---|
| 152 | * Page のプロセス. |
---|
| 153 | * |
---|
| 154 | * @return void |
---|
| 155 | */ |
---|
| 156 | public function process() |
---|
| 157 | { |
---|
| 158 | parent::process(); |
---|
| 159 | $this->action(); |
---|
| 160 | $this->sendResponse(); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | /** |
---|
| 164 | * Page のAction. |
---|
| 165 | * |
---|
| 166 | * @return void |
---|
| 167 | */ |
---|
| 168 | public function action() |
---|
| 169 | { |
---|
| 170 | //決済処理中ステータスのロールバック |
---|
| 171 | $objPurchase = new SC_Helper_Purchase_Ex(); |
---|
| 172 | $objPurchase->cancelPendingOrder(PENDING_ORDER_CANCEL_FLAG); |
---|
| 173 | |
---|
| 174 | // 会員クラス |
---|
| 175 | $objCustomer = new SC_Customer_Ex(); |
---|
| 176 | |
---|
| 177 | // パラメーター管理クラス |
---|
| 178 | $this->objFormParam = new SC_FormParam_Ex(); |
---|
| 179 | // パラメーター情報の初期化 |
---|
| 180 | $this->arrForm = $this->lfInitParam($this->objFormParam); |
---|
| 181 | // ファイル管理クラス |
---|
| 182 | $this->objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); |
---|
| 183 | // ファイル情報の初期化 |
---|
| 184 | $this->objUpFile = $this->lfInitFile($this->objUpFile); |
---|
| 185 | $this->mode = $this->getMode(); |
---|
| 186 | |
---|
| 187 | $objProduct = new SC_Product_Ex(); |
---|
| 188 | |
---|
| 189 | // プロダクトIDの正当性チェック |
---|
| 190 | $product_id = $this->lfCheckProductId($this->objFormParam->getValue('admin'), $this->objFormParam->getValue('product_id'), $objProduct); |
---|
| 191 | |
---|
| 192 | $objProduct->setProductsClassByProductIds(array($product_id)); |
---|
| 193 | |
---|
| 194 | // 規格1クラス名 |
---|
| 195 | $this->tpl_class_name1 = $objProduct->className1[$product_id]; |
---|
| 196 | |
---|
| 197 | // 規格2クラス名 |
---|
| 198 | $this->tpl_class_name2 = $objProduct->className2[$product_id]; |
---|
| 199 | |
---|
| 200 | // 規格1 |
---|
| 201 | $this->arrClassCat1 = $objProduct->classCats1[$product_id]; |
---|
| 202 | |
---|
| 203 | // 規格1が設定されている |
---|
| 204 | $this->tpl_classcat_find1 = $objProduct->classCat1_find[$product_id]; |
---|
| 205 | // 規格2が設定されている |
---|
| 206 | $this->tpl_classcat_find2 = $objProduct->classCat2_find[$product_id]; |
---|
| 207 | |
---|
| 208 | $this->tpl_stock_find = $objProduct->stock_find[$product_id]; |
---|
| 209 | $this->tpl_product_class_id = $objProduct->classCategories[$product_id]['__unselected']['__unselected']['product_class_id']; |
---|
| 210 | $this->tpl_product_type = $objProduct->classCategories[$product_id]['__unselected']['__unselected']['product_type']; |
---|
| 211 | |
---|
| 212 | // 在庫が無い場合は、OnLoadしない。(javascriptエラー防止) |
---|
| 213 | if ($this->tpl_stock_find) { |
---|
| 214 | // 規格選択セレクトボックスの作成 |
---|
| 215 | $this->js_lnOnload .= $this->lfMakeSelect(); |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | $this->tpl_javascript .= 'eccube.classCategories = ' . SC_Utils_Ex::jsonEncode($objProduct->classCategories[$product_id]) . ';'; |
---|
| 219 | $this->tpl_javascript .= 'function lnOnLoad() |
---|
| 220 | {' . $this->js_lnOnload . '}'; |
---|
| 221 | $this->tpl_onload .= 'lnOnLoad();'; |
---|
| 222 | |
---|
| 223 | // モバイル用 規格選択セレクトボックスの作成 |
---|
| 224 | if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) { |
---|
| 225 | $this->lfMakeSelectMobile($this, $product_id, $this->objFormParam->getValue('classcategory_id1')); |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | // 商品IDをFORM内に保持する |
---|
| 229 | $this->tpl_product_id = $product_id; |
---|
| 230 | |
---|
| 231 | switch ($this->mode) { |
---|
| 232 | case 'cart': |
---|
| 233 | $this->doCart(); |
---|
| 234 | break; |
---|
| 235 | |
---|
| 236 | case 'add_favorite': |
---|
| 237 | $this->doAddFavorite($objCustomer); |
---|
| 238 | break; |
---|
| 239 | |
---|
| 240 | case 'add_favorite_sphone': |
---|
| 241 | $this->doAddFavoriteSphone($objCustomer); |
---|
| 242 | break; |
---|
| 243 | |
---|
| 244 | case 'select': |
---|
| 245 | case 'select2': |
---|
| 246 | case 'selectItem': |
---|
| 247 | /** |
---|
| 248 | * モバイルの数量指定・規格選択の際に、 |
---|
| 249 | * $_SESSION['cart_referer_url'] を上書きさせないために、 |
---|
| 250 | * 何もせずbreakする。 |
---|
| 251 | */ |
---|
| 252 | break; |
---|
| 253 | |
---|
| 254 | default: |
---|
| 255 | $this->doDefault(); |
---|
| 256 | break; |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | // モバイル用 ポストバック処理 |
---|
| 260 | if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE) { |
---|
| 261 | switch ($this->mode) { |
---|
| 262 | case 'select': |
---|
| 263 | $this->doMobileSelect(); |
---|
| 264 | break; |
---|
| 265 | |
---|
| 266 | case 'select2': |
---|
| 267 | $this->doMobileSelect2(); |
---|
| 268 | break; |
---|
| 269 | |
---|
| 270 | case 'selectItem': |
---|
| 271 | $this->doMobileSelectItem(); |
---|
| 272 | break; |
---|
| 273 | |
---|
| 274 | case 'cart': |
---|
| 275 | $this->doMobileCart(); |
---|
| 276 | break; |
---|
| 277 | |
---|
| 278 | default: |
---|
| 279 | $this->doMobileDefault(); |
---|
| 280 | break; |
---|
| 281 | } |
---|
| 282 | } |
---|
| 283 | |
---|
| 284 | // 商品詳細を取得 |
---|
| 285 | $this->arrProduct = $objProduct->getDetail($product_id); |
---|
| 286 | |
---|
| 287 | // サブタイトルを取得 |
---|
| 288 | $this->tpl_subtitle = $this->arrProduct['name']; |
---|
| 289 | |
---|
| 290 | // 関連カテゴリを取得 |
---|
| 291 | $arrCategory_id = $objProduct->getCategoryIds($product_id); |
---|
| 292 | $objCategory = new SC_Helper_Category_Ex(); |
---|
| 293 | $this->arrRelativeCat = array(); |
---|
| 294 | foreach ($arrCategory_id as $category_id) { |
---|
| 295 | $this->arrRelativeCat[] = $objCategory->getTreeTrail($category_id, false); |
---|
| 296 | } |
---|
| 297 | |
---|
| 298 | // 商品ステータスを取得 |
---|
| 299 | $this->productStatus = $objProduct->getProductStatus($product_id); |
---|
| 300 | |
---|
| 301 | // 画像ファイル指定がない場合の置換処理 |
---|
| 302 | $this->arrProduct['main_image'] |
---|
| 303 | = SC_Utils_Ex::sfNoImageMain($this->arrProduct['main_image']); |
---|
| 304 | |
---|
| 305 | $this->subImageFlag = $this->lfSetFile($this->objUpFile, $this->arrProduct, $this->arrFile); |
---|
| 306 | //レビュー情報の取得 |
---|
| 307 | $objReview = new SC_Helper_Review_Ex(); |
---|
| 308 | $this->arrReview = $objReview->getListByProductId($product_id); |
---|
| 309 | |
---|
| 310 | //関連商品情報表示 |
---|
| 311 | $this->arrRecommend = $this->lfPreGetRecommendProducts($product_id); |
---|
| 312 | |
---|
| 313 | // ログイン判定 |
---|
| 314 | if ($objCustomer->isLoginSuccess() === true) { |
---|
| 315 | //お気に入りボタン表示 |
---|
| 316 | $this->tpl_login = true; |
---|
| 317 | $this->is_favorite = SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($objCustomer->getValue('customer_id'), $product_id)); |
---|
| 318 | } |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | /** |
---|
| 322 | * プロダクトIDの正当性チェック |
---|
| 323 | * |
---|
| 324 | * @param string $admin_mode |
---|
| 325 | * @param int $product_id |
---|
| 326 | * @param SC_Product $objProduct |
---|
| 327 | * @return int|void |
---|
| 328 | */ |
---|
| 329 | public function lfCheckProductId($admin_mode, $product_id, SC_Product $objProduct) |
---|
| 330 | { |
---|
| 331 | // 管理機能からの確認の場合は、非公開の商品も表示する。 |
---|
| 332 | if (isset($admin_mode) && $admin_mode == 'on' && SC_Utils_Ex::sfIsSuccess(new SC_Session_Ex(), false)) { |
---|
| 333 | $include_hidden = true; |
---|
| 334 | } else { |
---|
| 335 | $include_hidden = false; |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | if (!$objProduct->isValidProductId($product_id, $include_hidden)) { |
---|
| 339 | SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | return $product_id; |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | /** |
---|
| 346 | * ファイル情報の初期化 |
---|
| 347 | * |
---|
| 348 | * @param SC_UploadFile $objUpFile |
---|
| 349 | * @return SC_UploadFile |
---|
| 350 | */ |
---|
| 351 | public function lfInitFile(SC_UploadFile $objUpFile) |
---|
| 352 | { |
---|
| 353 | $objUpFile->addFile('詳細-メイン画像', 'main_image', array('jpg'), IMAGE_SIZE); |
---|
| 354 | for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) { |
---|
| 355 | $objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg'), IMAGE_SIZE); |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | return $objUpFile; |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | /* 規格選択セレクトボックスの作成 */ |
---|
| 362 | public function lfMakeSelect() |
---|
| 363 | { |
---|
| 364 | return 'fnSetClassCategories(' |
---|
| 365 | . 'document.form1, ' |
---|
| 366 | . SC_Utils_Ex::jsonEncode($this->objFormParam->getValue('classcategory_id2')) |
---|
| 367 | . '); '; |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | /* 規格選択セレクトボックスの作成(モバイル) */ |
---|
| 371 | public function lfMakeSelectMobile(&$objPage, $product_id, $request_classcategory_id1) |
---|
| 372 | { |
---|
| 373 | $classcat_find1 = false; |
---|
| 374 | $classcat_find2 = false; |
---|
| 375 | |
---|
| 376 | // 規格名一覧 |
---|
| 377 | $arrClassName = SC_Helper_DB_Ex::sfGetIDValueList('dtb_class', 'class_id', 'name'); |
---|
| 378 | // 規格分類名一覧 |
---|
| 379 | $arrClassCatName = SC_Helper_DB_Ex::sfGetIDValueList('dtb_classcategory', 'classcategory_id', 'name'); |
---|
| 380 | // 商品規格情報の取得 |
---|
| 381 | $arrProductsClass = $this->lfGetProductsClass($product_id); |
---|
| 382 | |
---|
| 383 | // 規格1クラス名の取得 |
---|
| 384 | $objPage->tpl_class_name1 = $arrClassName[$arrProductsClass[0]['class_id1']]; |
---|
| 385 | // 規格2クラス名の取得 |
---|
| 386 | $objPage->tpl_class_name2 = $arrClassName[$arrProductsClass[0]['class_id2']]; |
---|
| 387 | |
---|
| 388 | // 全ての組み合わせ数 |
---|
| 389 | $count = count($arrProductsClass); |
---|
| 390 | |
---|
| 391 | $classcat_id1 = ''; |
---|
| 392 | $classcat_id2 = ''; |
---|
| 393 | |
---|
| 394 | $arrSele1 = array(); |
---|
| 395 | $arrSele2 = array(); |
---|
| 396 | |
---|
| 397 | for ($i = 0; $i < $count; $i++) { |
---|
| 398 | // 在庫のチェック |
---|
| 399 | if ($arrProductsClass[$i]['stock'] <= 0 && $arrProductsClass[$i]['stock_unlimited'] != '1') { |
---|
| 400 | continue; |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | // 規格1のセレクトボックス用 |
---|
| 404 | if ($classcat_id1 != $arrProductsClass[$i]['classcategory_id1']) { |
---|
| 405 | $classcat_id1 = $arrProductsClass[$i]['classcategory_id1']; |
---|
| 406 | $arrSele1[$classcat_id1] = $arrClassCatName[$classcat_id1]; |
---|
| 407 | } |
---|
| 408 | |
---|
| 409 | // 規格2のセレクトボックス用 |
---|
| 410 | if ($arrProductsClass[$i]['classcategory_id1'] == $request_classcategory_id1 and $classcat_id2 != $arrProductsClass[$i]['classcategory_id2']) { |
---|
| 411 | $classcat_id2 = $arrProductsClass[$i]['classcategory_id2']; |
---|
| 412 | $arrSele2[$classcat_id2] = $arrClassCatName[$classcat_id2]; |
---|
| 413 | } |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | // 規格1 |
---|
| 417 | $objPage->arrClassCat1 = $arrSele1; |
---|
| 418 | $objPage->arrClassCat2 = $arrSele2; |
---|
| 419 | |
---|
| 420 | // 規格1が設定されている |
---|
| 421 | if (isset($arrProductsClass[0]['classcategory_id1']) && $arrProductsClass[0]['classcategory_id1'] != '0') { |
---|
| 422 | $classcat_find1 = true; |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | // 規格2が設定されている |
---|
| 426 | if (isset($arrProductsClass[0]['classcategory_id2']) && $arrProductsClass[0]['classcategory_id2'] != '0') { |
---|
| 427 | $classcat_find2 = true; |
---|
| 428 | } |
---|
| 429 | |
---|
| 430 | $objPage->tpl_classcat_find1 = $classcat_find1; |
---|
| 431 | $objPage->tpl_classcat_find2 = $classcat_find2; |
---|
| 432 | } |
---|
| 433 | |
---|
| 434 | /** |
---|
| 435 | * パラメーター情報の初期化 |
---|
| 436 | * |
---|
| 437 | * @param SC_FormParam $objFormParam |
---|
| 438 | * @return array |
---|
| 439 | */ |
---|
| 440 | public function lfInitParam(SC_FormParam &$objFormParam) |
---|
| 441 | { |
---|
| 442 | $objFormParam->addParam('規格1', 'classcategory_id1', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 443 | $objFormParam->addParam('規格2', 'classcategory_id2', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 444 | $objFormParam->addParam('数量', 'quantity', INT_LEN, 'n', array('EXIST_CHECK', 'ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 445 | $objFormParam->addParam('管理者ログイン', 'admin', INT_LEN, 'a', array('ALNUM_CHECK','MAX_LENGTH_CHECK')); |
---|
| 446 | $objFormParam->addParam('商品ID', 'product_id', INT_LEN, 'n', array('EXIST_CHECK', 'ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 447 | $objFormParam->addParam('お気に入り商品ID', 'favorite_product_id', INT_LEN, 'n', array('ZERO_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 448 | $objFormParam->addParam('商品規格ID', 'product_class_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
| 449 | // 値の取得 |
---|
| 450 | $objFormParam->setParam($_REQUEST); |
---|
| 451 | // 入力値の変換 |
---|
| 452 | $objFormParam->convParam(); |
---|
| 453 | // 入力情報を渡す |
---|
| 454 | return $objFormParam->getFormParamList(); |
---|
| 455 | } |
---|
| 456 | |
---|
| 457 | /* 商品規格情報の取得 */ |
---|
| 458 | public function lfGetProductsClass($product_id) |
---|
| 459 | { |
---|
| 460 | $objProduct = new SC_Product_Ex(); |
---|
| 461 | |
---|
| 462 | return $objProduct->getProductsClassFullByProductId($product_id); |
---|
| 463 | } |
---|
| 464 | |
---|
| 465 | /* 登録済み関連商品の読み込み */ |
---|
| 466 | public function lfPreGetRecommendProducts($product_id) |
---|
| 467 | { |
---|
| 468 | $objProduct = new SC_Product_Ex(); |
---|
| 469 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 470 | |
---|
| 471 | $objQuery->setOrder('rank DESC'); |
---|
| 472 | $arrRecommendData = $objQuery->select('recommend_product_id, comment', 'dtb_recommend_products as t1 left join dtb_products as t2 on t1.recommend_product_id = t2.product_id', 't1.product_id = ? and t2.del_flg = 0 and t2.status = 1', array($product_id)); |
---|
| 473 | |
---|
| 474 | $recommendProductIds = array(); |
---|
| 475 | foreach ($arrRecommendData as $recommend) { |
---|
| 476 | $recommendProductIds[] = $recommend['recommend_product_id']; |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 480 | $arrProducts = $objProduct->getListByProductIds($objQuery, $recommendProductIds); |
---|
| 481 | |
---|
| 482 | foreach ($arrRecommendData as $key => $arrRow) { |
---|
| 483 | $arrRecommendData[$key] = array_merge($arrRow, $arrProducts[$arrRow['recommend_product_id']]); |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | return $arrRecommendData; |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | /* 入力内容のチェック */ |
---|
| 490 | public function lfCheckError($mode, SC_FormParam &$objFormParam, $tpl_classcat_find1 = null , $tpl_classcat_find2 = null) |
---|
| 491 | { |
---|
| 492 | switch ($mode) { |
---|
| 493 | case 'add_favorite_sphone': |
---|
| 494 | case 'add_favorite': |
---|
| 495 | $objCustomer = new SC_Customer_Ex(); |
---|
| 496 | $objErr = new SC_CheckError_Ex(); |
---|
| 497 | $customer_id = $objCustomer->getValue('customer_id'); |
---|
| 498 | $favorite_product_id = $objCustomer->getValue('favorite_product_id'); |
---|
| 499 | if (SC_Helper_DB_Ex::sfDataExists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id))) { |
---|
| 500 | $objErr->arrErr['add_favorite'.$favorite_product_id] = '※ この商品は既にお気に入りに追加されています。<br />'; |
---|
| 501 | } |
---|
| 502 | break; |
---|
| 503 | default: |
---|
| 504 | // 入力データを渡す。 |
---|
| 505 | $arrRet = $objFormParam->getHashArray(); |
---|
| 506 | $objErr = new SC_CheckError_Ex($arrRet); |
---|
| 507 | $objErr->arrErr = $objFormParam->checkError(); |
---|
| 508 | |
---|
| 509 | // 複数項目チェック |
---|
| 510 | if ($tpl_classcat_find1) { |
---|
| 511 | $objErr->doFunc(array('規格1', 'classcategory_id1'), array('EXIST_CHECK')); |
---|
| 512 | } |
---|
| 513 | if ($tpl_classcat_find2) { |
---|
| 514 | $objErr->doFunc(array('規格2', 'classcategory_id2'), array('EXIST_CHECK')); |
---|
| 515 | } |
---|
| 516 | break; |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | return $objErr->arrErr; |
---|
| 520 | } |
---|
| 521 | |
---|
| 522 | /** |
---|
| 523 | * ファイルの情報をセットする |
---|
| 524 | * |
---|
| 525 | * @param SC_UploadFile $objUpFile |
---|
| 526 | * @param array $arrProduct |
---|
| 527 | * @param array $arrFile |
---|
| 528 | * @return bool |
---|
| 529 | */ |
---|
| 530 | public function lfSetFile(SC_UploadFile $objUpFile, $arrProduct, &$arrFile) |
---|
| 531 | { |
---|
| 532 | // DBからのデータを引き継ぐ |
---|
| 533 | $objUpFile->setDBFileList($arrProduct); |
---|
| 534 | // ファイル表示用配列を渡す |
---|
| 535 | $arrFile = $objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH, true); |
---|
| 536 | |
---|
| 537 | // サブ画像の有無を判定 |
---|
| 538 | $subImageFlag = false; |
---|
| 539 | for ($i = 1; $i <= PRODUCTSUB_MAX; $i++) { |
---|
| 540 | if ($arrFile['sub_image' . $i]['filepath'] != '') { |
---|
| 541 | $subImageFlag = true; |
---|
| 542 | } |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | return $subImageFlag; |
---|
| 546 | } |
---|
| 547 | |
---|
| 548 | /* |
---|
| 549 | * お気に入り商品登録 |
---|
| 550 | * @return void |
---|
| 551 | */ |
---|
| 552 | public function lfRegistFavoriteProduct($favorite_product_id, $customer_id) |
---|
| 553 | { |
---|
| 554 | // ログイン中のユーザが商品をお気に入りにいれる処理 |
---|
| 555 | if (!SC_Helper_DB_Ex::sfIsRecord('dtb_products', 'product_id', $favorite_product_id, 'del_flg = 0 AND status = 1')) { |
---|
| 556 | SC_Utils_Ex::sfDispSiteError(PRODUCT_NOT_FOUND); |
---|
| 557 | |
---|
| 558 | return false; |
---|
| 559 | } else { |
---|
| 560 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
| 561 | $exists = $objQuery->exists('dtb_customer_favorite_products', 'customer_id = ? AND product_id = ?', array($customer_id, $favorite_product_id)); |
---|
| 562 | |
---|
| 563 | if (!$exists) { |
---|
| 564 | $sqlval['customer_id'] = $customer_id; |
---|
| 565 | $sqlval['product_id'] = $favorite_product_id; |
---|
| 566 | $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
| 567 | $sqlval['create_date'] = 'CURRENT_TIMESTAMP'; |
---|
| 568 | |
---|
| 569 | $objQuery->begin(); |
---|
| 570 | $objQuery->insert('dtb_customer_favorite_products', $sqlval); |
---|
| 571 | $objQuery->commit(); |
---|
| 572 | } |
---|
| 573 | // お気に入りに登録したことを示すフラグ |
---|
| 574 | $this->just_added_favorite = true; |
---|
| 575 | |
---|
| 576 | return true; |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | /** |
---|
| 581 | * Add product(s) into the cart. |
---|
| 582 | * |
---|
| 583 | * @return void |
---|
| 584 | */ |
---|
| 585 | public function doCart() |
---|
| 586 | { |
---|
| 587 | $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam, |
---|
| 588 | $this->tpl_classcat_find1, |
---|
| 589 | $this->tpl_classcat_find2); |
---|
| 590 | if (count($this->arrErr) == 0) { |
---|
| 591 | $objCartSess = new SC_CartSession_Ex(); |
---|
| 592 | $product_class_id = $this->objFormParam->getValue('product_class_id'); |
---|
| 593 | |
---|
| 594 | $objCartSess->addProduct($product_class_id, $this->objFormParam->getValue('quantity')); |
---|
| 595 | |
---|
| 596 | // 開いているカテゴリーツリーを維持するためのパラメーター |
---|
| 597 | $arrQueryString = array( |
---|
| 598 | 'product_id' => $this->objFormParam->getValue('product_id'), |
---|
| 599 | ); |
---|
| 600 | |
---|
| 601 | SC_Response_Ex::sendRedirect(CART_URL, $arrQueryString); |
---|
| 602 | SC_Response_Ex::actionExit(); |
---|
| 603 | } |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | /** |
---|
| 607 | * Add product to authenticated user's favorites. |
---|
| 608 | * |
---|
| 609 | * @param SC_Customer $objCustomer |
---|
| 610 | * @return void |
---|
| 611 | */ |
---|
| 612 | public function doAddFavorite(SC_Customer &$objCustomer) |
---|
| 613 | { |
---|
| 614 | // ログイン中のユーザが商品をお気に入りにいれる処理 |
---|
| 615 | if ($objCustomer->isLoginSuccess() === true && $this->objFormParam->getValue('favorite_product_id') > 0) { |
---|
| 616 | $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam); |
---|
| 617 | if (count($this->arrErr) == 0) { |
---|
| 618 | if (!$this->lfRegistFavoriteProduct($this->objFormParam->getValue('favorite_product_id'),$objCustomer->getValue('customer_id'))) { |
---|
| 619 | SC_Response_Ex::actionExit(); |
---|
| 620 | } |
---|
| 621 | $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg); |
---|
| 622 | $objPlugin->doAction('LC_Page_Products_Detail_action_add_favorite', array($this)); |
---|
| 623 | } |
---|
| 624 | } |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | /** |
---|
| 628 | * Add product to authenticated user's favorites. (for Smart phone) |
---|
| 629 | * |
---|
| 630 | * @param SC_Customer $objCustomer |
---|
| 631 | * @return void |
---|
| 632 | */ |
---|
| 633 | public function doAddFavoriteSphone(SC_Customer $objCustomer) |
---|
| 634 | { |
---|
| 635 | // ログイン中のユーザが商品をお気に入りにいれる処理(スマートフォン用) |
---|
| 636 | if ($objCustomer->isLoginSuccess() === true && $this->objFormParam->getValue('favorite_product_id') > 0) { |
---|
| 637 | $this->arrErr = $this->lfCheckError($this->mode,$this->objFormParam); |
---|
| 638 | if (count($this->arrErr) == 0) { |
---|
| 639 | if ($this->lfRegistFavoriteProduct($this->objFormParam->getValue('favorite_product_id'),$objCustomer->getValue('customer_id'))) { |
---|
| 640 | $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg); |
---|
| 641 | $objPlugin->doAction('LC_Page_Products_Detail_action_add_favorite_sphone', array($this)); |
---|
| 642 | print 'true'; |
---|
| 643 | SC_Response_Ex::actionExit(); |
---|
| 644 | } |
---|
| 645 | } |
---|
| 646 | print 'error'; |
---|
| 647 | SC_Response_Ex::actionExit(); |
---|
| 648 | } |
---|
| 649 | } |
---|
| 650 | |
---|
| 651 | /** |
---|
| 652 | * |
---|
| 653 | * |
---|
| 654 | * @return void |
---|
| 655 | */ |
---|
| 656 | public function doDefault() |
---|
| 657 | { |
---|
| 658 | // カート「戻るボタン」用に保持 |
---|
| 659 | $netURL = new Net_URL(); |
---|
| 660 | $_SESSION['cart_referer_url'] = $netURL->getURL(); |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | /** |
---|
| 664 | * |
---|
| 665 | * @return void |
---|
| 666 | */ |
---|
| 667 | public function doMobileSelect() |
---|
| 668 | { |
---|
| 669 | // 規格1が設定されている場合 |
---|
| 670 | if ($this->tpl_classcat_find1) { |
---|
| 671 | // templateの変更 |
---|
| 672 | $this->tpl_mainpage = 'products/select_find1.tpl'; |
---|
| 673 | |
---|
| 674 | return; |
---|
| 675 | } |
---|
| 676 | |
---|
| 677 | // 数量の入力を行う |
---|
| 678 | $this->tpl_mainpage = 'products/select_item.tpl'; |
---|
| 679 | } |
---|
| 680 | |
---|
| 681 | /** |
---|
| 682 | * |
---|
| 683 | * @return void |
---|
| 684 | */ |
---|
| 685 | public function doMobileSelect2() |
---|
| 686 | { |
---|
| 687 | $this->arrErr = $this->lfCheckError($this->mode, $this->objFormParam, $this->tpl_classcat_find1, $this->tpl_classcat_find2); |
---|
| 688 | |
---|
| 689 | // 規格1が設定されていて、エラーを検出した場合 |
---|
| 690 | if ($this->tpl_classcat_find1 and $this->arrErr['classcategory_id1']) { |
---|
| 691 | // templateの変更 |
---|
| 692 | $this->tpl_mainpage = 'products/select_find1.tpl'; |
---|
| 693 | |
---|
| 694 | return; |
---|
| 695 | } |
---|
| 696 | |
---|
| 697 | // 規格2が設定されている場合 |
---|
| 698 | if ($this->tpl_classcat_find2) { |
---|
| 699 | $this->arrErr = array(); |
---|
| 700 | |
---|
| 701 | $this->tpl_mainpage = 'products/select_find2.tpl'; |
---|
| 702 | |
---|
| 703 | return; |
---|
| 704 | } |
---|
| 705 | |
---|
| 706 | $this->doMobileSelectItem(); |
---|
| 707 | } |
---|
| 708 | |
---|
| 709 | /** |
---|
| 710 | * |
---|
| 711 | * @return void |
---|
| 712 | */ |
---|
| 713 | public function doMobileSelectItem() |
---|
| 714 | { |
---|
| 715 | $objProduct = new SC_Product_Ex(); |
---|
| 716 | |
---|
| 717 | $this->arrErr = $this->lfCheckError($this->mode, $this->objFormParam, $this->tpl_classcat_find1, $this->tpl_classcat_find2); |
---|
| 718 | |
---|
| 719 | // この段階では、商品規格ID・数量の入力チェックエラーを出させない。 |
---|
| 720 | // FIXME: エラーチェックの定義で mode で定義を分岐する方が良いように感じる |
---|
| 721 | unset($this->arrErr['product_class_id']); |
---|
| 722 | unset($this->arrErr['quantity']); |
---|
| 723 | |
---|
| 724 | // 規格2が設定されていて、エラーを検出した場合 |
---|
| 725 | if ($this->tpl_classcat_find2 and !empty($this->arrErr)) { |
---|
| 726 | // templateの変更 |
---|
| 727 | $this->tpl_mainpage = 'products/select_find2.tpl'; |
---|
| 728 | |
---|
| 729 | return; |
---|
| 730 | } |
---|
| 731 | |
---|
| 732 | $product_id = $this->objFormParam->getValue('product_id'); |
---|
| 733 | |
---|
| 734 | $value1 = $this->objFormParam->getValue('classcategory_id1'); |
---|
| 735 | if (strlen($value1) === 0) { |
---|
| 736 | $value1 = '__unselected'; |
---|
| 737 | } |
---|
| 738 | |
---|
| 739 | // 規格2が設定されている場合. |
---|
| 740 | if (SC_Utils_Ex::isBlank($this->objFormParam->getValue('classcategory_id2')) == false) { |
---|
| 741 | $value2 = '#' . $this->objFormParam->getValue('classcategory_id2'); |
---|
| 742 | } else { |
---|
| 743 | $value2 = '#0'; |
---|
| 744 | } |
---|
| 745 | |
---|
| 746 | $objProduct->setProductsClassByProductIds(array($product_id)); |
---|
| 747 | $this->tpl_product_class_id = $objProduct->classCategories[$product_id][$value1][$value2]['product_class_id']; |
---|
| 748 | |
---|
| 749 | // 数量の入力を行う |
---|
| 750 | $this->tpl_mainpage = 'products/select_item.tpl'; |
---|
| 751 | } |
---|
| 752 | |
---|
| 753 | /** |
---|
| 754 | * |
---|
| 755 | * @return void |
---|
| 756 | */ |
---|
| 757 | public function doMobileCart() |
---|
| 758 | { |
---|
| 759 | // この段階でエラーが出る場合は、数量の入力エラーのはず |
---|
| 760 | if (count($this->arrErr)) { |
---|
| 761 | // 数量の入力を行う |
---|
| 762 | $this->tpl_mainpage = 'products/select_item.tpl'; |
---|
| 763 | } |
---|
| 764 | } |
---|
| 765 | |
---|
| 766 | /** |
---|
| 767 | * |
---|
| 768 | * @return void |
---|
| 769 | */ |
---|
| 770 | public function doMobileDefault() |
---|
| 771 | { |
---|
| 772 | $this->tpl_mainpage = 'products/detail.tpl'; |
---|
| 773 | } |
---|
| 774 | } |
---|