index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  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. ?>
  10. <?php
  11. use fecshop\app\apphtml5\helper\Format;
  12. use fec\helpers\CRequest;
  13. ?>
  14. <div class="main container one-column">
  15. <div class="col-main">
  16. <?= Yii::$service->page->widget->render('flashmessage'); ?>
  17. <?php if(is_array($cart_info) && !empty($cart_info)): ?>
  18. <div class="product_page">
  19. <div class="cart">
  20. <div class="page-title title-buttons">
  21. <div class="shopping-cart-img">
  22. <?= Yii::$service->page->translate->__('Shopping Cart'); ?>
  23. </div>
  24. </div>
  25. <div class="cart_info">
  26. <div class="cart_select_div">
  27. <input id="cart_select_all" type="checkbox" name="cart_select_all" class="cart_select cart_select_all">
  28. &nbsp;
  29. <label for="cart_select_all">Select All Product</label>
  30. </div>
  31. <?php if(is_array($cart_info['products']) && (!empty($cart_info['products']))): ?>
  32. <?php foreach($cart_info['products'] as $product_one): ?>
  33. <div class="row">
  34. <div class="col-33">
  35. <input rel="<?= $product_one['item_id']; ?>" <?= ($product_one['active'] == Yii::$service->cart->quoteItem->activeStatus ) ? 'checked="checked"' : '' ?> type="checkbox" name="cart_select_item" class="cart_select cart_select_item">
  36. <a external href="<?= $product_one['url'] ?>" title="<?= $product_one['name'] ?>" class="product-image">
  37. <img src="<?= Yii::$service->product->image->getResize($product_one['image'],[150,150],false) ?>" alt="<?= $product_one['name'] ?>" width="75" height="75">
  38. </a>
  39. </div>
  40. <div class="col-66">
  41. <h2 class="product-name">
  42. <a external href="<?= $product_one['url'] ?>"><?= $product_one['name'] ?></a>
  43. </h2>
  44. <?php if(is_array($product_one['custom_option_info'])): ?>
  45. <ul class="options">
  46. <?php foreach($product_one['custom_option_info'] as $label => $val): ?>
  47. <li><?= Yii::$service->page->translate->__(ucwords($label).':') ?><?= Yii::$service->page->translate->__($val) ?> </li>
  48. <?php endforeach; ?>
  49. </ul>
  50. <div class="clear"></div>
  51. <?php endif; ?>
  52. <span class="cart-price">
  53. <span class="price"><?= $currency_info['symbol']; ?><?= Format::price($product_one['product_price']); ?></span>
  54. </span>
  55. <div class="cart_qty">
  56. <a externalhref="javascript:void(0)" class="cartqtydown changeitemqty" rel="<?= $product_one['item_id']; ?>" num="<?= $product_one['qty']; ?>">-</a>
  57. <input name="cart[qty]" size="4" title="Qty" class="input-text qty" rel="<?= $product_one['item_id']; ?>" maxlength="12" value="<?= $product_one['qty']; ?>">
  58. <a externalhref="javascript:void(0)" class="cartqtyup changeitemqty" rel="<?= $product_one['item_id']; ?>" num="<?= $product_one['qty']; ?>">+</a>
  59. <div class="clear"></div>
  60. </div>
  61. <a externalhref="javascript:void(0)" rel="<?= $product_one['item_id']; ?>" title="Remove item" class="btn-remove btn-remove2"><span class="icon icon-remove"></span></a>
  62. </div>
  63. </div>
  64. <?php endforeach; ?>
  65. <?php endif; ?>
  66. </div>
  67. <div class="cart-collaterals">
  68. <div class="col2-set">
  69. <div class="col-1">
  70. </div>
  71. <div class="col-2">
  72. <form id="discount-coupon-form" >
  73. <div class="discount">
  74. <h2><?= Yii::$service->page->translate->__('Discount Codes');?></h2>
  75. <div class="discount-form">
  76. <div class="input-box">
  77. <div class="ui-input-text ui-body-inherit ui-corner-all ui-shadow-inset">
  78. <input type="hidden" class="couponType" value="<?= $cart_info['coupon_code'] ? 1 : 2 ; ?>" />
  79. <input style="color:#777;" class="input-text" id="coupon_code" name="coupon_code" value="<?= $cart_info['coupon_code']; ?>">
  80. </div>
  81. </div>
  82. <div class="buttons-coupon">
  83. <a external data-role="button" href="javascript:void(0)" class="add_coupon_submit submitbutton ui-link ui-btn ui-shadow ui-corner-all" role="button">
  84. <span>
  85. <span><?= Yii::$service->page->translate->__($cart_info['coupon_code'] ? 'Cancel Coupon' : 'Add Coupon') ; ?></span>
  86. </span>
  87. </a>
  88. </div>
  89. <div class="clear"></div>
  90. <div class="coupon_add_log"></div>
  91. </div>
  92. </div>
  93. </form>
  94. <div class="clear"></div>
  95. </div>
  96. </div>
  97. <div class="cart_cost">
  98. <div class="row no-gutter">
  99. <div class="col-66"><?= Yii::$service->page->translate->__('Sub Total');?> : </div>
  100. <div class="col-33"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['product_total']); ?></div>
  101. </div>
  102. <div class="row no-gutter">
  103. <div class="col-66"><?= Yii::$service->page->translate->__('Sub Weight');?> : </div>
  104. <div class="col-33"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['product_weight']); ?> Kg</div>
  105. </div>
  106. <div class="row no-gutter">
  107. <div class="col-66"><?= Yii::$service->page->translate->__('Sub Volume');?> : </div>
  108. <div class="col-33"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['product_volume']); ?> c㎡</div>
  109. </div>
  110. <div class="row no-gutter">
  111. <div class="col-66"><?= Yii::$service->page->translate->__('Shipping Cost');?> : </div>
  112. <div class="col-33"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['shipping_cost']); ?></div>
  113. </div>
  114. <div class="row no-gutter">
  115. <div class="col-66"><?= Yii::$service->page->translate->__('Discount');?> :</div>
  116. <div class="col-33">-<?= $currency_info['symbol']; ?><?= Format::price($cart_info['coupon_cost']); ?>%</div>
  117. </div>
  118. <div class="row no-gutter">
  119. <div class="col-66"><?= Yii::$service->page->translate->__('Grand Total');?> :</div>
  120. <div class="col-33"><?= $currency_info['symbol']; ?><?= Format::price($cart_info['grand_total']) ?></div>
  121. </div>
  122. </div>
  123. <div class="totals cart-totals">
  124. <div class="proceed_to_checkout">
  125. <div class="row no-gutter">
  126. <div class="col-50">
  127. <button onclick="location.href='<?= Yii::$service->url->getUrl('checkout/onepage'); ?>'" type="button" title="Proceed to Checkout" class="button btn-proceed-checkout btn-checkout"><span><span><?= Yii::$service->page->translate->__('Proceed to Pay');?></span></span></button>
  128. </div>
  129. <div class="col-50">
  130. <a external class="express_paypal" href="<?= Yii::$service->url->getUrl('payment/paypal/express/start'); ?>">
  131. <img src="<?= Yii::$service->image->getImgUrl('/images/pay.png') ?>" />
  132. </a>
  133. </div>
  134. </div>
  135. </div>
  136. </div>
  137. <div class="clear"></div>
  138. </div>
  139. </div>
  140. </div>
  141. <?php else: ?>
  142. <div class="empty_cart ">
  143. <?php
  144. $param = ['urlB' => '<a external rel="nofollow" href="'.Yii::$service->url->getUrl('customer/account/login').'">','urlE' =>'</a>'];
  145. ?>
  146. <div id="empty_cart_info">
  147. <?= Yii::$service->page->translate->__('Your Shopping Cart is empty');?>
  148. <a external href="<?= Yii::$service->url->homeUrl(); ?>"><?= Yii::$service->page->translate->__('Start shopping now!');?></a>
  149. <br>
  150. <?= Yii::$service->page->translate->__('Please {urlB}log in{urlE} to view the products you have previously added to your Shopping Cart.',$param);?>
  151. </div>
  152. </div>
  153. <div class="empty_cart_img">
  154. </div>
  155. <?php endif; ?>
  156. </div>
  157. </div>
  158. <script>
  159. // add to cart js
  160. <?php $this->beginBlock('changeCartInfo') ?>
  161. csrfName = "<?= CRequest::getCsrfName() ?>";
  162. csrfVal = "<?= CRequest::getCsrfValue() ?>";
  163. $(document).ready(function(){
  164. // set select all checkbox
  165. selectall = "<?= Yii::$app->request->get('selectall') ?>";
  166. selectAllChecked = false;
  167. if (selectall == 1) {
  168. selectAllChecked = true;
  169. } else {
  170. item_select_all = 1;
  171. $(".cart_select_item").each(function(){
  172. checked = $(this).is(':checked');
  173. if (checked == false) {
  174. item_select_all = 0;
  175. }
  176. });
  177. if (item_select_all == 1) {
  178. selectAllChecked = true;
  179. }
  180. }
  181. if (selectAllChecked) {
  182. $(".cart_select_all").attr("checked",selectAllChecked);
  183. } else {
  184. $(".cart_select_all").removeAttr("checked");
  185. }
  186. currentUrl = "<?= Yii::$service->url->getUrl('checkout/cart') ?>";
  187. updateCartInfoUrl = "<?= Yii::$service->url->getUrl('checkout/cart/updateinfo') ?>";
  188. selectOneProductUrl = "<?= Yii::$service->url->getUrl('checkout/cart/selectone') ?>";
  189. selectAllProductUrl = "<?= Yii::$service->url->getUrl('checkout/cart/selectall') ?>";
  190. $(".cartqtydown").click(function(){
  191. $item_id = $(this).attr("rel");
  192. num = $(this).attr("num");
  193. if(num > 1){
  194. $data = {
  195. item_id:$item_id,
  196. up_type:"less_one"
  197. };
  198. $data[csrfName] = csrfVal;
  199. $.ajax({
  200. async:true,
  201. timeout: 6000,
  202. dataType: 'json',
  203. type:'post',
  204. data: $data,
  205. url:updateCartInfoUrl,
  206. success:function(data, textStatus){
  207. if(data.status == 'success'){
  208. window.location.href=currentUrl;
  209. }
  210. },
  211. error:function (XMLHttpRequest, textStatus, errorThrown){}
  212. });
  213. }
  214. });
  215. $(".cartqtyup").click(function(){
  216. $item_id = $(this).attr("rel");
  217. $data = {
  218. item_id:$item_id,
  219. up_type:"add_one"
  220. };
  221. $data[csrfName] = csrfVal;
  222. $.ajax({
  223. async:true,
  224. timeout: 6000,
  225. dataType: 'json',
  226. type:'post',
  227. data: $data,
  228. url:updateCartInfoUrl,
  229. success:function(data, textStatus){
  230. if(data.status == 'success'){
  231. window.location.href=currentUrl;
  232. }
  233. },
  234. error:function (XMLHttpRequest, textStatus, errorThrown){}
  235. });
  236. });
  237. $(".btn-remove").click(function(){
  238. $item_id = $(this).attr("rel");
  239. $data = {
  240. item_id:$item_id,
  241. up_type:"remove"
  242. };
  243. $data[csrfName] = csrfVal;
  244. $.ajax({
  245. async:true,
  246. timeout: 6000,
  247. dataType: 'json',
  248. type:'post',
  249. data: $data,
  250. url:updateCartInfoUrl,
  251. success:function(data, textStatus){
  252. if(data.status == 'success'){
  253. window.location.href=currentUrl;
  254. }
  255. },
  256. error:function (XMLHttpRequest, textStatus, errorThrown){}
  257. });
  258. });
  259. $(".cart_select_item").click(function(){
  260. $item_id = $(this).attr("rel");
  261. checked = $(this).is(':checked');
  262. checked = checked ? 1 : 0;
  263. $data = {
  264. item_id:$item_id,
  265. checked:checked
  266. };
  267. $data[csrfName] = csrfVal;
  268. $.ajax({
  269. async:true,
  270. timeout: 6000,
  271. dataType: 'json',
  272. type:'post',
  273. data: $data,
  274. url:selectOneProductUrl,
  275. success:function(data, textStatus){
  276. if(data.status == 'success'){
  277. window.location.href = currentUrl;
  278. }
  279. },
  280. error:function (XMLHttpRequest, textStatus, errorThrown){}
  281. });
  282. });
  283. $(".cart_select_all").click(function(){
  284. checked = $(this).is(':checked');
  285. checked = checked ? 1 : 0;
  286. $data = {
  287. checked:checked
  288. };
  289. $data[csrfName] = csrfVal;
  290. selectCurrentUrl = currentUrl + '?selectall=' + checked;
  291. $.ajax({
  292. async:true,
  293. timeout: 6000,
  294. dataType: 'json',
  295. type:'post',
  296. data: $data,
  297. url:selectAllProductUrl,
  298. success:function(data, textStatus){
  299. if(data.status == 'success'){
  300. window.location.href = selectCurrentUrl;
  301. }
  302. },
  303. error:function (XMLHttpRequest, textStatus, errorThrown){}
  304. });
  305. });
  306. $(".add_coupon_submit").click(function(){
  307. coupon_code = $("#coupon_code").val();
  308. coupon_type = $(".couponType").val();
  309. coupon_url = "";
  310. if(coupon_type == 2){
  311. coupon_url = "<?= Yii::$service->url->getUrl('checkout/cart/addcoupon'); ?>";
  312. }else if(coupon_type == 1){
  313. coupon_url = "<?= Yii::$service->url->getUrl('checkout/cart/cancelcoupon'); ?>";
  314. }
  315. if(!coupon_code){
  316. //alert("coupon can not empty!");
  317. }
  318. $data = {"coupon_code":coupon_code};
  319. $data[csrfName] = csrfVal;
  320. $.ajax({
  321. async:true,
  322. timeout: 6000,
  323. dataType: 'json',
  324. type: 'post',
  325. data: $data,
  326. url:coupon_url,
  327. success:function(data, textStatus){
  328. if(data.status == 'success'){
  329. window.location.href=currentUrl;
  330. }else if(data.content == 'nologin'){
  331. window.location.href="<?= Yii::$service->url->getUrl('customer/account/login'); ?>";
  332. }else{
  333. $(".coupon_add_log").html(data.content);
  334. }
  335. },
  336. error:function (XMLHttpRequest, textStatus, errorThrown){}
  337. });
  338. });
  339. });
  340. <?php $this->endBlock(); ?>
  341. <?php $this->registerJs($this->blocks['changeCartInfo'],\yii\web\View::POS_END);//将编写的js代码注册到页面底部 ?>
  342. </script>
  343. <?php // Yii::$service->page->trace->getTraceCartJsCode($trace_cart_info) // 这个改成服务端发送加入购物车数据,而不是js传递的方式 ?>