/PhpOnAzure.Web/data/class/pages/shopping/LC_Page_Shopping_Multiple.php
http://eccubeonwaz.codeplex.com · PHP · 317 lines · 180 code · 32 blank · 105 comment · 25 complexity · 360377f9dc5480e65f250731bbbd2e21 MD5 · raw file
- <?php
- /*
- * This file is part of EC-CUBE
- *
- * Copyright(c) 2000-2011 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.
- */
- // {{{ requires
- require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
- /**
- * ????????? ???????.
- *
- * @package Page
- * @author LOCKON CO.,LTD.
- * @version $Id$
- */
- class LC_Page_Shopping_Multiple extends LC_Page_Ex {
- // }}}
- // {{{ functions
- /**
- * Page ??????.
- *
- * @return void
- */
- function init() {
- parent::init();
- $this->tpl_title = "?????????";
- $this->httpCacheControl('nocache');
- }
- /**
- * Page ?????.
- *
- * @return void
- */
- function process() {
- $this->action();
- $this->sendResponse();
- }
- /**
- * Page ?????.
- *
- * @return void
- */
- function action() {
- $objSiteSess = new SC_SiteSession_Ex();
- $objCartSess = new SC_CartSession_Ex();
- $objPurchase = new SC_Helper_Purchase_Ex();
- $objCustomer = new SC_Customer_Ex();
- $objFormParam = new SC_FormParam_Ex();
- $this->tpl_uniqid = $objSiteSess->getUniqId();
- $this->addrs = $this->getDelivAddrs($objCustomer, $objPurchase,
- $this->tpl_uniqid);
- $this->tpl_addrmax = count($this->addrs);
- $this->lfInitParam($objFormParam);
- $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
- switch ($this->getMode()) {
- case 'confirm':
- $objFormParam->setParam($_POST);
- $this->arrErr = $this->lfCheckError($objFormParam);
- if (SC_Utils_Ex::isBlank($this->arrErr)) {
- // ????????????????
- $_SESSION['multiple_temp'] = $objFormParam->getHashArray();
- $this->saveMultipleShippings($this->tpl_uniqid, $objFormParam,
- $objCustomer, $objPurchase,
- $objCartSess);
- $objSiteSess->setRegistFlag();
- SC_Response_Ex::sendRedirect("payment.php");
- exit;
- }
- break;
- default:
- $this->setParamToSplitItems($objFormParam, $objCartSess);
- }
- // ??????????????
- if ($_GET['from'] == 'multiple') {
- $objFormParam->setParam($_SESSION['multiple_temp']);
- }
- $this->arrForm = $objFormParam->getFormParamList();
- }
- /**
- * ??????.
- *
- * @return void
- */
- function destroy() {
- parent::destroy();
- }
- /**
- * ??????????.
- *
- * @param SC_FormParam $objFormParam SC_FormParam ??????
- * @return void
- */
- function lfInitParam(&$objFormParam) {
- $objFormParam->addParam("????ID", "product_class_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
- $objFormParam->addParam("???", "name");
- $objFormParam->addParam("??1", "class_name1");
- $objFormParam->addParam("??2", "class_name2");
- $objFormParam->addParam("????1", "classcategory_name1");
- $objFormParam->addParam("????2", "classcategory_name2");
- $objFormParam->addParam("?????", "main_image");
- $objFormParam->addParam("???????", "main_list_image");
- $objFormParam->addParam("????", "price");
- $objFormParam->addParam("??", 'quantity', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
- $objFormParam->addParam("?????", 'shipping', INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"));
- $objFormParam->addParam("?????", "cart_no", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
- $objFormParam->addParam("??", "line_of_num", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
- }
- /**
- * ???????????????, ?????????.
- *
- * @param SC_FormParam $objFormParam SC_FormParam ??????
- * @param SC_CartSession $objCartSess SC_CartSession ??????
- * @return void
- */
- function setParamToSplitItems(&$objFormParam, &$objCartSess) {
- $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
- $arrItems = array();
- $index = 0;
- foreach (array_keys($cartLists) as $key) {
- $arrProductsClass = $cartLists[$key]['productsClass'];
- $quantity = (int) $cartLists[$key]['quantity'];
- for ($i = 0; $i < $quantity; $i++) {
- foreach ($arrProductsClass as $key2 => $val) {
- $arrItems[$key2][$index] = $val;
- }
- $arrItems['quantity'][$index] = 1;
- $arrItems['price'][$index] = $cartLists[$key]['price'];
- $index++;
- }
- }
- $objFormParam->setParam($arrItems);
- $objFormParam->setValue('line_of_num', $index);
- }
- /**
- * ????????????????????.
- *
- * ????????????, ???????????????????.
- * ???????, ???????????????????????.
- *
- * @param SC_Customer $objCustomer SC_Customer ??????
- * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase ??????
- * @param integer $uniqid ?????????????ID
- * @return array ???????????????
- */
- function getDelivAddrs(&$objCustomer, &$objPurchase, $uniqid) {
- $masterData = new SC_DB_MasterData();
- $arrPref = $masterData->getMasterData('mtb_pref');
- $arrResults = array('' => '????????');
- // ???????
- if ($objCustomer->isLoginSuccess(true)) {
- $arrAddrs = $objCustomer->getCustomerAddress($objCustomer->getValue('customer_id'));
- foreach ($arrAddrs as $val) {
- $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id'];
- $arrResults[$other_deliv_id] = $val['name01'] . $val['name02']
- . " " . $arrPref[$val['pref']] . $val['addr01'] . $val['addr02'];
- }
- }
- // ???
- else {
- $arrShippings = $objPurchase->getShippingTemp();
- foreach ($arrShippings as $shipping_id => $val) {
- $arrResults[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02']
- . " " . $arrPref[$val['shipping_pref']]
- . $val['shipping_addr01'] . $val['shipping_addr02'];
- }
- }
- return $arrResults;
- }
- /**
- * ?????????.
- *
- * @param SC_FormParam $objFormParam SC_FormParam ??????
- * @return array ????????
- */
- function lfCheckError(&$objFormParam) {
- $objCartSess = new SC_CartSession_Ex();
- $objFormParam->convParam();
- // ??????0???
- $objFormParam->setValue('quantity', $objFormParam->getValue('quantity', 0));
- $arrErr = $objFormParam->checkError();
- $arrParams = $objFormParam->getSwapArray();
- if (empty($arrErr)) {
- foreach ($arrParams as $index => $arrParam) {
- // ??0???????????????
- if ($arrParam['quantity'] == 0 && !SC_Utils_Ex::isBlank($arrParam['shipping'])) {
- $arrErr['shipping'][$index] = '? ???0?????????????????<br />';;
- }
- // ???????????????????????
- if ($arrParam['quantity'] > 0 && SC_Utils_Ex::isBlank($arrParam['shipping'])) {
- $arrErr['shipping'][$index] = '? ???????????????<br />';
- }
- }
- }
- // ??????????????????????????
- if (empty($arrErr)) {
- $arrQuantity = array();
- // ???????
- foreach ($arrParams as $arrParam) {
- $product_class_id = $arrParam['product_class_id'];
- $arrQuantity[$product_class_id] += $arrParam['quantity'];
- }
- // ???????????
- $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
- foreach ($cartLists as $arrCartRow) {
- $product_class_id = $arrCartRow['id'];
- // ??????????????
- if ($arrCartRow['quantity'] != $arrQuantity[$product_class_id]) {
- foreach ($arrParams as $index => $arrParam) {
- if ($arrParam['product_class_id'] == $product_class_id) {
- $arrErr['quantity'][$index] = '? ??????' . $arrCartRow['quantity'] .'?????????<br />';
- }
- }
- }
- }
- }
- return $arrErr;
- }
- /**
- * ?????????????.
- *
- * ?????????????, ???????????????????.
- *
- * @param integer $uniqid ?????????????ID
- * @param SC_FormParam $objFormParam SC_FormParam ??????
- * @param SC_Customer $objCustomer SC_Customer ??????
- * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase ??????
- * @param SC_CartSession $objCartSess SC_CartSession ??????
- * @return void
- */
- function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer,
- &$objPurchase, &$objCartSess) {
- $objQuery =& SC_Query_Ex::getSingletonInstance();
- $arrParams = $objFormParam->getSwapArray();
- foreach ($arrParams as $arrParam) {
- $other_deliv_id = $arrParam['shipping'];
- if ($objCustomer->isLoginSuccess(true)) {
- if ($other_deliv_id != 0) {
- $otherDeliv = $objQuery->select("*", "dtb_other_deliv",
- "other_deliv_id = ?",
- array($other_deliv_id));
- foreach ($otherDeliv[0] as $key => $val) {
- $arrValues[$other_deliv_id]['shipping_' . $key] = $val;
- }
- } else {
- $objPurchase->copyFromCustomer($arrValues[0], $objCustomer,
- 'shipping');
- }
- } else {
- $arrValues = $objPurchase->getShippingTemp();
- }
- $arrItemTemp[$other_deliv_id][$arrParam['product_class_id']] += $arrParam['quantity'];
- }
- $objPurchase->clearShipmentItemTemp();
- foreach ($arrValues as $shipping_id => $arrVal) {
- $objPurchase->saveShippingTemp($arrVal, $shipping_id);
- }
- foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds) {
- foreach ($arrProductClassIds as $product_class_id => $quantity) {
- if ($quantity == 0) continue;
- $objPurchase->setShipmentItemTemp($other_deliv_id,
- $product_class_id,
- $quantity);
- }
- }
- // $arrValues[0] ??, ??????????????
- $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer);
- }
- }
- ?>