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系統&3系統のポイント共有(覚書)