WC_Naguro_Designer

The WooCommerce Naguro Connect WC Naguro Designer class.

Defined (1)

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

/includes/woocommerce/core/class-wc-naguro-designer.php  
  1. class WC_Naguro_Designer { 
  2. /** 
  3. * @var WC_Product 
  4. */ 
  5. private $product; 
  6.  
  7. /** @var Naguro_Session_Model */ 
  8. private $session; 
  9.  
  10. /** @var string */ 
  11. private $hash; 
  12.  
  13. /** 
  14. * @param $product WC_Product 
  15. */ 
  16. public function __construct( $product ) { 
  17. $this->product = $product; 
  18. if ( $this->prepare_request() ) { 
  19. $this->html = $this->get_html(); 
  20. wp_enqueue_script('naguro-designer', $this->get_js_url()); 
  21. wp_enqueue_style('naguro-designer', $this->get_css_url()); 
  22. } else { 
  23. $this->html = 'The editor is not loaded yet.'; 
  24.  
  25. /** 
  26. * @return bool 
  27. */ 
  28. private function prepare_request() { 
  29. $this->session = new Naguro_Session_Model(); 
  30. $this->session->set( 'product_id', $this->product->id); 
  31. WC()->session->set('naguro_session_id', $this->session->get_id()); 
  32. $this->session->save_data(); 
  33.  
  34. $this->hash = $this->product_hash( $this->product ); 
  35.  
  36. return ( $this->does_editor_exist($this->hash ) ); 
  37.  
  38. private function does_editor_exist( $hash ) { 
  39. $editor_option = get_option( 'naguro_editor_' . $hash, false ); 
  40. return ( false === $editor_option ) ? false : true; 
  41.  
  42. private function product_hash( $product ) { 
  43. $design_areas = get_post_meta( $product->id, 'naguro_design_area' ); 
  44.  
  45. $use_overlay_module = false; 
  46.  
  47. foreach ( $design_areas as $design_area ) { 
  48. if ( ! empty( $design_area['product_overlay_id'] ) && 0 != $design_area['product_overlay_id'] ) { 
  49. $use_overlay_module = true; 
  50. break; 
  51.  
  52. if ( $use_overlay_module ) { 
  53. $params['modules'] = 'main, overlay'; 
  54. } else { 
  55. $params['modules'] = 'main'; 
  56.  
  57. $params['version'] = '1.1'; 
  58. $params['theme'] = 'standard'; 
  59. $params['language'] = 'en_GB'; 
  60. $params['callback'] = home_url('naguro-editor/download'); 
  61.  
  62. return md5( implode( ', ', $params ) ); 
  63.  
  64. private function get_html() { 
  65. $editor_option = get_option( 'naguro_editor_' . $this->hash ); 
  66.  
  67. $html = file_get_contents($editor_option['html']); 
  68. $html = str_replace('{{endpoint}}', get_home_url() . '/wp-admin/admin-ajax.php', $html ); 
  69. $html = str_replace('{{session-id}}', $this->session->get_id(), $html ); 
  70. return $html; 
  71.  
  72. private function get_css_url() { 
  73. $editor_option = get_option( 'naguro_editor_' . $this->hash ); 
  74. return $editor_option['css']; 
  75.  
  76. private function get_js_url() { 
  77. $editor_option = get_option( 'naguro_editor_' . $this->hash ); 
  78. return $editor_option['js']; 
  79.  
  80. public function output() { 
  81. echo $this->html;