index.php 16 KB

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