Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Created December 12, 2016 06:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kurozumi/2708319923e1277f19ee21730442a17d to your computer and use it in GitHub Desktop.
Save kurozumi/2708319923e1277f19ee21730442a17d to your computer and use it in GitHub Desktop.
【EC-CUBE2.13】新しく追加した商品種別の商品を通常商品と同じカートに追加する方法
<?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
{
/**
* マスターデータ管理でサンプル商品の商品種別を追加してそのIDが3の場合
*/
const PRODUCT_TYPE_SAMPLE = 3;
// カートへの商品追加
public function addProduct($product_class_id, $quantity)
{
$objProduct = new SC_Product_Ex();
$arrProduct = $objProduct->getProductsClass($product_class_id);
$productTypeId = $arrProduct['product_type_id'];
// サンプル商品が追加された時、通常商品と同じカートに入れる
if($arrProduct['product_type_id'] == self::PRODUCT_TYPE_SAMPLE) {
$productTypeId = PRODUCT_TYPE_NORMAL;
}
$find = false;
$max = $this->getMax($productTypeId);
for ($i = 0; $i <= $max; $i++) {
if ($this->cartSession[$productTypeId][$i]['id'] == $product_class_id) {
$val = $this->cartSession[$productTypeId][$i]['quantity'] + $quantity;
if (strlen($val) <= INT_LEN) {
$this->cartSession[$productTypeId][$i]['quantity'] += $quantity;
}
$find = true;
}
}
if (!$find) {
$this->cartSession[$productTypeId][$max+1]['id'] = $product_class_id;
$this->cartSession[$productTypeId][$max+1]['quantity'] = $quantity;
$this->cartSession[$productTypeId][$max+1]['cart_no'] = $this->getNextCartID($productTypeId);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment