Naguro_Order_Preview_Get_Request

The WooCommerce Naguro Connect Naguro Order Preview Get Request class.

Defined (1)

The class is defined in the following location(s).

/includes/naguro/requests/class-order-preview-get-request.php  
  1. class Naguro_Order_Preview_Get_Request extends Naguro_Request { 
  2. public function output() { 
  3. $session = new Naguro_Session_Model( $this->params['session'] ); 
  4. $design_areas = get_post_meta( $session->get('product_id'), 'naguro_design_area' ); 
  5.  
  6. $options = get_option('naguro_settings'); 
  7. $dimension_unit = isset( $options['dimension_unit'] ) ? $options['dimension_unit'] : get_option('woocommerce_dimension_unit'); 
  8. $dpi = isset( $options['dpi'] ) ? intval( $options['dpi'] ) : 300; 
  9.  
  10. foreach ( $_POST['data'] as $key => $subtype ) { 
  11. if ( isset( $subtype['layers'] ) ) { 
  12. foreach ( $subtype['layers'] as $layer_key => $layer ) { 
  13. if ( 'image' == $layer['type'] ) { 
  14. $image_src = wp_get_attachment_image_src( $layer['image_id'], 'full' ); 
  15. $this->params['data'][$key]['layers'][$layer_key]['image_src'] = $image_src[0]; 
  16. $this->params['data'][$key]['dpi'] = $dpi; 
  17.  
  18. $this->params['design_area_array'] = array(); 
  19. foreach ( $design_areas as $key => $design_area ) { 
  20. $image_src = wp_get_attachment_image_src( $design_area['product_image_id'], 'full' ); 
  21. $width = ( $image_src[1] / 100 ) * $design_area['print_width']; 
  22. $height = ( $image_src[2] / 100 ) * $design_area['print_height']; 
  23.  
  24. $this->params['design_area_array'][ $key ] = array( 
  25. 'width' => $width,  
  26. 'perc_width' => $design_area['print_width'],  
  27. 'original_width' => $image_src[1],  
  28. 'output_width' => $design_area['output_width'],  
  29. 'height' => $height,  
  30. 'perc_height' => $design_area['print_height'],  
  31. 'original_height' => $image_src[2],  
  32. 'output_height' => $design_area['output_height'],  
  33. 'dimension_unit' => $dimension_unit,  
  34. ); 
  35.  
  36. $request_params['timeout'] = 30; 
  37.  
  38. $this->handler->handle_request('order-preview', $this->params, 'post', $request_params ); 
  39. $data = $this->handler->get_data(); 
  40. $output_array = array(); 
  41.  
  42. $output_data = json_decode( $data['body'] ); 
  43.  
  44. foreach ( $output_data as $part ) { 
  45. $output_array[] = array( 
  46. 'src' => $part->src,  
  47. 'full_size_src' => $part->full_size_src,  
  48. 'design_area_id' => $part->design_area_id,  
  49. ); 
  50.  
  51. $session->set('order_preview', $output_array ); 
  52.  
  53. echo json_encode($output_array); die();