index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. use fec\helpers\CRequest;
  10. ?>
  11. <div class="main container one-column">
  12. <div class="col-main">
  13. <?= Yii::$service->page->widget->render('flashmessage'); ?>
  14. <form action="<?= Yii::$service->url->getUrl('checkout/onepage'); ?>" method="post" id="onestepcheckout-form">
  15. <?= CRequest::getCsrfInputHtml(); ?>
  16. <div style="margin: 0;" class="group-select">
  17. <p class="onestepcheckout-description"><?= Yii::$service->page->translate->__('Welcome to the checkout,Fill in the fields below to complete your purchase');?> !</p>
  18. <?php if (\Yii::$app->user->isGuest): ?>
  19. <p class="onestepcheckout-login-link">
  20. <a external href="<?= Yii::$service->url->getUrl('customer/account/login'); ?>" id="onestepcheckout-login-link"><?= Yii::$service->page->translate->__('Already registered? Click here to login');?>.</a>
  21. </p>
  22. <?php endif; ?>
  23. <div class="onestepcheckout-threecolumns checkoutcontainer onestepcheckout-skin-generic onestepcheckout-enterprise">
  24. <div class="onestepcheckout-column-left">
  25. <?php # address 部门
  26. //echo $address_view_file;
  27. $addressView = [
  28. 'view' => $address_view_file,
  29. ];
  30. //var_dump($address_list);
  31. $addressParam = [
  32. 'cart_address_id' => $cart_address_id,
  33. 'address_list' => $address_list,
  34. 'customer_info' => $customer_info,
  35. 'country_select' => $country_select,
  36. 'state_html' => $state_html,
  37. 'cart_address' => $cart_address,
  38. //'payments' => $payments,
  39. //'current_payment_mothod' => $current_payment_mothod,
  40. ];
  41. ?>
  42. <?= Yii::$service->page->widget->render($addressView,$addressParam); ?>
  43. </div>
  44. <div class="onestepcheckout-column-middle">
  45. <div class="shipping_method_html">
  46. <?php # shipping部分
  47. $shippingView = [
  48. 'view' => 'checkout/onepage/index/shipping.php'
  49. ];
  50. $shippingParam = [
  51. 'shippings' => $shippings,
  52. ];
  53. ?>
  54. <?= Yii::$service->page->widget->render($shippingView,$shippingParam); ?>
  55. </div>
  56. <?php # payment部分
  57. $paymentView = [
  58. 'view' => 'checkout/onepage/index/payment.php'
  59. ];
  60. $paymentParam = [
  61. 'payments' => $payments,
  62. 'current_payment_mothod' => $current_payment_mothod,
  63. ];
  64. ?>
  65. <?= Yii::$service->page->widget->render($paymentView,$paymentParam); ?>
  66. <div class="onestepcheckout-coupons">
  67. <div style="display: none;" id="coupon-notice"></div>
  68. <div class="op_block_title"><?= Yii::$service->page->translate->__('Coupon codes (optional)');?></div>
  69. <label for="id_couponcode"><?= Yii::$service->page->translate->__('Enter your coupon code if you have one.');?></label>
  70. <input type="hidden" class="couponType" value="<?= $cart_info['coupon_code'] ? 1 : 2 ; ?>" />
  71. <input style="color:#777;" class="input-text" id="id_couponcode" name="coupon_code" value="<?= $cart_info['coupon_code']; ?>">
  72. <br>
  73. <button style="" type="button" class="submitbutton add_coupon_submit" id="onestepcheckout-coupon-add"><?= Yii::$service->page->translate->__($cart_info['coupon_code'] ? 'Cancel Coupon' : 'Add Coupon') ; ?></button>
  74. <div class="clear"></div>
  75. <div class="coupon_add_log"></div>
  76. </div>
  77. <div class="onestepcheckout-coupons">
  78. <div class="op_block_title"><?= Yii::$service->page->translate->__('Order Remark (optional)');?></div>
  79. <label for="id_couponcode"><?= Yii::$service->page->translate->__('You can fill in the order remark information below');?></label>
  80. <textarea class="order_remark" name="order_remark" style="width:100%;height:100px;padding:10px;"></textarea>
  81. </div>
  82. </div>
  83. <div class="onestepcheckout-column-right">
  84. <div class="review_order_view">
  85. <?php # review order部分
  86. $reviewOrderView = [
  87. 'view' => 'checkout/onepage/index/review_order.php'
  88. ];
  89. $reviewOrderParam = [
  90. 'cart_info' => $cart_info,
  91. 'currency_info' => $currency_info,
  92. ];
  93. ?>
  94. <?= Yii::$service->page->widget->render($reviewOrderView,$reviewOrderParam); ?>
  95. </div>
  96. <div class="onestepcheckout-place-order">
  97. <a class="large orange onestepcheckout-button" href="javascript:void(0)" id="onestepcheckout-place-order"><?= Yii::$service->page->translate->__('Place order now');?></a>
  98. <div class="onestepcheckout-place-order-loading"><img src="<?= Yii::$service->image->getImgUrl('images/opc-ajax-loader.gif'); ?>">&nbsp;&nbsp;<?= Yii::$service->page->translate->__('Please wait, processing your order...');?></div>
  99. </div>
  100. </div>
  101. <div style="clear: both;">&nbsp;</div>
  102. </div>
  103. </div>
  104. </form>
  105. </div>
  106. </div>
  107. <script>
  108. <?php $this->beginBlock('placeOrder') ?>
  109. csrfName = $(".thiscsrf").attr("name");
  110. csrfVal = $(".thiscsrf").val();
  111. function validateEmail(email) {
  112. var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
  113. return re.test(email);
  114. }
  115. // ajax
  116. function ajaxreflush(){
  117. shipping_method = $("input[name=shipping_method]:checked").val();
  118. //alert(shipping_method);
  119. country = $(".billing_country").val();
  120. address_id = $(".address_list").val();
  121. state = $(".address_state").val();
  122. //alert(state);
  123. if(country || address_id){
  124. $(".onestepcheckout-summary").html('<div style="text-align:center;min-height:40px;"><img src="<?= Yii::$service->image->getImgUrl('images/ajax-loader.gif'); ?>" /></div>');
  125. $(".onestepcheckout-shipping-method-block").html('<div style="text-align:center;min-height:40px;"><img src="<?= Yii::$service->image->getImgUrl('images/ajax-loader.gif'); ?>" /></div>');
  126. ajaxurl = "<?= Yii::$service->url->getUrl('checkout/onepage/ajaxupdateorder'); ?>";
  127. $.ajax({
  128. async:false,
  129. timeout: 8000,
  130. dataType: 'json',
  131. type:'get',
  132. data: {
  133. 'country':country,
  134. 'shipping_method':shipping_method,
  135. 'address_id':address_id,
  136. 'state':state,
  137. },
  138. url:ajaxurl,
  139. success:function(data, textStatus){
  140. status = data.status;
  141. if(status == 'success'){
  142. $(".review_order_view").html(data.reviewOrderHtml)
  143. $(".shipping_method_html").html(data.shippingHtml);
  144. }
  145. },
  146. error:function (XMLHttpRequest, textStatus, errorThrown){
  147. }
  148. });
  149. }
  150. }
  151. $(document).ready(function(){
  152. currentUrl = "<?= Yii::$service->url->getUrl('checkout/onepage') ?>"
  153. //优惠券
  154. $(".add_coupon_submit").click(function(){
  155. coupon_code = $("#id_couponcode").val();
  156. coupon_type = $(".couponType").val();
  157. coupon_url = "";
  158. $succ_coupon_type = 0;
  159. if(coupon_type == 2){
  160. coupon_url = "<?= Yii::$service->url->getUrl('checkout/cart/addcoupon'); ?>";
  161. $succ_coupon_type = 1;
  162. }else if(coupon_type == 1){
  163. coupon_url = "<?= Yii::$service->url->getUrl('checkout/cart/cancelcoupon'); ?>";
  164. $succ_coupon_type = 2;
  165. }
  166. //alert(coupon_type);
  167. if(!coupon_code){
  168. //alert("coupon can not empty!");
  169. }
  170. $data = {"coupon_code":coupon_code};
  171. $data[csrfName] = csrfVal;
  172. $.ajax({
  173. async:true,
  174. timeout: 6000,
  175. dataType: 'json',
  176. type:'post',
  177. data: $data,
  178. url:coupon_url,
  179. success:function(data, textStatus){
  180. if(data.status == 'success'){
  181. $(".couponType").val($succ_coupon_type);
  182. hml = $('.add_coupon_submit').html();
  183. if(hml == '<?= Yii::$service->page->translate->__('Add Coupon');?>'){
  184. $('.add_coupon_submit').html('<?= Yii::$service->page->translate->__('Cancel Coupon');?>');
  185. }else{
  186. $('.add_coupon_submit').html('<?= Yii::$service->page->translate->__('Add Coupon');?>');
  187. }
  188. $(".coupon_add_log").html("");
  189. ajaxreflush();
  190. }else if(data.content == 'nologin'){
  191. $(".coupon_add_log").html("<?= Yii::$service->page->translate->__('you must login your account before you use coupon');?>");
  192. }else{
  193. $(".coupon_add_log").html(data.content);
  194. }
  195. },
  196. error:function (XMLHttpRequest, textStatus, errorThrown){}
  197. });
  198. });
  199. // 对于非登录用户,可以填写密码,进行注册账户,这里进行信息的检查。
  200. $("#id_create_account").click(function(){
  201. if($(this).is(':checked')){
  202. email = $("input[name='billing[email]']").val();
  203. if(!email){
  204. $(this).prop('checked', false);
  205. $(".label_create_account").html(" <?= Yii::$service->page->translate->__('email address is empty, you must Fill in email');?>");
  206. }else{
  207. thischeckbox = this;
  208. if(!validateEmail(email)){
  209. $(this).prop('checked', false);
  210. $(".label_create_account").html(" <?= Yii::$service->page->translate->__('email address format is incorrect');?>");
  211. }else{
  212. // ajax get if email is register
  213. $.ajax({
  214. async:true,
  215. timeout: 6000,
  216. dataType: 'json',
  217. type:'get',
  218. data: {"email":email},
  219. url:"<?= Yii::$service->url->getUrl('customer/ajax/isregister'); ?>",
  220. success:function(data, textStatus){
  221. if(data.registered == 2){
  222. $(".label_create_account").html("");
  223. $("#onestepcheckout-li-password").show();
  224. $("#onestepcheckout-li-password input").addClass("required-entry");
  225. }else{
  226. $(thischeckbox).prop('checked', false);
  227. $(".label_create_account").html(" <?= Yii::$service->page->translate->__('This email is registered , you must fill in another email');?>");
  228. }
  229. },
  230. error:function (XMLHttpRequest, textStatus, errorThrown){}
  231. });
  232. }
  233. }
  234. }else{
  235. $(".label_create_account").html("");
  236. $("#onestepcheckout-li-password").hide();
  237. $("#onestepcheckout-li-password input").removeClass("required-entry");
  238. }
  239. });
  240. //###########################
  241. //下单(这个部分未完成。)
  242. $("#onestepcheckout-place-order").click(function(){
  243. $(".validation-advice").remove();
  244. i = 0;
  245. j = 0;
  246. address_list = $(".address_list").val();
  247. // shipping
  248. shipment_method = $(".onestepcheckout-shipping-method-block input[name='shipping_method']:checked").val();
  249. //alert(shipment_method);
  250. if(!shipment_method){
  251. $(".shipment-methods").after('<div style="" class="validation-advice"><?= Yii::$service->page->translate->__('This is a required field.');?></div>');
  252. j = 1;
  253. }
  254. //alert(j);
  255. //payment
  256. payment_method = $("#checkout-payment-method-load input[name='payment_method']:checked").val();
  257. //alert(shipment_method);
  258. if(!payment_method){
  259. $(".checkout-payment-method-load").after('<div style="" class="validation-advice"><?= Yii::$service->page->translate->__('This is a required field.');?></div>');
  260. j = 1;
  261. }
  262. if(address_list){
  263. if(!j){
  264. $(".onestepcheckout-place-order").addClass('visit');
  265. $("#onestepcheckout-form").submit();
  266. }
  267. }else{
  268. //alert(11);
  269. //alert(j);
  270. $("#onestepcheckout-form .required-entry").each(function(){
  271. value = $(this).val();
  272. if(!value){
  273. //alert(this);
  274. //alert($(this).attr('name'));
  275. i++;
  276. $(this).after('<div style="" class="validation-advice"><?= Yii::$service->page->translate->__('This is a required field.');?></div>');
  277. }
  278. });
  279. //email format validate
  280. user_email = $("#billing_address .validate-email").val();
  281. if(user_email && !validateEmail(user_email)){
  282. $("#billing_address .validate-email").after('<div style="" class="validation-advice"><?= Yii::$service->page->translate->__('email address format is incorrect');?></div>');
  283. i++;
  284. }
  285. // password 是否长度大于6,并且两个密码一致
  286. if($("#id_create_account").is(':checked')){
  287. new_user_pass = $(".customer_password").val();
  288. new_user_pass_cm = $(".customer_confirm_password").val();
  289. //alert(new_user_pass);
  290. //alert(new_user_pass.length);
  291. //alert(new_user_pass_cm);
  292. <?php
  293. $passwdMinLength = Yii::$service->customer->getRegisterPassMinLength();
  294. $passwdMaxLength = Yii::$service->customer->getRegisterPassMaxLength();
  295. ?>
  296. passwdMinLength = "<?= $passwdMinLength ?>";
  297. passwdMaxLength = "<?= $passwdMaxLength ?>";
  298. if(new_user_pass.length < passwdMinLength){
  299. $(".customer_password").after('<div style="" class="validation-advice"><?= Yii::$service->page->translate->__('Password length must be greater than or equal to {passwdMinLength}',['passwdMinLength' => $passwdMinLength]);?></div>');
  300. i++;
  301. }else if(new_user_pass.length > passwdMaxLength){
  302. $(".customer_password").after('<div style="" class="validation-advice"><?= Yii::$service->page->translate->__('Password length must be less than or equal to {passwdMaxLength}',['passwdMaxLength' => $passwdMaxLength]);?></div>');
  303. i++;
  304. }else if(new_user_pass != new_user_pass_cm){
  305. $(".customer_confirm_password").after('<div style="" class="validation-advice"><?= Yii::$service->page->translate->__('The passwords are inconsistent');?></div>');
  306. i++;
  307. }
  308. }
  309. //alert(222);
  310. if(!i && !j){
  311. //alert(333);
  312. $(".onestepcheckout-place-order").addClass('visit');
  313. $("#onestepcheckout-form").submit();
  314. }
  315. }
  316. });
  317. //登录用户切换地址列表
  318. $(".address_list").change(function(){
  319. val = $(this).val();
  320. if(!val){
  321. $(".billing_address_list_new").show();
  322. $(".save_in_address_book").attr("checked","checked");
  323. ajaxreflush();
  324. }else{
  325. $(".billing_address_list_new").hide();
  326. $(".save_in_address_book").attr("checked",false);
  327. addressid = $(this).val();
  328. if(addressid){
  329. ajaxreflush();
  330. }
  331. }
  332. });
  333. // 国家选择后,state需要清空,重新选择或者填写
  334. $(".billing_country").change(function(){
  335. country = $(this).val();
  336. //state = $(".address_state").val();
  337. //shipping_method = $("input[name=shipping_method]:checked").val();
  338. //alert(shipping_method);
  339. //$(".onestepcheckout-shipping-method-block").html('<div style="text-align:center;min-height:40px;"><img src="http://www.intosmile.com/skin/default/images/ajax-loader.gif" /></div>');
  340. //$(".onestepcheckout-summary").html('<div style="text-align:center;min-height:40px;"><img src="http://www.intosmile.com/skin/default/images/ajax-loader.gif" /></div>');
  341. ajaxurl = "<?= Yii::$service->url->getUrl('checkout/onepage/changecountry'); ?>";
  342. $.ajax({
  343. async:true,
  344. timeout: 8000,
  345. dataType: 'json',
  346. type:'get',
  347. data: {
  348. 'country':country,
  349. //'shipping_method':shipping_method,
  350. //'state':state
  351. },
  352. url:ajaxurl,
  353. success:function(data, textStatus){
  354. $(".state_html").html(data.state);
  355. },
  356. error:function (XMLHttpRequest, textStatus, errorThrown){
  357. }
  358. });
  359. ajaxreflush();
  360. });
  361. // state select 改变后的事件
  362. $(".input-state").off("change").on("change","select.address_state",function(){
  363. ajaxreflush();
  364. });
  365. // state input 改变后的事件
  366. $(".input-state").off("blur").on("blur","input.address_state",function(){
  367. ajaxreflush();
  368. });
  369. //改变shipping methos
  370. $(".onestepcheckout-column-middle").off("click").on("click","input[name=shipping_method]",function(){
  371. ajaxreflush();
  372. });
  373. });
  374. //ajaxreflush();
  375. <?php $this->endBlock(); ?>
  376. <?php $this->registerJs($this->blocks['placeOrder'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
  377. </script>