Last active
December 6, 2016 06:48
-
-
Save kurozumi/4c81c2183354daf2540fde4dadcb2c36 to your computer and use it in GitHub Desktop.
【EC-CUBE2.13】購入回数のチェック
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 SC_CartSession_Ex extends SC_CartSession | |
{ | |
/** | |
* カート内の商品の妥当性をチェックする. | |
* | |
* エラーが発生した場合は, 商品をカート内から削除又は数量を調整し, | |
* エラーメッセージを返す. | |
* | |
* 1. 商品種別に関連づけられた配送業者の存在チェック | |
* 2. 削除/非表示商品のチェック | |
* 3. 販売制限数のチェック | |
* 4. 在庫数チェック | |
* | |
* @param string $productTypeId 商品種別ID | |
* @return string エラーが発生した場合はエラーメッセージ | |
*/ | |
public function checkProducts($productTypeId) | |
{ | |
$objProduct = new SC_Product_Ex(); | |
$objCustomer = new SC_Customer_Ex(); | |
$objDelivery = new SC_Helper_Delivery_Ex(); | |
$arrDeliv = $objDelivery->getList($productTypeId); | |
$tpl_message = ''; | |
// カート内の情報を取得 | |
$arrItems = $this->getCartList($productTypeId); | |
foreach ($arrItems as &$arrItem) { | |
$product =& $arrItem['productsClass']; | |
/* | |
* 表示/非表示商品のチェック | |
*/ | |
if (SC_Utils_Ex::isBlank($product) || $product['status'] != 1) { | |
$this->delProduct($arrItem['cart_no'], $productTypeId); | |
$tpl_message .= "※ 現時点で販売していない商品が含まれておりました。該当商品をカートから削除しました。\n"; | |
} else { | |
/** | |
* 購入回数のチェックを追加 | |
*/ | |
$count = $objCustomer->getBuyCount($product); | |
// ココに数値を設定。以下の場合、10回まで購入可能。 | |
if($count > 10) { | |
$tpl_message .= '※ 購入回数の上限を超えましたので購入できません。' . "\n"; | |
$this->delProduct($arrItem['cart_no'], $productTypeId); | |
continue; | |
} | |
/* | |
* 配送業者のチェック | |
*/ | |
if (SC_Utils_Ex::isBlank($arrDeliv)) { | |
$tpl_message .= '※「' . $product['name'] . '」はまだ配送の準備ができておりません。'; | |
$tpl_message .= '恐れ入りますがお問い合わせページよりお問い合わせください。' . "\n"; | |
$this->delProduct($arrItem['cart_no'], $productTypeId); | |
} | |
/* | |
* 販売制限数, 在庫数のチェック | |
*/ | |
$limit = $objProduct->getBuyLimit($product); | |
if (!is_null($limit) && $arrItem['quantity'] > $limit) { | |
if ($limit > 0) { | |
$this->setProductValue($arrItem['id'], 'quantity', $limit, $productTypeId); | |
$total_inctax = $limit * SC_Helper_TaxRule_Ex::sfCalcIncTax($arrItem['price'], | |
$product['product_id'], | |
$arrItem['id'][0]); | |
$this->setProductValue($arrItem['id'], 'total_inctax', $total_inctax, $productTypeId); | |
$tpl_message .= '※「' . $product['name'] . '」は販売制限(または在庫が不足)しております。'; | |
$tpl_message .= "一度に数量{$limit}を超える購入はできません。\n"; | |
} else { | |
$this->delProduct($arrItem['cart_no'], $productTypeId); | |
$tpl_message .= '※「' . $product['name'] . "」は売り切れました。\n"; | |
continue; | |
} | |
} | |
} | |
} | |
return $tpl_message; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment