source: branches/camp/camp-2_5-C/data/class/pages/admin/products/LC_Page_Admin_Products_Product.php @ 19635

Revision 19635, 38.1 KB checked in by kishik, 13 years ago (diff)

商品登録前プレビュー

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 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// {{{ requires
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/**
28 * 商品登録 のページクラス
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Products_Product extends LC_Page {
35
36    // {{{ properties
37
38    /** ファイル管理クラスのインスタンス */
39    var $objUpFile;
40
41    /** ダウンロード用ファイル管理クラスのインスタンス */
42    var $objDownFile;
43
44    /** hidden 項目の配列 */
45    var $arrHidden;
46
47    /** エラー情報 */
48    var $arrErr;
49
50    // }}}
51    // {{{ functions
52
53    /**
54     * Page を初期化する.
55     *
56     * @return void
57     */
58    function init() {
59        parent::init();
60        $this->tpl_mainpage = 'products/product.tpl';
61        $this->tpl_subnavi = 'products/subnavi.tpl';
62        $this->tpl_mainno = 'products';
63        $this->tpl_subno = 'product';
64        $this->tpl_subtitle = '商品登録';
65        $this->arrErr = array();
66
67        $masterData = new SC_DB_MasterData_Ex();
68        $this->arrDISP = $masterData->getMasterData("mtb_disp");
69        $this->arrCLASS = $masterData->getMasterData("mtb_class");
70        $this->arrSTATUS = $masterData->getMasterData("mtb_status");
71        $this->arrSTATUS_IMAGE = $masterData->getMasterData("mtb_status_image");
72        $this->arrDELIVERYDATE = $masterData->getMasterData("mtb_delivery_date");
73        $this->arrAllowedTag = $masterData->getMasterData("mtb_allowed_tag");
74        $this->arrProductType = $masterData->getMasterData("mtb_product_type");
75        $this->arrMaker = SC_Helper_DB_Ex::sfGetIDValueList("dtb_maker", "maker_id", "name");
76        $this->tpl_nonclass = true;
77    }
78
79    /**
80     * Page のプロセス.
81     *
82     * @return void
83     */
84    function process() {
85        $objView = new SC_AdminView();
86        $objSiteInfo = new SC_SiteInfo();
87        $objQuery = new SC_Query();
88        $objDb = new SC_Helper_DB_Ex();
89        $objProduct = new SC_Product();
90
91        // 認証可否の判定
92        $objSess = new SC_Session();
93        SC_Utils_Ex::sfIsSuccess($objSess);
94
95        // Downファイル管理クラス
96        $this->objDownFile = new SC_UploadFile(DOWN_TEMP_DIR, DOWN_SAVE_DIR);
97        // Downファイル情報の初期化
98        $this->lfInitDownFile();
99        // Hiddenからのデータを引き継ぐ
100        $this->objDownFile->setHiddenFileList($_POST);
101
102        // ファイル管理クラス
103        $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_DIR, IMAGE_SAVE_DIR);
104
105        // ファイル情報の初期化
106        $this->lfInitFile();
107        // Hiddenからのデータを引き継ぐ
108        $this->objUpFile->setHiddenFileList($_POST);
109
110        // 規格の有り無し判定
111        $this->tpl_nonclass = !$objDb->sfHasProductClass($_POST['product_id']);
112
113        // 検索パラメータの引き継ぎ
114        foreach ($_POST as $key => $val) {
115            if (ereg("^search_", $key)) {
116                $this->arrSearchHidden[$key] = $val;
117            }
118        }
119
120        // FORMデータの引き継ぎ
121        $this->arrForm = $_POST;
122
123        if (!isset($_POST['mode'])) $_POST['mode'] = "";
124
125        switch($_POST['mode']) {
126            // 検索画面からの編集
127            case 'pre_edit':
128            case 'copy' :
129                if (!SC_Utils_Ex::sfIsInt($_POST['product_id'])) {
130                    SC_Utils_Ex::sfDispException();
131                }
132
133                // DBから商品情報の読込
134                $this->arrForm = $this->lfGetProduct($_POST['product_id']);
135                $productStatus= $objProduct->getProductStatus(array($_POST['product_id']));
136                $this->arrForm['product_status'] = $productStatus[$_POST['product_id']];
137
138                // DBデータから画像ファイル名の読込
139                $this->objUpFile->setDBFileList($this->arrForm);
140                // DBデータからダウンロードファイル名の読込
141                $this->objDownFile->setDBDownFile($this->arrForm);
142
143                // 商品ステータスの変換
144                $arrRet = SC_Utils_Ex::sfSplitCBValue($this->arrForm['product_flag'], "product_flag");
145                $this->arrForm = array_merge($this->arrForm, $arrRet);
146                // DBから関連商品の読み込み
147                $this->lfPreGetRecommendProducts($_POST['product_id']);
148
149                $this->lfProductPage();     // 商品登録ページ
150
151                if($_POST['mode'] == "copy"){
152                    $this->arrForm["copy_product_id"] = $this->arrForm["product_id"];
153                    $this->arrForm["product_id"] = "";
154                    // 画像ファイルのコピー
155                    $arrKey = $this->objUpFile->keyname;
156                    $arrSaveFile = $this->objUpFile->save_file;
157
158                    foreach($arrSaveFile as $key => $val){
159                        $this->lfMakeScaleImage($arrKey[$key], $arrKey[$key], true);
160                    }
161                }
162                break;
163            // 商品登録・編集
164            case 'edit':
165                if($_POST['product_id'] == "" and SC_Utils_Ex::sfIsInt($_POST['copy_product_id'])){
166                    $this->tpl_nonclass = !$objDb->sfHasProductClass($_POST['copy_product_id']);
167                }
168
169                // 入力値の変換
170                $this->arrForm = $this->lfConvertParam($this->arrForm);
171                // エラーチェック
172                $this->arrErr = $this->lfErrorCheck($this->arrForm);
173                // ファイル存在チェック
174                $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS());
175                // エラーなしの場合
176                if(count($this->arrErr) == 0) {
177                    //$this->lfProductConfirmPage(); // 確認ページ
178                    $this->tpl_mainpage = 'products/complete.tpl';
179
180                    $this->arrForm['product_id'] = $this->lfRegistProduct($_POST);      // データ登録
181
182                    // 件数カウントバッチ実行
183                    $objDb->sfCategory_Count($objQuery);
184                    $objDb->sfMaker_Count($objQuery);
185                    // 一時ファイルを本番ディレクトリに移動する
186                    $this->objUpFile->moveTempFile();
187                    $this->objDownFile->moveTempDownFile();
188                    } else {
189                        $this->lfProductPage();     // 商品登録ページ
190                    }
191                break;
192            // 確認ページから完了ページへ
193            case 'complete':
194                $this->tpl_mainpage = 'products/complete.tpl';
195
196                $this->arrForm['product_id'] = $this->lfRegistProduct($_POST);      // データ登録
197
198                // 件数カウントバッチ実行
199                $objDb->sfCategory_Count($objQuery);
200                $objDb->sfMaker_Count($objQuery);
201                // 一時ファイルを本番ディレクトリに移動する
202                $this->objUpFile->moveTempFile();
203                $this->objDownFile->moveTempDownFile();
204
205                break;
206            // 画像のアップロード
207            case 'upload_image':
208                // ファイル存在チェック
209                $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objUpFile->checkEXISTS($_POST['image_key']));
210                // 画像保存処理
211                $this->arrErr[$_POST['image_key']] = $this->objUpFile->makeTempFile($_POST['image_key'],IMAGE_RENAME);
212
213                // 中、小画像生成
214                $this->lfSetScaleImage();
215
216                $this->lfProductPage(); // 商品登録ページ
217                break;
218            // 画像の削除
219            case 'delete_image':
220                $this->objUpFile->deleteFile($_POST['image_key']);
221                $this->lfProductPage(); // 商品登録ページ
222                break;
223            // ダウンロード商品ファイルアップロード
224            case 'upload_down':
225                // ファイル存在チェック
226                $this->arrErr = array_merge((array)$this->arrErr, (array)$this->objDownFile->checkEXISTS($_POST['down_key']));
227                // 画像保存処理
228                $this->arrErr[$_POST['down_key']] = $this->objDownFile->makeTempDownFile();
229
230                $this->lfProductPage(); // 商品登録ページ
231                break;
232            // ダウンロードファイルの削除
233            case 'delete_down':
234                $this->objDownFile->deleteFile($_POST['down_key']);
235                $this->lfProductPage(); // 商品登録ページ
236                break;
237            // 確認ページからの戻り
238            case 'confirm_return':
239                $this->lfProductPage();     // 商品登録ページ
240                break;
241            // 関連商品選択
242            case 'recommend_select' :
243                $this->lfProductPage();     // 商品登録ページ
244                break;
245            case 'preview':
246                $_SESSION['preview'] = $this->arrForm;
247                $this->tpl_javascript = "window.open('".URL_DIR."admin/products/product_preview.php"."','test')";
248                $this->lfProductPage();
249                break;
250            default:
251                $this->lfProductPage();     // 商品登録ページ
252                break;
253        }
254
255        // 関連商品の読み込み
256        $this->arrRecommend = $this->lfGetRecommendProducts();
257
258        // 基本情報を渡す
259        $this->arrInfo = $objSiteInfo->data;
260
261        // サブ情報の入力があるかどうかチェックする
262        $sub_find = false;
263        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
264            if( (isset($this->arrForm['sub_title'.$cnt])
265            && !empty($this->arrForm['sub_title'.$cnt])) ||
266            (isset($this->arrForm['sub_comment'.$cnt])
267            && !empty($this->arrForm['sub_comment'.$cnt])) ||
268            (isset($this->arrForm['sub_image'.$cnt])
269            && !empty($this->arrForm['sub_image'.$cnt])) ||
270            (isset($this->arrForm['sub_large_image'.$cnt])
271            && !empty($this->arrForm['sub_large_image'.$cnt])) ||
272            (isset($this->arrForm['sub_image'.$cnt])
273            && is_array($this->arrFile['sub_image'.$cnt])) ||
274            (isset($this->arrForm['sub_large_image'.$cnt])
275            && is_array($this->arrFile['sub_large_image'.$cnt]))) {
276                $sub_find = true;
277                break;
278            }
279        }
280
281        // サブ情報表示・非表示のチェックに使用する。
282        $this->sub_find = $sub_find;
283        $objView->assignobj($this);
284        $objView->display(MAIN_FRAME);
285    }
286
287    /**
288     * デストラクタ.
289     *
290     * @return void
291     */
292    function destroy() {
293        parent::destroy();
294    }
295
296    /**
297     * 関連商品の名称などを商品マスタから読み込み、一つの配列にまとめて返す
298     *
299     * @return array 関連商品の情報を格納した2次元配列
300     */
301    function lfGetRecommendProducts() {
302        $objQuery = new SC_Query();
303        $arrRecommend = array();
304        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
305            $keyname = "recommend_id" . $i;
306            $delkey = "recommend_delete" . $i;
307            $commentkey = "recommend_comment" . $i;
308
309            if (!isset($this->arrForm[$delkey])) $this->arrForm[$delkey] = null;
310
311            if((isset($this->arrForm[$keyname]) && !empty($this->arrForm[$keyname])) && $this->arrForm[$delkey] != 1) {
312                $objProduct = new SC_Product();
313                $arrRecommend[$i] = $objProduct->getDetail($this->arrForm[$keyname]);
314                $arrRecommend[$i]['product_id'] = $this->arrForm[$keyname];
315                $arrRecommend[$i]['comment'] = $this->arrForm[$commentkey];
316            }
317        }
318        return $arrRecommend;
319    }
320
321    /* 関連商品の登録 */
322    function lfInsertRecommendProducts($objQuery, $arrList, $product_id) {
323        // 一旦関連商品をすべて削除する
324        $objQuery->delete("dtb_recommend_products", "product_id = ?", array($product_id));
325        $sqlval['product_id'] = $product_id;
326        $rank = RECOMMEND_PRODUCT_MAX;
327        for($i = 1; $i <= RECOMMEND_PRODUCT_MAX; $i++) {
328            $keyname = "recommend_id" . $i;
329            $commentkey = "recommend_comment" . $i;
330            $deletekey = "recommend_delete" . $i;
331
332            if (!isset($arrList[$deletekey])) $arrList[$deletekey] = null;
333
334            if($arrList[$keyname] != "" && $arrList[$deletekey] != '1') {
335                $sqlval['recommend_product_id'] = $arrList[$keyname];
336                $sqlval['comment'] = $arrList[$commentkey];
337                $sqlval['rank'] = $rank;
338                $sqlval['creator_id'] = $_SESSION['member_id'];
339                $sqlval['create_date'] = "now()";
340                $sqlval['update_date'] = "now()";
341                $objQuery->insert("dtb_recommend_products", $sqlval);
342                $rank--;
343            }
344        }
345    }
346
347    /**
348     * 指定商品の関連商品をDBから読み込む
349     *
350     * @param string $product_id 商品ID
351     * @return void
352     */
353    function lfPreGetRecommendProducts($product_id) {
354        $objQuery = new SC_Query();
355        $objQuery->setOrder("rank DESC");
356        $arrRet = $objQuery->select("recommend_product_id, comment", "dtb_recommend_products", "product_id = ?", array($product_id));
357        $no = 1;
358
359        foreach ($arrRet as $ret) {
360            $this->arrForm['recommend_id' . $no] = $ret['recommend_product_id'];
361            $this->arrForm['recommend_comment' . $no] = $ret['comment'];
362            $no++;
363        }
364    }
365
366    /* 商品情報の読み込み */
367    function lfGetProduct($product_id) {
368        $objQuery = new SC_Query();
369        $objDb = new SC_Helper_DB_Ex();
370
371        $col = "*";
372        $table = <<< __EOF__
373                      dtb_products AS T1
374            LEFT JOIN (
375                       SELECT product_id AS product_id_sub,
376                              product_code,
377                              price01,
378                              price02,
379                              stock,
380                              stock_unlimited,
381                              sale_limit,
382                              point_rate,
383                              product_type_id,
384                              down_filename,
385                              down_realfilename
386                         FROM dtb_products_class
387                        WHERE class_combination_id IS NULL
388                       ) AS T2
389                     ON T1.product_id = T2.product_id_sub
390__EOF__;
391        $where = "product_id = ?";
392
393        $arrRet = $objQuery->select($col, $table, $where, array($product_id));
394
395        // カテゴリID を取得
396        $arrRet[0]['category_id'] = $objQuery->getCol("dtb_product_categories",
397                                                      "category_id",
398                                                      "product_id = ?",
399        array($product_id));
400        //編集時に規格IDが変わってしまうのを防ぐために規格が登録されていなければ規格IDを取得する
401        if (!$objDb->sfHasProductClass($_POST['product_id'])) {
402            $arrRet[0]['product_class_id'] = SC_Utils::sfGetProductClassId($product_id,"0","0");
403        }
404        return $arrRet[0];
405    }
406
407    /* 商品登録ページ表示用 */
408    function lfProductPage() {
409        $objDb = new SC_Helper_DB_Ex();
410
411        // カテゴリの読込
412        list($this->arrCatVal, $this->arrCatOut) = $objDb->sfGetLevelCatList(false);
413
414        if (isset($this->arrForm['category_id']) && !is_array($this->arrForm['category_id'])) {
415            $this->arrForm['category_id'] = unserialize($this->arrForm['category_id']);
416        }
417        if($this->arrForm['status'] == "") {
418            $this->arrForm['status'] = DEFAULT_PRODUCT_DISP;
419        }
420        if($this->arrForm['product_type_id'] == "") {
421            $this->arrForm['product_type_id'] = DEFAULT_PRODUCT_DOWN;
422        }
423
424        // HIDDEN用に配列を渡す。
425        $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objUpFile->getHiddenFileList());
426        $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objDownFile->getHiddenFileList());
427        // Form用配列を渡す。
428        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
429
430        $this->arrForm['down_realfilename'] = $this->objDownFile->getFormDownFile();
431
432        // アンカーを設定
433        if (isset($_POST['image_key']) && !empty($_POST['image_key'])) {
434            $anchor_hash = "location.hash='#" . $_POST['image_key'] . "'";
435        } elseif (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
436            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
437        } else {
438            $anchor_hash = "";
439        }
440
441        $this->tpl_onload = "fnCheckStockLimit('" . DISABLED_RGB . "'); fnMoveSelect('category_id_unselect', 'category_id');" . $anchor_hash;
442    }
443
444    /* ファイル情報の初期化 */
445    function lfInitFile() {
446        $this->objUpFile->addFile("一覧-メイン画像", 'main_list_image', array('jpg', 'gif', 'png'),IMAGE_SIZE, false, SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT);
447        $this->objUpFile->addFile("詳細-メイン画像", 'main_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_IMAGE_WIDTH, NORMAL_IMAGE_HEIGHT);
448        $this->objUpFile->addFile("詳細-メイン拡大画像", 'main_large_image', array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_IMAGE_WIDTH, LARGE_IMAGE_HEIGHT);
449        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
450            $this->objUpFile->addFile("詳細-サブ画像$cnt", "sub_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, NORMAL_SUBIMAGE_WIDTH, NORMAL_SUBIMAGE_HEIGHT);
451            $this->objUpFile->addFile("詳細-サブ拡大画像$cnt", "sub_large_image$cnt", array('jpg', 'gif', 'png'), IMAGE_SIZE, false, LARGE_SUBIMAGE_WIDTH, LARGE_SUBIMAGE_HEIGHT);
452        }
453    }
454
455    /* 商品の登録 */
456    function lfRegistProduct($arrList) {
457        $objQuery = new SC_Query();
458        $objDb = new SC_Helper_DB_Ex();
459        $objQuery->begin();
460
461        // 配列の添字を定義
462        $checkArray = array("name", "status",
463                            "main_list_comment", "main_comment",
464                            "deliv_fee", "comment1", "comment2", "comment3",
465                            "comment4", "comment5", "comment6", "main_list_comment",
466                            "sale_limit", "deliv_date_id", "maker_id", "note");
467        $arrList = SC_Utils_Ex::arrayDefineIndexes($arrList, $checkArray);
468
469        // INSERTする値を作成する。
470        $sqlval['name'] = $arrList['name'];
471        $sqlval['status'] = $arrList['status'];
472        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
473        $sqlval['main_comment'] = $arrList['main_comment'];
474        $sqlval['comment1'] = $arrList['comment1'];
475        $sqlval['comment2'] = $arrList['comment2'];
476        $sqlval['comment3'] = $arrList['comment3'];
477        $sqlval['comment4'] = $arrList['comment4'];
478        $sqlval['comment5'] = $arrList['comment5'];
479        $sqlval['comment6'] = $arrList['comment6'];
480        $sqlval['main_list_comment'] = $arrList['main_list_comment'];
481        $sqlval['deliv_date_id'] = $arrList['deliv_date_id'];
482        $sqlval['maker_id'] = $arrList['maker_id'];
483        $sqlval['note'] = $arrList['note'];
484        $sqlval['update_date'] = "Now()";
485        $sqlval['creator_id'] = $_SESSION['member_id'];
486        $arrRet = $this->objUpFile->getDBFileList();
487        $sqlval = array_merge($sqlval, $arrRet);
488
489        $arrList['category_id'] = unserialize($arrList['category_id']);
490
491        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
492            $sqlval['sub_title'.$cnt] = $arrList['sub_title'.$cnt];
493            $sqlval['sub_comment'.$cnt] = $arrList['sub_comment'.$cnt];
494        }
495
496        // 新規登録(複製時を含む)
497        if ($arrList['product_id'] == "") {
498            $product_id = $objQuery->nextVal("dtb_products_product_id");
499            $sqlval['product_id'] = $product_id;
500
501            // INSERTの実行
502            $sqlval['create_date'] = "Now()";
503            $objQuery->insert("dtb_products", $sqlval);
504
505            $arrList['product_id'] = $product_id;
506
507            // カテゴリを更新
508            $objDb->updateProductCategories($arrList['category_id'], $product_id);
509
510            // 複製商品の場合には規格も複製する
511            if($_POST["copy_product_id"] != "" and SC_Utils_Ex::sfIsInt($_POST["copy_product_id"])){
512
513                if($this->tpl_nonclass)
514                {
515                    //規格なしの場合、複製は価格等の入力が発生しているため、その内容で追加登録を行う
516                    $this->lfCopyProductClass($arrList, $objQuery);
517                }
518                else
519                {
520                    //規格がある場合の複製は複製元の内容で追加登録を行う
521                    // dtb_products_class のカラムを取得
522                    $dbFactory = SC_DB_DBFactory_Ex::getInstance();
523                    $arrColList = $dbFactory->sfGetColumnList("dtb_products_class", $objQuery);
524                    $arrColList_tmp = array_flip($arrColList);
525
526                    // 複製しない列
527                    unset($arrColList[$arrColList_tmp["product_class_id"]]);     //規格ID
528                    unset($arrColList[$arrColList_tmp["product_id"]]);           //商品ID
529                    unset($arrColList[$arrColList_tmp["create_date"]]);
530
531                    $col = SC_Utils_Ex::sfGetCommaList($arrColList);
532                    $product_class_id = $objQuery->nextVal('dtb_products_class_product_class_id');
533                    $objQuery->query("INSERT INTO dtb_products_class (product_class_id, product_id, create_date, ". $col .") SELECT ?, now(), " . $col. " FROM dtb_products_class WHERE product_id = ? ORDER BY product_class_id", array($product_class_id, $product_id, $_POST["copy_product_id"]));
534                }
535            }
536        }
537        // 更新
538        else {
539            $product_id = $arrList['product_id'];
540            // 削除要求のあった既存ファイルの削除
541            $arrRet = $this->lfGetProduct($arrList['product_id']);
542            $this->objUpFile->deleteDBFile($arrRet);
543            $this->objDownFile->deleteDBDownFile($arrRet);
544
545            // UPDATEの実行
546            $where = "product_id = ?";
547            $objQuery->update("dtb_products", $sqlval, $where, array($product_id));
548
549            // カテゴリを更新
550            $objDb->updateProductCategories($arrList['category_id'], $product_id);
551        }
552
553        //商品登録の時は規格を生成する。複製の場合は規格も複製されるのでこの処理は不要。
554        if( $_POST["copy_product_id"] == "" ){
555            // 規格登録
556            $this->lfInsertDummyProductClass($arrList);
557        }
558
559        // ステータス設定
560        $objProduct = new SC_Product();
561        $objProduct->setProductStatus($product_id, $arrList['product_status']);
562
563        // 関連商品登録
564        $this->lfInsertRecommendProducts($objQuery, $arrList, $product_id);
565
566        $objQuery->commit();
567        return $product_id;
568    }
569
570
571    /* 取得文字列の変換 */
572    function lfConvertParam($array) {
573        /*
574         *  文字列の変換
575         *  K :  「半角(ハンカク)片仮名」を「全角片仮名」に変換
576         *  C :  「全角ひら仮名」を「全角かた仮名」に変換
577         *  V :  濁点付きの文字を一文字に変換。"K","H"と共に使用します
578         *  n :  「全角」数字を「半角(ハンカク)」に変換
579         */
580
581        // スポット商品
582        $arrConvList['name'] = "KVa";
583        $arrConvList['main_list_comment'] = "KVa";
584        $arrConvList['main_comment'] = "KVa";
585        $arrConvList['price01'] = "n";
586        $arrConvList['price02'] = "n";
587        $arrConvList['stock'] = "n";
588        $arrConvList['sale_limit'] = "n";
589        $arrConvList['point_rate'] = "n";
590        $arrConvList['product_code'] = "KVna";
591        $arrConvList['comment1'] = "a";
592        $arrConvList['deliv_fee'] = "n";
593
594        // 詳細-サブ
595        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
596            $arrConvList["sub_title$cnt"] = "KVa";
597        }
598        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
599            $arrConvList["sub_comment$cnt"] = "KVa";
600        }
601
602        // 関連商品
603        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
604            $arrConvList["recommend_comment$cnt"] = "KVa";
605        }
606
607        // 文字変換
608        foreach ($arrConvList as $key => $val) {
609            // POSTされてきた値のみ変換する。
610            if(isset($array[$key])) {
611                $array[$key] = mb_convert_kana($array[$key] ,$val);
612            }
613        }
614
615        if (!isset($array['product_flag'])) $array['product_flag'] = "";
616        $max = max(array_keys($this->arrSTATUS));
617        $array['product_flag'] = SC_Utils_Ex::sfMergeCheckBoxes($array['product_flag'], $max);
618
619        return $array;
620    }
621
622    // 入力エラーチェック
623    function lfErrorCheck($array) {
624
625        $objErr = new SC_CheckError($array);
626        $objErr->doFunc(array("商品名", "name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
627        $objErr->doFunc(array("一覧-メインコメント", "main_list_comment", MTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
628        $objErr->doFunc(array("詳細-メインコメント", "main_comment", LLTEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
629        $objErr->doFunc(array("詳細-メインコメント", "main_comment", $this->arrAllowedTag), array("HTML_TAG_CHECK"));
630        $objErr->doFunc(array("ポイント付与率", "point_rate", PERCENTAGE_LEN), array("EXIST_CHECK", "NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
631        $objErr->doFunc(array("商品送料", "deliv_fee", PRICE_LEN), array("NUM_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
632        $objErr->doFunc(array("備考欄(SHOP専用)", "note", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
633        $objErr->doFunc(array("検索ワード", "comment3", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
634        $objErr->doFunc(array("メーカーURL", "comment1", URL_LEN), array("SPTAB_CHECK", "URL_CHECK", "MAX_LENGTH_CHECK"));
635        $objErr->doFunc(array("発送日目安", "deliv_date_id", INT_LEN), array("NUM_CHECK"));
636        $objErr->doFunc(array("メーカー", 'maker_id', INT_LEN), array("NUM_CHECK"));
637
638        if($this->tpl_nonclass) {
639            $objErr->doFunc(array("商品コード", "product_code", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK","MAX_LENGTH_CHECK"));
640            $objErr->doFunc(array(NORMAL_PRICE_TITLE, "price01", PRICE_LEN), array("NUM_CHECK", "MAX_LENGTH_CHECK"));
641            $objErr->doFunc(array(SALE_PRICE_TITLE, "price02", PRICE_LEN), array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
642
643            if(!isset($array['stock_unlimited']) && $array['stock_unlimited'] != "1") {
644                $objErr->doFunc(array("在庫数", "stock", AMOUNT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
645            }
646
647            //ダウンロード商品チェック
648            if($array['product_type_id'] == PRODUCT_TYPE_DOWNLOAD) {
649                $objErr->doFunc(array("ダウンロードファイル名", "down_filename", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
650                if($array['down_realfilename'] == "") {
651                    $objErr->arrErr['down_realfilename'] = "※ ダウンロード商品の場合はダウンロード商品用ファイルをアップロードしてください。<br />";
652                }
653            }
654            //実商品チェック
655            if($array['product_type_id'] == PRODUCT_TYPE_NORMAL) {
656                if($array['down_filename'] != "") {
657                    $objErr->arrErr['down_filename'] = "※ 通常商品の場合はダウンロードファイル名を設定できません。<br />";
658                }
659                if($array['down_realfilename'] != "") {
660                    $objErr->arrErr['down_realfilename'] = "※ 通常商品の場合はダウンロード商品用ファイルをアップロードできません。<br />ファイルを取り消してください。<br />";
661                }
662            }
663        }
664
665        $objErr->doFunc(array("購入制限", "sale_limit", AMOUNT_LEN), array("SPTAB_CHECK", "ZERO_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
666
667        for ($cnt = 1; $cnt <= PRODUCTSUB_MAX; $cnt++) {
668            $objErr->doFunc(array("詳細-サブタイトル$cnt", "sub_title$cnt", STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
669            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", LLTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
670            $objErr->doFunc(array("詳細-サブコメント$cnt", "sub_comment$cnt", $this->arrAllowedTag),  array("HTML_TAG_CHECK"));
671        }
672
673        for ($cnt = 1; $cnt <= RECOMMEND_PRODUCT_MAX; $cnt++) {
674
675            if (!isset($_POST["recommend_delete$cnt"]))  $_POST["recommend_delete$cnt"] = "";
676
677            if(isset($_POST["recommend_id$cnt"])
678            && $_POST["recommend_id$cnt"] != ""
679            && $_POST["recommend_delete$cnt"] != 1) {
680                $objErr->doFunc(array("関連商品コメント$cnt", "recommend_comment$cnt", LTEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
681            }
682        }
683
684        // カテゴリID のチェック
685        if (empty($array['category_id'])) {
686            $objErr->arrErr['category_id'] = "※ 商品カテゴリが選択されていません。<br />";
687        } else {
688            $arrCategory_id = array();
689            for ($i = 0; $i < count($array['category_id']); $i++) {
690                $arrCategory_id['category_id' . $i] = $array['category_id'][$i];
691            }
692            $objCheckCategory = new SC_CheckError($arrCategory_id);
693            for ($i = 0; $i < count($array['category_id']); $i++) {
694                $objCheckCategory->doFunc(array("商品カテゴリ", "category_id" . $i, STEXT_LEN), array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
695            }
696            if (!empty($objCheckCategory->arrErr)) {
697                $objErr->arrErr = array_merge($objErr->arrErr,
698                $objCheckCategory->arrErr);
699            }
700        }
701        return $objErr->arrErr;
702    }
703
704    /* 確認ページ表示用 */
705    function lfProductConfirmPage() {
706        $this->tpl_mainpage = 'products/confirm.tpl';
707        $this->arrForm['mode'] = 'complete';
708
709        $objDb = new SC_Helper_DB_Ex();
710
711        // カテゴリ表示
712        $this->arrCategory_id = $this->arrForm['category_id'];
713        $this->arrCatList = array();
714        list($arrCatVal, $arrCatOut) = $objDb->sfGetLevelCatList(false);
715        for ($i = 0; $i < count($arrCatVal); $i++) {
716            $this->arrCatList[$arrCatVal[$i]] = $arrCatOut[$i];
717        }
718
719        // hidden に渡す値は serialize する
720        $this->arrForm['category_id'] = serialize($this->arrForm['category_id']);
721
722        // Form用配列を渡す。
723        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URL, IMAGE_SAVE_URL);
724        $this->arrForm['down_realfilename'] = $this->objDownFile->getFormDownFile();
725    }
726
727    // 縮小した画像をセットする
728    function lfSetScaleImage(){
729
730        $subno = str_replace("sub_large_image", "", $_POST['image_key']);
731        switch ($_POST['image_key']){
732            case "main_large_image":
733                // 詳細メイン画像
734                $this->lfMakeScaleImage($_POST['image_key'], "main_image");
735            case "main_image":
736                // 一覧メイン画像
737                $this->lfMakeScaleImage($_POST['image_key'], "main_list_image");
738                break;
739            case "sub_large_image" . $subno:
740                // サブメイン画像
741                $this->lfMakeScaleImage($_POST['image_key'], "sub_image" . $subno);
742                break;
743            default:
744                break;
745        }
746    }
747
748    // 縮小画像生成
749    function lfMakeScaleImage($from_key, $to_key, $forced = false){
750        $arrImageKey = array_flip($this->objUpFile->keyname);
751
752        if($this->objUpFile->temp_file[$arrImageKey[$from_key]]){
753            $from_path = $this->objUpFile->temp_dir . $this->objUpFile->temp_file[$arrImageKey[$from_key]];
754        }elseif($this->objUpFile->save_file[$arrImageKey[$from_key]]){
755            $from_path = $this->objUpFile->save_dir . $this->objUpFile->save_file[$arrImageKey[$from_key]];
756        }else{
757            return "";
758        }
759
760        if(file_exists($from_path)){
761            // 生成先の画像サイズを取得
762            $to_w = $this->objUpFile->width[$arrImageKey[$to_key]];
763            $to_h = $this->objUpFile->height[$arrImageKey[$to_key]];
764
765            if($forced) $this->objUpFile->save_file[$arrImageKey[$to_key]] = "";
766
767            if(empty($this->objUpFile->temp_file[$arrImageKey[$to_key]]) &&
768            empty($this->objUpFile->save_file[$arrImageKey[$to_key]])) {
769
770                // リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
771                $dst_file = $this->objUpFile->lfGetTmpImageName(IMAGE_RENAME, "", $this->objUpFile->temp_file[$arrImageKey[$from_key]]) . $this->lfGetAddSuffix($to_key);
772                $path = $this->objUpFile->makeThumb($from_path, $to_w, $to_h, $dst_file);
773                $this->objUpFile->temp_file[$arrImageKey[$to_key]] = basename($path);
774            }
775        }else{
776            return "";
777        }
778    }
779
780    /**
781     * リネームする際は、自動生成される画像名に一意となるように、Suffixを付ける
782     */
783    function lfGetAddSuffix($to_key){
784        if( IMAGE_RENAME === true ){ return ; }
785
786        // 自動生成される画像名
787        $dist_name = "";
788        switch($to_key){
789            case "main_list_image":
790                $dist_name = '_s';
791                break;
792            case "main_image":
793                $dist_name = '_m';
794                break;
795            default:
796                $arrRet = explode('sub_image', $to_key);
797                $dist_name = '_sub' .$arrRet[1];
798                break;
799        }
800        return $dist_name;
801    }
802
803    /**
804     * dtb_products_classの複製
805     * 複製後、価格や商品コードを更新する
806     *
807     * @param array $arrList
808     * @param array $objQuery
809     * @return bool
810     */
811    function lfCopyProductClass($arrList,$objQuery)
812    {
813        // 複製元のdtb_products_classを取得(規格なしのため、1件のみの取得)
814        $col = "*";
815        $table = "dtb_products_class";
816        $where = "product_id = ?";
817        $arrProductClass = $objQuery->select($col, $table, $where, array($arrList["copy_product_id"]));
818
819        //トランザクション開始
820        $objQuery->begin();
821        $err_flag = false;
822        //非編集項目は複製、編集項目は上書きして登録
823        foreach($arrProductClass as $records)
824        {
825            foreach($records as $key => $value)
826            {
827                if(isset($arrList[$key]))
828                {
829                    $records[$key] = $arrList[$key];
830                }
831            }
832
833            $records["product_class_id"] = $objQuery->nextVal('dtb_products_class_product_class_id');
834            unset($records["update_date"]);
835
836            $records["create_date"] = "Now()";
837            $objQuery->insert($table, $records);
838            //エラー発生時は中断
839            if($objQuery->isError())
840            {
841                $err_flag = true;
842                continue;
843            }
844        }
845        //トランザクション終了
846        if($err_flag)
847        {
848            $objQuery->rollback();
849        }
850        else
851        {
852            $objQuery->commit();
853        }
854        return !$err_flag;
855    }
856
857    /**
858     * 規格を設定していない商品を商品規格テーブルに登録
859     *
860     * @param array $arrList
861     * @return void
862     */
863    function lfInsertDummyProductClass($arrList) {
864        $objQuery  = new SC_Query();
865        $objDb = new SC_Helper_DB_Ex();
866
867        $product_id = $arrList['product_id'];
868        // 規格登録してある商品の場合、処理しない
869        if ($objDb->sfHasProductClass($product_id)) return;
870
871        // 配列の添字を定義
872        $checkArray = array('product_class_id', 'product_id', 'product_code', 'stock', 'stock_unlimited', 'price01', 'price02', 'sale_limit', 'deliv_fee', 'point_rate' ,'product_type_id', 'down_filename', 'down_realfilename');
873        $sqlval = SC_Utils_Ex::sfArrayIntersectKeys($arrList, $checkArray);
874        $sqlval = SC_Utils_Ex::arrayDefineIndexes($sqlval, $checkArray);
875
876        $sqlval['stock_unlimited'] = $sqlval['stock_unlimited'] ? '1' : '0';
877        $sqlval['creator_id'] = strlen($_SESSION['member_id']) >= 1 ? $_SESSION['member_id'] : '0';
878
879        if (strlen($sqlval['product_class_id']) == 0) {
880            $sqlval['product_class_id'] = $objQuery->nextVal('dtb_products_class_product_class_id');
881            $sqlval['create_date'] = 'now()';
882            $sqlval['update_date'] = 'now()';
883            // INSERTの実行
884            $objQuery->insert('dtb_products_class', $sqlval);
885        } else {
886            $sqlval['update_date'] = 'now()';
887            // UPDATEの実行
888            $objQuery->update('dtb_products_class', $sqlval, "product_class_id = ?", array($sqlval['product_class_id']));
889
890        }
891    }
892
893    /* ダウンロードファイル情報の初期化 */
894    function lfInitDownFile() {
895        $this->objDownFile->addFile("ダウンロード販売用ファイル", 'down_file', explode(",", DOWNLOAD_EXTENSION),DOWN_SIZE, true, 0, 0);
896    }
897}
898?>
Note: See TracBrowser for help on using the repository browser.