Eccube

ECCUBE2系統&3系統のポイント共有(覚書)

オリジナルのポイントプラグインがありますので、
一般的なお話ではありません。

覚書ので、お探しの情報でないことが濃厚です。

 

2系統と3系統の併用なんて、、、

 

誰が、興味あるねん?

後半は、購入金額に基づく、付与率を実装しているので、
そっちが、有益かも。
ポイント付与率の関連は、ファイル名の後ろに、※つけてます。

***

さて、

ECCUBE3には、ポイントの機能が標準でなく、
プラグインを追加することになるため、
2系統の標準のポイント機能とは、共通性がないため、使えない。

3系統は触りたくないので、
2系統から3系統のテーブルを参照し、値を共有する。

/data/class_ex/SC_Customer_Ex.php

カート内など、session上に保存したデータを引っ張ってくる関数だけど、
pointだけは、リアルタイムで拾っているので、コードを追加。

    public function getValue($keyname)
    {
        // ポイントはリアルタイム表示
        if ($keyname == 'point') {
            $objQuery = SC_Query_Ex::getSingletonInstance();
//            $point = $objQuery->get('point', extrenal_db. 'dtb_customer', 'customer_id = ?', array($_SESSION['customer']['customer_id']));

				// 2021-12-12 * ECCUBE3ポイント専用テーブルを参照
				$objQuery->setorder('order_id desc');
				$objQuery->setlimit(1);
				$arrRet = $objQuery->select('point_current', extrenal_db. 'plg_point_order_point', 'customer_id = ?', array($_SESSION['customer']['customer_id']));
				$point = $arrRet[0]['point_current'];
#var_dump($point);

            $_SESSION['customer']['point'] = $point;
            return $point;
        } else {
            return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : '';
        }
    }

/data/class_ex/SC_Helper_Customer_Ex.php

管理画面や、マイページなどで使用されてるんかな?

    public function sfGetCustomerData($customer_id, $mask_flg = true)
    {
        $objQuery       = SC_Query_Ex::getSingletonInstance();

        // 会員情報DB取得
        $ret        = $objQuery->select('*', 'dtb_customer', 'customer_id=? AND del_flg = 0', array($customer_id));

        if (empty($ret)) {
            trigger_error('存在しない会員IDです。', E_USER_ERROR);
        }

        $arrForm    = $ret[0];

        // 確認項目に複製
        $arrForm['email02'] = $arrForm['email'];
        $arrForm['email_mobile02'] = $arrForm['email_mobile'];

        // 誕生日を年月日に分ける
        if (isset($arrForm['birth'])) {
            $birth = explode(' ', $arrForm['birth']);
            list($arrForm['year'], $arrForm['month'], $arrForm['day']) = array_map("intval",explode('-', $birth[0]));
        }

        if ($mask_flg) {
            $arrForm['password']          = DEFAULT_PASSWORD;
            $arrForm['password02']        = DEFAULT_PASSWORD;
            $arrForm['reminder_answer']   = DEFAULT_PASSWORD;
        }

				// 2021-12-12 * ECCUBE3ポイント専用テーブルを参照
				$objQuery->setorder('order_id desc');
				$objQuery->setlimit(1);
				$arrRet = $objQuery->select('point_current', extrenal_db. 'plg_point_order_point', 'customer_id = ?', array($customer_id));
				$point = $arrRet[0]['point_current'];
#var_dump($point);
				$arrForm['point']	= $point;

        return $arrForm;
    }

/data/class_ex/SC_CartSession_Ex.php ※

今回、ソースを追いかけて、驚いたのだけど、

管理画面 > 基本設定 > ポイント設定で、1%とした場合、
今回の付与は、0となりました。

1%とした後に、商品を追加したところ、
商品のポイント付与率の初期値に、1が入っていました。

つまり、商品ごとに設定しないといけない仕様ようですね?

 

でも、必須項目だから、NULLにすることも出来ず、
この商品には、付与したくない場合は、0にするわけで。

まあ、独自案件なんで、「付与しない商品」は無いことし、
0の場合は、初期値を反映します。

    public function getAllProductsPoint($productTypeId)
    {
        // ポイント合計
        $total = 0;
        if (USE_POINT !== false) {
			// 2021-12-12
			$BasisData = SC_Helper_DB_Ex::sfGetBasisData();
#var_dump2(array('基本レート' => $arrRet['point_rate']));

            $max = $this->getMax($productTypeId);
            for ($i = 0; $i <= $max; $i++) { $price = $this->cartSession[$productTypeId][$i]['price'];
                $quantity = $this->cartSession[$productTypeId][$i]['quantity'];

//                if (!isset($this->cartSession[$productTypeId][$i]['point_rate'])) {
//                    $this->cartSession[$productTypeId][$i]['point_rate'] = '';
				// 2021-12-12 * 商品にポイントが入っていない時は、初期値を使う
				if (empty($this->cartSession[$productTypeId][$i]['point_rate'])) {
					$this->cartSession[$productTypeId][$i]['point_rate'] = $BasisData['point_rate'];
				}

                $point_rate = $this->cartSession[$productTypeId][$i]['point_rate'];
				// 2021-12-12 * 
				global $customer_rank_rate;
				if (!empty($_SESSION['customer']['customer_rank'])) {
					$point_rate	= $point_rate * $customer_rank_rate[$_SESSION['customer']['customer_rank']];
				}
                $point = SC_Utils_Ex::sfPrePoint($price, $point_rate);
                $total += ($point * (int) $quantity);

#var_dump(array('point_rate' => $point_rate, 'price' => $price, 'total' => $total));
            }
        }
        return $total;
    }

 

/data/class_ex/util_ex/SC_Util_Ex.php ※

ポイント払いをした場合、付与するポイントを減算

        public static function sfGetAddPoint($totalpoint, $use_point, $point_rate)
    {
		// 2021-12-12 * 
		global $customer_rank_rate;
		if (!empty($_SESSION['customer']['customer_rank'])) {
			$point_rate	= $point_rate * $customer_rank_rate[$_SESSION['customer']['customer_rank']];
		}

        // 購入商品の合計ポイントから利用したポイントのポイント換算価値を引く方式
        $add_point = $totalpoint - intval($use_point * ($point_rate / 100));

        if ($add_point < 0) {
            $add_point = '0';
        }

        return $add_point;
    }

*

-

ECCUBE2.13(2.17)* おすすめ商品の機能をもう1つ(簡易版)

標準では、管理画面の

コンテンツ管理 > おすすめ商品

の機能ですが、

専用項目として、もう1つほしかったので、
完コピすると、とってもめんどくさいので、
簡易的なものを作りました。

***

完全にコピーする方法は、こちらにおまかせするとして、

https://www.thank-u.net/blog/eccube/eccube_best5copy/

今回は、簡易版です。
なので、データベースは用いず、商品CDの配列を用います。
よって、
管理画面からの修正も、しません。

また、商品のコメントには、一覧-メインコメントを表示してます。

 

1. ブロックの追加

デザイン管理 > PC > ブロック より、新しいブロックを登録します。

テンプレートは、オリジナルの「おすすめ商品」より、
丸コピーし、

このままだと、オリジナルのおすすめを表示することになるので、
2箇所変更を加えます。

$arrBestProducts >> $arrBestProducts2

に、書き換えます。

ECCUBE2.13 おすすめブロックを増やす

 

2. データベースをいじる

phpMyAdminを開き、dtb_blockに、
上記で追加したブロックを探し、

php_pathに、「frontparts/bloc/recommend2.php」に変更します。

要は、先程追加した、ブロックは、
単にテンプレートなので、これに付随する専用のプログラムを作る
ということですね。

ECCUBE2.13 おすすめブロックを増やす

3. frontparts/bloc/recommend2.phpを作る

本来は、/data/class_exとかで、ゴリゴリするのですが、
無駄なので、1ファイルで。

オリジナルコードは、
/_data/class/pages/frontparts/bloc/LC_Page_FrontParts_Bloc.php
から、丸コピーし、

/frontparts/block/reccomend.php
と、フュージョンしたものが、以下のコードで、
これを、/frontparts/block/reccomend2.phpとして、保存しています。

上記の通り、今回は、簡易版なので、
配列で必要な商品を列記しているのがキモですね。


<?php /* * This file is part of EC-CUBE * * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved. * * http://www.lockon.co.jp/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ require_once realpath(dirname(__FILE__)) . '/../../require.php'; //require_once CLASS_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Recommend_Ex.php'; require_once CLASS_EX_REALDIR . 'page_extends/frontparts/bloc/LC_Page_FrontParts_Bloc_Ex.php'; /** * Recommend のページクラス. * * @package Page * @author EC-CUBE CO.,LTD. * @version $Id$ */ class LC_Page_FrontParts_Bloc_Recommend2 extends LC_Page_FrontParts_Bloc_Ex { /** * Page を初期化する. * * @return void */ public function init() { parent::init(); } /** * Page のプロセス. * * @return void */ public function process() { $this->action();
        $this->sendResponse();
    }

    /**
     * Page のアクション.
     *
     * @return void
     */
    public function action()
    {
        // 基本情報を渡す
        $objSiteInfo = SC_Helper_DB_Ex::sfGetBasisData();
        $this->arrInfo = $objSiteInfo->data;

        //おすすめ商品表示
        $this->arrBestProducts2 = $this->lfGetRanking();
    }

    /**
     * おすすめ商品検索.
     *
     * @return array $arrBestProducts 検索結果配列
     */
    public function lfGetRanking()
    {
//        $objRecommend = new SC_Helper_BestProducts_Ex();

        // おすすめ商品取得
//        $arrRecommends = $objRecommend->getList(RECOMMEND_NUM);
//var_dump3($arrRecommends, __FILE__);

        $response = array();

//        if (count($arrRecommends) > 0) {
            // 商品一覧を取得
            $objQuery = SC_Query_Ex::getSingletonInstance();
            $objProduct = new SC_Product_Ex();
/*
            // where条件生成&セット
            $arrProductId = array();
            foreach ($arrRecommends as $key => $val) {
                $arrProductId[] = $val['product_id'];
            }
*/
			// 2021-12-08 * ここで、表示する商品を定義。
			$arrProductId	= array(24, 25, 26, 27, 28);
#var_dump($arrProductId);
            $arrProducts = $objProduct->getListByProductIds($objQuery, $arrProductId);
#var_dump($arrProducts);

            // 税込金額を設定する
            SC_Product_Ex::setIncTaxToProducts($arrProducts);

            // おすすめ商品情報にマージ
//            foreach ($arrRecommends as $key => $value) {
			foreach ($arrProductId as $key => $value) {
//                if (isset($arrProducts[$value['product_id']])) {
//                    $product = $arrProducts[$value['product_id']];
                if (isset($arrProducts[$value])) {
                    $product = $arrProducts[$value];
                    if ($product['status'] == 1 && (!NOSTOCK_HIDDEN || ($product['stock_max'] >= 1 || $product['stock_unlimited_max'] == 1))) {
                        $response[] = $arrProducts[$value];
                    }
                } else {
                    // 削除済み商品は除外
                    unset($arrRecommends[$key]);
                }
            }

//        }

//var_dump($response);
        return $response;
    }
}

$objPage = new LC_Page_FrontParts_BLoc_Recommend2 ();
$objPage->blocItems = $params['items'];
$objPage->init();
$objPage->process();

加工の跡がわかるように、
不要なところは、コメントアウトで、残してあります。

 

-