<?php
/*--------------------------------------------------------- 
 * File:tradeEntry.php
 * Author:Tomix
 * Description: 產品交易邏輯核心類
 * Created:2009
 * -------------------------------------------------------
 * Modified history:2023/08/23
 * Copyright © 2023 蘋果世界股份有限公司 版權所有
 * -------------------------------------------------------
 */
require_once dirname(__FILE__)."/bllBase.php";
class tradeEntry {
	/* 更新購物車
	 * @param		string		$updateMode		0，直接不進行遞增操作；1，購物車數量遞增
	 */
	static public function updateCart($sessionID, $productID, $sizeID, $quantity, $updateMode = 0) {
		require_once dirname(__FILE__) . "/../dal/cartDAL.php";
		$cart = new cartDAL();
		$cart->SessionID = $sessionID;
		$cart->ProductID = $productID;
		$cart->SizeID = $sizeID;

		if ($cart->checkExists($sessionID, $productID, $sizeID)) {
			$cart->loadRecord();
			if ($updateMode === 1) {
				$cart->Quantity += $quantity;
			} else {
				$cart->Quantity = $quantity;
				if ($quantity === 0) return $cart->deleteRecord($sessionID, $productID, $sizeID);
			}
			return $cart->updateRecord();
		} else {
			$cart->Quantity = $quantity;
			return $cart->insertRecord();
		}
	}
}
?>