Advertisement
krot

MODX shk historyOrder

Mar 7th, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.96 KB | None | 0 0
  1. <table class="table table-hover">
  2.   <thead>
  3.     <tr>
  4.       <th scope="col">#</th>
  5.       <th scope="col">Дата</th>
  6.       <th scope="col">Способ доставки</th>
  7.       <th scope="col">Способ оплаты</th>
  8.       <th scope="col">Сумма заказа</th>
  9.       <th scope="col">Статус</th>
  10.       <th scope="col"></th>
  11.      
  12.     </tr>
  13.   </thead>
  14.   <tbody>
  15.     [[!pdoPage?
  16.     &element=`historyOrder`
  17.     &chunk=`historyOrder`
  18.     &chunk_product=`historyOrderProduct`
  19.     &chunk_modal=`historyOrderModal`
  20.     &limit=`10`
  21.     &tplPageWrapper=`@INLINE <div class="pagination_prof"><ul class="pagination">[[+first]][[+prev]][[+pages]][[+next]][[+last]]</ul></div>`
  22.    
  23.     ]]
  24.   </tbody>
  25. </table>
  26.  
  27.  
  28. [[!+page.nav]]
  29.  
  30.  
  31.  
  32.  
  33. <div class="modal" tabindex="-1" role="dialog" id="orderModal">
  34.   <div class="modal-dialog md_pp" role="document">
  35.     <div class="modal-content">
  36.        
  37.         <div class="modal-header">
  38.         <h5 class="modal-title">Состав заказа №<span class="orderNum"></span></h5>
  39.         <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  40.           <span aria-hidden="true">&times;</span>
  41.         </button>
  42.       </div>
  43.    
  44.       <div class="modal-body">
  45.        
  46.       </div>
  47.       <div class="modal-footer">
  48.         <button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
  49.       </div>
  50.     </div>
  51.   </div>
  52. </div>
  53.  
  54.  
  55.  
  56.  
  57. <script>
  58.    
  59.    
  60. function historyOrder(id_order){
  61.  
  62.  
  63.  $.ajax({
  64.       url: "/cabinet/istoriya-zakazov?id="+id_order+"&ajax=1",
  65.       type: 'GET',
  66.       dataType: 'html',
  67.       success: function (o) {
  68.           $('.orderNum').html(id_order);
  69.          $('#orderModal .modal-body').html(o);
  70.          
  71.        $('#orderModal').modal('show');
  72.        
  73.        
  74.        
  75.       }
  76.     });
  77.  
  78.  
  79.  
  80.      
  81.    
  82. }
  83.    
  84.    
  85. </script>
  86. -----------------------------
  87. <?php
  88. $totalVar=$modx->getOption('totalVar', $scriptProperties, 'total');
  89.  
  90. $limit=$modx->getOption('limit', $scriptProperties, 10);
  91. $offset=$modx->getOption('offset', $scriptProperties, 0);
  92.  
  93.  
  94. $chunk= (empty($chunk))?'historyOrder':$chunk;
  95. $chunk_product= (empty($chunk_product))?'historyOrderProduct':$chunk_product;
  96. $chunk_modal= (empty($chunk_modal))?'historyOrderModal':$chunk_modal;
  97.  
  98.  
  99.  
  100.  
  101.  
  102. $user = $modx->getUser();
  103. $userid=$user->get('id');
  104. if(!$userid)return;
  105.  
  106.  
  107.  
  108. $modx->addPackage('shopkeeper3', $modx->getOption('core_path').'components/shopkeeper3/model/');
  109.  
  110.  
  111. $status=array('default','Новый','Принят к оплате',"Отправлен","Выполнен","Отменен","Оплата получена");
  112.  
  113.  
  114.  
  115. if(!$_GET['ajax']){
  116. ##########
  117. //count page
  118. $q = $modx->newQuery('shk_order');
  119. $q->where(array(
  120.     'userid' => $userid
  121. ));
  122. $q->select(array(
  123.     "count(*) as total"
  124.  
  125. ));
  126. $s = $q->prepare();
  127. $s->execute();
  128. $rows = $s->fetchAll(PDO::FETCH_ASSOC);
  129. $modx->setPlaceholder($totalVar,$rows[0]['total']);//pdoPage
  130. ###########
  131. $q = $modx->newQuery('shk_order');
  132. $q->where(array(
  133.     'userid' => $userid
  134. ));
  135. $q->limit($limit, $offset);
  136. $q->sortby('id', 'DESC');
  137.  
  138. $orders = $modx->getCollection('shk_order', $q);
  139.  
  140.  
  141.  $item='';
  142.  foreach ($orders as $p) {
  143.     $item.=$modx->getChunk($chunk,array(
  144.        
  145.     'id'=> $p->get('id'),
  146.     'price'=>$p->get('price'),
  147.     'date'=>$p->get('date'),
  148.     'delivery'=> $p->get('delivery'),
  149.     'payment'=> $p->get('payment'),
  150.     'status'=> $status[$p->get('status')],
  151.        
  152.                         )
  153.                         );
  154.     }
  155.  
  156.  
  157. }else{
  158. #########################################################################################################
  159.    /*товар*/
  160.     $id=(int)$_GET['id'];
  161.    
  162.    $order = $modx->getObject('shk_order', $id);  
  163.    $contacts=json_decode($order->get('contacts'),true);
  164.    
  165.     $contacts=array_column($contacts,'value','name');
  166.  
  167.     $item='';
  168.     $purchases = $modx->getCollection('shk_purchases', array('order_id' => $id));
  169.     $count=0;
  170.     foreach ($purchases as $p) {
  171.      // print_r( $p->toArray());
  172.      $data=json_decode($p->get('data'),true);
  173.      $options=json_decode($p->get('options'),true);
  174.      
  175.      $art=$data ['articul']?$data ['articul']:$options ['article'][0] ;
  176.      $brand=$data ['brand']?$data ['brand']:$options ['brand'][0] ;
  177.      $stock=$data ['stock']?$data ['stock']:$options ['stock'][0] ;
  178.      $count+=$p->get('count');
  179.           $item.=$modx->getChunk($chunk_product,array(
  180.        
  181.                 'name'=> $p->get('name'),
  182.                 'price'=> $p->get('price'),
  183.                 'count'=> $p->get('count'),
  184.                
  185.                 'art'=> $art,
  186.                 'brand'=> $brand,
  187.                 'stock'=> $stock,
  188.          
  189.        
  190.                         )
  191.                         );
  192.  
  193.     }
  194.      
  195.      echo  $modx->getChunk($chunk_modal,array(
  196.                         'order_id'=>$id,
  197.                        
  198.                         'item'=>$item,
  199.                        
  200.                          
  201.                          'price'=>$order->get('price'),
  202.                          'count'=> $count,
  203.                          'fullname'=>$contacts['fullname'],
  204.                          'email'=>$order->get('email'),
  205.                          'phone'=>$contacts['phone'],
  206.                          'city'=>$contacts['city'],
  207.                          'zip'=>$contacts['zip'],
  208.                          'address'=>$contacts['address'],
  209.                          'message'=>$contacts['message'],
  210.                          
  211.                          'date'=>$order->get('date'),
  212.                          'delivery'=>$order->get('delivery'),
  213.                          'delivery_price'=>$order->get('delivery_price'),
  214.                          'payment'=>$order->get('payment'),
  215.                      
  216.                        
  217.    
  218.  
  219.  
  220.  
  221.                        
  222.                          
  223.    
  224.    
  225.    
  226.                         ));
  227.     exit;
  228. }
  229.  
  230.  
  231.  
  232.  
  233. return $item;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement