Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 64c8d5b78022908cd80ec46c0a664fb9cdc9a479 @kurozumi committed Jan 5, 2017
Showing with 487 additions and 0 deletions.
  1. +2 −0 .gitignore
  2. +204 −0 OnlyOnce.php
  3. +102 −0 data/class/plg_OnlyOnce_SC_CartSession.php
  4. +53 −0 data/class/plg_OnlyOnce_SC_Product.php
  5. +76 −0 plugin_info.php
  6. +50 −0 plugin_update.php
@@ -0,0 +1,2 @@
+*.tar.gz
+*.DS_Store
@@ -0,0 +1,204 @@
+<?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.
+ *
+ *
+ */
+
+/**
+ * プラグインの基底クラス
+ *
+ * @package Plugin
+ * @author LOCKON CO.,LTD.
+ * @version $Id: $
+ */
+class OnlyOnce extends SC_Plugin_Base
+{
+ /**
+ * コンストラクタ
+ *
+ * @param array $arrSelfInfo 自身のプラグイン情報
+ * @return void
+ */
+ public function __construct(array $arrSelfInfo)
+ {
+ if ($arrSelfInfo["enable"] == 1) {
+ define("PLG_PRODUCT_TYPE_ONLY_ONCE", $arrSelfInfo["free_field1"]);
+ }
+
+ }
+
+ /**
+ * インストール
+ * installはプラグインのインストール時に実行されます.
+ * 引数にはdtb_pluginのプラグイン情報が渡されます.
+ *
+ * @param array $arrPlugin plugin_infoを元にDBに登録されたプラグイン情報(dtb_plugin)
+ * @return void
+ */
+ public function install($arrPlugin, $objPluginInstaller = null)
+ {
+
+ }
+
+ /**
+ * アンインストール
+ * uninstallはアンインストール時に実行されます.
+ * 引数にはdtb_pluginのプラグイン情報が渡されます.
+ *
+ * @param array $arrPlugin プラグイン情報の連想配列(dtb_plugin)
+ * @return void
+ */
+ public function uninstall($arrPlugin, $objPluginInstaller = null)
+ {
+
+ }
+
+ /**
+ * 稼働
+ * enableはプラグインを有効にした際に実行されます.
+ * 引数にはdtb_pluginのプラグイン情報が渡されます.
+ *
+ * @param array $arrPlugin プラグイン情報の連想配列(dtb_plugin)
+ * @return void
+ */
+ public function enable($arrPlugin, $objPluginInstaller = null)
+ {
+ $masterData = new SC_DB_MasterData_Ex();
+
+ $objQuery = & SC_Query_Ex::getSingletonInstance();
+
+ $objQuery->begin();
+
+ $product_type_id = self::getNextMasterDataId("mtb_product_type");
+
+ // 初回購入限定商品用の商品種別IDを登録
+ $objQuery->insert("mtb_product_type", array(
+ 'id' => $product_type_id,
+ 'name' => "初回購入限定商品",
+ 'rank' => self::getNextMasterDataRank("mtb_product_type")));
+
+ $masterData->clearCache("mtb_product_type");
+
+ // プラグイン情報に初回購入限定商品の商品種別IDを保持しておく
+ $objQuery->update("dtb_plugin", array("free_field1" => $product_type_id), "plugin_code = ?", array($arrPlugin["plugin_code"]));
+
+ $objQuery->commit();
+
+ }
+
+ /**
+ * 停止
+ * disableはプラグインを無効にした際に実行されます.
+ * 引数にはdtb_pluginのプラグイン情報が渡されます.
+ *
+ * @param array $arrPlugin プラグイン情報の連想配列(dtb_plugin)
+ * @return void
+ */
+ public function disable($arrPlugin, $objPluginInstaller = null)
+ {
+ $masterData = new SC_DB_MasterData_Ex();
+
+ $objQuery = & SC_Query_Ex::getSingletonInstance();
+
+ $objQuery->begin();
+
+ // 初回購入限定商品用の商品種別IDを削除
+ $objQuery->delete("mtb_product_type", "id=?", array($arrPlugin["free_field1"]));
+
+ $masterData->clearCache("mtb_product_type");
+
+ $objQuery->update("dtb_plugin", array("free_field1" => null), "plugin_code = ?", array($arrPlugin["plugin_code"]));
+
+ $objQuery->setGroupBy("product_id");
+ $products = $objQuery->select("product_id", "dtb_products_class", "product_type_id=?", array(PLG_PRODUCT_TYPE_ONLY_ONCE));
+
+ // 初回購入限定商品を非表示してproduct_type_idを通常商品へ変更する
+ foreach ($products as $product) {
+ $objQuery->update("dtb_products", array("status" => 2), "product_id=?", array($product["product_id"]));
+ }
+
+ $objQuery->update("dtb_products_class", array("product_type_id" => 1), "product_type_id=?", array(PLG_PRODUCT_TYPE_ONLY_ONCE));
+
+ $objQuery->commit();
+
+ }
+
+ /**
+ * プラグインヘルパーへ, コールバックメソッドを登録します.
+ *
+ * @param integer $priority
+ */
+ public function register(SC_Helper_Plugin $objHelperPlugin, $priority)
+ {
+ $objHelperPlugin->addAction("loadClassFileChange", array(&$this, "loadClassFileChange"), $priority);
+
+ }
+
+ /**
+ * SC_系のクラスをフックする
+ *
+ * @param type $classname
+ * @param type $classpath
+ */
+ public function loadClassFileChange(&$classname, &$classpath)
+ {
+ $base_path = PLUGIN_UPLOAD_REALDIR . basename(__DIR__) . "/data/class/";
+
+ if ($classname == "SC_CartSession_Ex") {
+ $classname = "plg_OnlyOnce_SC_CartSession";
+ $classpath = $base_path . $classname . ".php";
+ }
+ if ($classname == "SC_Product_Ex") {
+ $classname = "plg_OnlyOnce_SC_Product";
+ $classpath = $base_path . $classname . ".php";
+ }
+
+ }
+
+ /**
+ * 次に割り当てるMasterDataのIDを取得する
+ *
+ * @param type $name
+ * @return type
+ */
+ public static function getNextMasterDataId($name)
+ {
+ $objQuery = & SC_Query_Ex::getSingletonInstance();
+ return $objQuery->max("id", $name) + 1;
+
+ }
+
+ /**
+ * 次に割り当てるMasterDataのRANKを取得する
+ *
+ * @param type $name
+ * @return type
+ */
+ public static function getNextMasterDataRank($name)
+ {
+ $objQuery = & SC_Query_Ex::getSingletonInstance();
+ return $objQuery->max("rank", $name) + 1;
+
+ }
+
+}
@@ -0,0 +1,102 @@
+<?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 CLASS_REALDIR . 'SC_CartSession.php';
+
+class plg_OnlyOnce_SC_CartSession extends SC_CartSession
+{
+ /**
+ * カート内の商品の妥当性をチェックする.
+ *
+ * エラーが発生した場合は, 商品をカート内から削除又は数量を調整し,
+ * エラーメッセージを返す.
+ *
+ * 1. 商品種別に関連づけられた配送業者の存在チェック
+ * 2. 削除/非表示商品のチェック
+ * 3. 販売制限数のチェック
+ * 4. 在庫数チェック
+ *
+ * @param string $productTypeId 商品種別ID
+ * @return string エラーが発生した場合はエラーメッセージ
+ */
+ public function checkProducts($productTypeId)
+ {
+ $tpl_message = parent::checkProducts($productTypeId);
+
+ // カート内の情報を取得
+ $arrItems = $this->getCartList($productTypeId);
+ foreach ($arrItems as &$arrItem) {
+
+ if($this->isOnlyOnce($arrItem) === false)
+ continue;
+
+ $product = & $arrItem['productsClass'];
+
+ // 購入回数を取得
+ $count = $this->getBuyCount($product);
+
+ if ($count >= 1) {
+ $tpl_message .= sprintf("※ %sは初回購入限定商品です。過去に一度購入しています。\n", $product["name"]);
+ $this->delProduct($arrItem['cart_no'], $productTypeId);
+ }
+ }
+
+ return $tpl_message;
+
+ }
+
+ /**
+ * 初回購入限定商品かどうか
+ *
+ * @param type $arrItem
+ * @return type
+ */
+ public function isOnlyOnce($arrItem)
+ {
+ return $arrItem['productsClass']['only_once_flg'];
+
+ }
+
+ /**
+ * 購入回数を取得
+ *
+ * @param array $p
+ * @return int
+ */
+ public function getBuyCount($p)
+ {
+ $objCustomer = new SC_Customer_Ex();
+ $objQuery = SC_Query_Ex::getSingletonInstance();
+
+ $customer_id = $objCustomer->getValue('customer_id');
+
+ $where = "O.customer_id = ? AND OD.product_id = ?";
+ $arrWhereVal = array($customer_id, $p["product_id"]);
+
+ $objQuery->setGroupBy("O.order_id");
+ return (int) $objQuery->count("dtb_order_detail AS OD JOIN dtb_order as O", $where, $arrWhereVal);
+
+ }
+
+}
@@ -0,0 +1,53 @@
+<?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 CLASS_REALDIR . 'SC_Product.php';
+
+class plg_OnlyOnce_SC_Product extends SC_Product
+{
+ /**
+ * 商品規格IDから商品規格を取得する.
+ *
+ * 削除された商品規格は取得しない.
+ *
+ * @param integer $productClassId 商品規格ID
+ * @return array 商品規格の配列
+ */
+ public function getProductsClass($productClassId)
+ {
+ $arrProduct = parent::getProductsClass($productClassId);
+
+ // 初回購入限定商品の場合、フラグを追加する
+ if ($arrProduct['product_type_id'] == PLG_PRODUCT_TYPE_ONLY_ONCE) {
+ $arrProduct['product_type_id'] = PRODUCT_TYPE_NORMAL;
+ $arrProduct['only_once_flg'] = true;
+ } else {
+ $arrProduct['only_once_flg'] = false;
+ }
+
+ return $arrProduct;
+
+ }
+
+}
Oops, something went wrong.

0 comments on commit 64c8d5b

Please sign in to comment.