Naguro_Session_Get_Request

The WooCommerce Naguro Connect Naguro Session Get Request class.

Defined (1)

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

/includes/naguro/requests/class-session-get-request.php  
  1. class Naguro_Session_Get_Request extends Naguro_Request { 
  2. private function get_product() { 
  3. return wc_get_product( $this->session->get('product_id')); 
  4.  
  5. /** 
  6. * @param $product WC_Product 
  7. * @return array 
  8. */ 
  9. private function get_design_areas( $product ) { 
  10. return get_post_meta($product->id, 'naguro_design_area', false); 
  11.  
  12. private function get_product_data_array() { 
  13. $product = $this->get_product(); 
  14. $design_areas = $this->get_design_areas( $product ); 
  15.  
  16. $design_areas_array = array(); 
  17. $subtypes_array = array(); 
  18. $i = 1; 
  19. foreach ( $design_areas as $design_area ) { 
  20. $image_src = wp_get_attachment_image_src( $design_area['product_image_id'], 'full' ); 
  21. $image_src = $image_src[0]; 
  22.  
  23. $overlay_src = ''; 
  24.  
  25. if ( isset( $design_area['product_overlay_id'] ) ) { 
  26. $overlay_src = wp_get_attachment_image_src( $design_area['product_overlay_id'], 'full' ); 
  27. $overlay_src = $overlay_src[0]; 
  28.  
  29. $design_areas_array[] = array( 
  30. 'product_design_area_id' => $i,  
  31. 'name' => $design_area['name'],  
  32. 'sort_order' => $i,  
  33. ); 
  34.  
  35. $settings = get_option( 'naguro_settings' ); 
  36. $dimension = $settings['dimension_unit']; 
  37. $dpi = isset( $settings['dpi'] ) ? intval( $settings['dpi'] ) : 300; 
  38.  
  39. $calulator = new WC_Size_Calculator( $dpi ); 
  40.  
  41. switch( $dimension ) { 
  42. case 'yard': 
  43. $src_width = $calulator->yard_to_px($design_area['output_width']); 
  44. $src_height = $calulator->yard_to_px($design_area['output_height']); 
  45. break; 
  46. case 'cm': 
  47. $src_width = $calulator->cm_to_px($design_area['output_width']); 
  48. $src_height = $calulator->cm_to_px($design_area['output_height']); 
  49. break; 
  50. case 'inch': 
  51. $src_width = $calulator->cm_to_px($design_area['output_width']); 
  52. $src_height = $calulator->cm_to_px($design_area['output_height']); 
  53. break; 
  54. default: // mm 
  55. $src_width = $calulator->mm_to_px($design_area['output_width']); 
  56. $src_height = $calulator->mm_to_px($design_area['output_height']); 
  57. break; 
  58.  
  59. $subtypes_array[] = array( 
  60. 'product_subtype_id' => $i,  
  61. 'product_design_area_id' => $i,  
  62. 'is_circle' => false, // @todo implementation plz 
  63. 'output_width' => $design_area['output_width'],  
  64. 'output_height' => $design_area['output_height'],  
  65. 'print_width' => $design_area['print_width'],  
  66. 'print_height' => $design_area['print_height'],  
  67. 'src_width' => $src_width,  
  68. 'src_height' => $src_height,  
  69. 'left' => $design_area['left'],  
  70. 'top' => $design_area['top'],  
  71. 'size_description' => $design_area['size_description'] . ' ('.$src_width.' x '. $src_height . ' px)',  
  72. 'image_src' => $image_src,  
  73. 'overlay_src' => $overlay_src,  
  74. ); 
  75.  
  76. $i++; 
  77.  
  78. return array( 
  79. 'product_id' => $product->id,  
  80. 'name' => $product->get_title(),  
  81. 'design_areas' => $design_areas_array,  
  82. 'subtypes' => $subtypes_array,  
  83. ); 
  84.  
  85. public function output() { 
  86. $object = new StdClass(); 
  87. $object->session_id = $this->session->get_id(); 
  88. $object->locale = 'nl_NL'; 
  89. $object->start_product_subtype_id = 1; 
  90. $object->product = $this->get_product_data_array(); 
  91.  
  92. echo json_encode( $object ); die();