PageRenderTime 54ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. * This file is part of EC-CUBE
  4. *
  5. * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
  6. *
  7. * http://www.lockon.co.jp/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. // {{{ requires
  24. require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
  25. /**
  26. * ????????? ???????.
  27. *
  28. * @package Page
  29. * @author LOCKON CO.,LTD.
  30. * @version $Id$
  31. */
  32. class LC_Page_Shopping_Multiple extends LC_Page_Ex {
  33. // }}}
  34. // {{{ functions
  35. /**
  36. * Page ??????.
  37. *
  38. * @return void
  39. */
  40. function init() {
  41. parent::init();
  42. $this->tpl_title = "?????????";
  43. $this->httpCacheControl('nocache');
  44. }
  45. /**
  46. * Page ?????.
  47. *
  48. * @return void
  49. */
  50. function process() {
  51. $this->action();
  52. $this->sendResponse();
  53. }
  54. /**
  55. * Page ?????.
  56. *
  57. * @return void
  58. */
  59. function action() {
  60. $objSiteSess = new SC_SiteSession_Ex();
  61. $objCartSess = new SC_CartSession_Ex();
  62. $objPurchase = new SC_Helper_Purchase_Ex();
  63. $objCustomer = new SC_Customer_Ex();
  64. $objFormParam = new SC_FormParam_Ex();
  65. $this->tpl_uniqid = $objSiteSess->getUniqId();
  66. $this->addrs = $this->getDelivAddrs($objCustomer, $objPurchase,
  67. $this->tpl_uniqid);
  68. $this->tpl_addrmax = count($this->addrs);
  69. $this->lfInitParam($objFormParam);
  70. $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
  71. switch ($this->getMode()) {
  72. case 'confirm':
  73. $objFormParam->setParam($_POST);
  74. $this->arrErr = $this->lfCheckError($objFormParam);
  75. if (SC_Utils_Ex::isBlank($this->arrErr)) {
  76. // ????????????????
  77. $_SESSION['multiple_temp'] = $objFormParam->getHashArray();
  78. $this->saveMultipleShippings($this->tpl_uniqid, $objFormParam,
  79. $objCustomer, $objPurchase,
  80. $objCartSess);
  81. $objSiteSess->setRegistFlag();
  82. SC_Response_Ex::sendRedirect("payment.php");
  83. exit;
  84. }
  85. break;
  86. default:
  87. $this->setParamToSplitItems($objFormParam, $objCartSess);
  88. }
  89. // ??????????????
  90. if ($_GET['from'] == 'multiple') {
  91. $objFormParam->setParam($_SESSION['multiple_temp']);
  92. }
  93. $this->arrForm = $objFormParam->getFormParamList();
  94. }
  95. /**
  96. * ??????.
  97. *
  98. * @return void
  99. */
  100. function destroy() {
  101. parent::destroy();
  102. }
  103. /**
  104. * ??????????.
  105. *
  106. * @param SC_FormParam $objFormParam SC_FormParam ??????
  107. * @return void
  108. */
  109. function lfInitParam(&$objFormParam) {
  110. $objFormParam->addParam("????ID", "product_class_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
  111. $objFormParam->addParam("???", "name");
  112. $objFormParam->addParam("??1", "class_name1");
  113. $objFormParam->addParam("??2", "class_name2");
  114. $objFormParam->addParam("????1", "classcategory_name1");
  115. $objFormParam->addParam("????2", "classcategory_name2");
  116. $objFormParam->addParam("?????", "main_image");
  117. $objFormParam->addParam("???????", "main_list_image");
  118. $objFormParam->addParam("????", "price");
  119. $objFormParam->addParam("??", 'quantity', INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), 1);
  120. $objFormParam->addParam("?????", 'shipping', INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"));
  121. $objFormParam->addParam("?????", "cart_no", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
  122. $objFormParam->addParam("??", "line_of_num", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
  123. }
  124. /**
  125. * ???????????????, ?????????.
  126. *
  127. * @param SC_FormParam $objFormParam SC_FormParam ??????
  128. * @param SC_CartSession $objCartSess SC_CartSession ??????
  129. * @return void
  130. */
  131. function setParamToSplitItems(&$objFormParam, &$objCartSess) {
  132. $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
  133. $arrItems = array();
  134. $index = 0;
  135. foreach (array_keys($cartLists) as $key) {
  136. $arrProductsClass = $cartLists[$key]['productsClass'];
  137. $quantity = (int) $cartLists[$key]['quantity'];
  138. for ($i = 0; $i < $quantity; $i++) {
  139. foreach ($arrProductsClass as $key2 => $val) {
  140. $arrItems[$key2][$index] = $val;
  141. }
  142. $arrItems['quantity'][$index] = 1;
  143. $arrItems['price'][$index] = $cartLists[$key]['price'];
  144. $index++;
  145. }
  146. }
  147. $objFormParam->setParam($arrItems);
  148. $objFormParam->setValue('line_of_num', $index);
  149. }
  150. /**
  151. * ????????????????????.
  152. *
  153. * ????????????, ???????????????????.
  154. * ???????, ???????????????????????.
  155. *
  156. * @param SC_Customer $objCustomer SC_Customer ??????
  157. * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase ??????
  158. * @param integer $uniqid ?????????????ID
  159. * @return array ???????????????
  160. */
  161. function getDelivAddrs(&$objCustomer, &$objPurchase, $uniqid) {
  162. $masterData = new SC_DB_MasterData();
  163. $arrPref = $masterData->getMasterData('mtb_pref');
  164. $arrResults = array('' => '????????');
  165. // ???????
  166. if ($objCustomer->isLoginSuccess(true)) {
  167. $arrAddrs = $objCustomer->getCustomerAddress($objCustomer->getValue('customer_id'));
  168. foreach ($arrAddrs as $val) {
  169. $other_deliv_id = SC_Utils_Ex::isBlank($val['other_deliv_id']) ? 0 : $val['other_deliv_id'];
  170. $arrResults[$other_deliv_id] = $val['name01'] . $val['name02']
  171. . " " . $arrPref[$val['pref']] . $val['addr01'] . $val['addr02'];
  172. }
  173. }
  174. // ???
  175. else {
  176. $arrShippings = $objPurchase->getShippingTemp();
  177. foreach ($arrShippings as $shipping_id => $val) {
  178. $arrResults[$shipping_id] = $val['shipping_name01'] . $val['shipping_name02']
  179. . " " . $arrPref[$val['shipping_pref']]
  180. . $val['shipping_addr01'] . $val['shipping_addr02'];
  181. }
  182. }
  183. return $arrResults;
  184. }
  185. /**
  186. * ?????????.
  187. *
  188. * @param SC_FormParam $objFormParam SC_FormParam ??????
  189. * @return array ????????
  190. */
  191. function lfCheckError(&$objFormParam) {
  192. $objCartSess = new SC_CartSession_Ex();
  193. $objFormParam->convParam();
  194. // ??????0???
  195. $objFormParam->setValue('quantity', $objFormParam->getValue('quantity', 0));
  196. $arrErr = $objFormParam->checkError();
  197. $arrParams = $objFormParam->getSwapArray();
  198. if (empty($arrErr)) {
  199. foreach ($arrParams as $index => $arrParam) {
  200. // ??0???????????????
  201. if ($arrParam['quantity'] == 0 && !SC_Utils_Ex::isBlank($arrParam['shipping'])) {
  202. $arrErr['shipping'][$index] = '? ???0?????????????????<br />';;
  203. }
  204. // ???????????????????????
  205. if ($arrParam['quantity'] > 0 && SC_Utils_Ex::isBlank($arrParam['shipping'])) {
  206. $arrErr['shipping'][$index] = '? ???????????????<br />';
  207. }
  208. }
  209. }
  210. // ??????????????????????????
  211. if (empty($arrErr)) {
  212. $arrQuantity = array();
  213. // ???????
  214. foreach ($arrParams as $arrParam) {
  215. $product_class_id = $arrParam['product_class_id'];
  216. $arrQuantity[$product_class_id] += $arrParam['quantity'];
  217. }
  218. // ???????????
  219. $cartLists =& $objCartSess->getCartList($objCartSess->getKey());
  220. foreach ($cartLists as $arrCartRow) {
  221. $product_class_id = $arrCartRow['id'];
  222. // ??????????????
  223. if ($arrCartRow['quantity'] != $arrQuantity[$product_class_id]) {
  224. foreach ($arrParams as $index => $arrParam) {
  225. if ($arrParam['product_class_id'] == $product_class_id) {
  226. $arrErr['quantity'][$index] = '? ??????' . $arrCartRow['quantity'] .'?????????<br />';
  227. }
  228. }
  229. }
  230. }
  231. }
  232. return $arrErr;
  233. }
  234. /**
  235. * ?????????????.
  236. *
  237. * ?????????????, ???????????????????.
  238. *
  239. * @param integer $uniqid ?????????????ID
  240. * @param SC_FormParam $objFormParam SC_FormParam ??????
  241. * @param SC_Customer $objCustomer SC_Customer ??????
  242. * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase ??????
  243. * @param SC_CartSession $objCartSess SC_CartSession ??????
  244. * @return void
  245. */
  246. function saveMultipleShippings($uniqid, &$objFormParam, &$objCustomer,
  247. &$objPurchase, &$objCartSess) {
  248. $objQuery =& SC_Query_Ex::getSingletonInstance();
  249. $arrParams = $objFormParam->getSwapArray();
  250. foreach ($arrParams as $arrParam) {
  251. $other_deliv_id = $arrParam['shipping'];
  252. if ($objCustomer->isLoginSuccess(true)) {
  253. if ($other_deliv_id != 0) {
  254. $otherDeliv = $objQuery->select("*", "dtb_other_deliv",
  255. "other_deliv_id = ?",
  256. array($other_deliv_id));
  257. foreach ($otherDeliv[0] as $key => $val) {
  258. $arrValues[$other_deliv_id]['shipping_' . $key] = $val;
  259. }
  260. } else {
  261. $objPurchase->copyFromCustomer($arrValues[0], $objCustomer,
  262. 'shipping');
  263. }
  264. } else {
  265. $arrValues = $objPurchase->getShippingTemp();
  266. }
  267. $arrItemTemp[$other_deliv_id][$arrParam['product_class_id']] += $arrParam['quantity'];
  268. }
  269. $objPurchase->clearShipmentItemTemp();
  270. foreach ($arrValues as $shipping_id => $arrVal) {
  271. $objPurchase->saveShippingTemp($arrVal, $shipping_id);
  272. }
  273. foreach ($arrItemTemp as $other_deliv_id => $arrProductClassIds) {
  274. foreach ($arrProductClassIds as $product_class_id => $quantity) {
  275. if ($quantity == 0) continue;
  276. $objPurchase->setShipmentItemTemp($other_deliv_id,
  277. $product_class_id,
  278. $quantity);
  279. }
  280. }
  281. // $arrValues[0] ??, ??????????????
  282. $objPurchase->saveOrderTemp($uniqid, $arrValues[0], $objCustomer);
  283. }
  284. }
  285. ?>