WCB_Product_XML_Document

The WooCommerce Billogram Integration WCB Product XML Document class.

Defined (1)

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

/class-billogram2-product-xml.php  
  1. class WCB_Product_XML_Document extends WCB_XML_Document{ 
  2. /** 
  3. */ 
  4. function __construct() { 
  5. parent::__construct(); 
  6. /** 
  7. * Creates a XML representation of a Product 
  8. * @access public 
  9. * @param mixed $product 
  10. * @return mixed 
  11. */ 
  12. public function create($product) { 
  13. //$root = 'Article'; 
  14. $productNode = array(); 
  15. $sku = $product->get_sku(); 
  16. $tax = $product->get_price_including_tax() - $product->get_price_excluding_tax(); 
  17. $taxper = round($tax*100/$product->get_price_excluding_tax()); 
  18. if($sku) { 
  19. $productNode['item_no'] = $sku; 
  20. if($product->post->post_type == 'product_variation' && $product->post->post_parent != 0) { 
  21. $attr = wc_get_product_variation_attributes($product->id); 
  22. //logthis($attr); 
  23. $attribute = ''; 
  24. foreach($attr as $key => $value) { 
  25. $attribute .= $value.'-'; 
  26. $parentProductTitle = explode('#', $product->get_title()); 
  27. $title = $attribute.$parentProductTitle[1]; 
  28. $productNode['title'] = (strlen($title) > 40) ? substr($title, 0, 36).'...' : $title; 
  29. }else{ 
  30. $productNode['title'] = (strlen($product->get_title()) > 40) ? substr($product->get_title(), 0, 36).'...' : $product->get_title(); 
  31. //$productNode['title'] = (strlen($product->get_title()) > 40) ? substr($product->get_title(), 0, 36).'...' : $product->get_title(); 
  32. $productDesc = strip_tags(get_post($product->id)->post_content); 
  33. $productNode['description'] = (strlen($productDesc) > 200) ? substr($productDesc, 0, 196).'...' : $productDesc; 
  34. $productNode['price'] = $product->get_price_excluding_tax() ? round($product->get_price_excluding_tax(), 2) : $product->get_regular_price(); 
  35. $productNode['vat'] = $taxper; 
  36. //$productNode['QuantityInStock'] = $product->get_stock_quantity(); 
  37. $productNode['unit'] = 'unit'; 
  38. //$productNode['ArticleNumber'] = $product->get_sku(); 
  39. return $productNode; 
  40. //return $this->generate($root, $productNode); 
  41. /** 
  42. * Updates a XML representation of a Product 
  43. * @access public 
  44. * @param mixed $product 
  45. * @return mixed 
  46. */ 
  47. public function update($product) {  
  48.  
  49. //$root = 'Article'; 
  50. $productNode = array(); 
  51.  
  52. $tax = $product->get_price_including_tax() - $product->get_price_excluding_tax(); 
  53. $taxper = round($tax*100/$product->get_price_excluding_tax()); 
  54. if($product->post->post_type == 'product_variation' && $product->post->post_parent != 0) { 
  55. $attr = wc_get_product_variation_attributes($product->id); 
  56. //logthis($attr); 
  57. $attribute = ''; 
  58. foreach($attr as $key => $value) { 
  59. $attribute .= $value.'-'; 
  60. $parentProductTitle = explode('#', $product->get_title()); 
  61. $title = $attribute.$parentProductTitle[1]; 
  62. $productNode['title'] = (strlen($title) > 40) ? substr($title, 0, 36).'...' : $title; 
  63. }else{ 
  64. $productNode['title'] = (strlen($product->get_title()) > 40) ? substr($product->get_title(), 0, 36).'...' : $product->get_title(); 
  65. $productDesc = strip_tags(get_post($product->id)->post_content); 
  66. $productNode['description'] = (strlen($productDesc) > 200) ? substr($productDesc, 0, 196).'...' : $productDesc; 
  67. $productNode['price'] = $product->get_price_excluding_tax() ? round($product->get_price_excluding_tax(), 2) : $product->get_regular_price(); 
  68. $productNode['vat'] = $taxper; 
  69. //$productNode['ArticleNumber'] = $product->get_sku(); 
  70. //$productNode['QuantityInStock'] = $product->get_stock_quantity(); 
  71. $productNode['unit'] = 'unit'; 
  72. return $productNode; 
  73. //return $this->generate($root, $productNode); 
  74.  
  75. /** 
  76. * Creates a XML representation of a Product 
  77. * @access public 
  78. * @param mixed $product 
  79. * @return mixed 
  80. */ 
  81. public function create_price($product) { 
  82.  
  83. $root = 'Price'; 
  84. $options = get_option('woocommerce_billogram_general_settings'); 
  85. $price = array(); 
  86.  
  87. if(!isset($meta['pricelist_id'])) { 
  88. $price['PriceList'] = 'A'; 
  89. else{ 
  90. $price['PriceList'] = $meta['pricelist_id']; 
  91. if($options['activate-vat'] == 'on') { 
  92. $price['Price'] = $product->get_price_excluding_tax() ? $product->get_price_excluding_tax() : $product->get_regular_price(); 
  93. logthis('YES'); 
  94. else{ 
  95. $price['Price'] = $product->get_price_excluding_tax() ? $product->get_price_excluding_tax() : $product->get_regular_price(); 
  96. logthis('NO'); 
  97. $price['ArticleNumber'] = $product->get_sku(); 
  98. $price['FromQuantity'] = 1; 
  99.  
  100. return $this->generate($root, $price); 
  101.  
  102. /** 
  103. * Creates a XML representation of a Product 
  104. * @access public 
  105. * @param mixed $product 
  106. * @return mixed 
  107. */ 
  108. public function update_price($product) { 
  109.  
  110. $root = 'Price'; 
  111. $price = array(); 
  112.  
  113. $options = get_option('woocommerce_billogram_general_settings'); 
  114. if($options['activate-vat'] == 'on') { 
  115. $price['Price'] = $product->get_price_excluding_tax() ? $product->get_price_excluding_tax() : $product->get_regular_price(); 
  116. logthis('YES'); 
  117. else{ 
  118. $price['Price'] = $product->get_price_excluding_tax() ? $product->get_price_excluding_tax() : $product->get_regular_price(); 
  119. logthis('NO'); 
  120.  
  121. return $this->generate($root, $price); 
  122.  
  123.  
  124. /** 
  125. * Create product meta key value in well formated text, added in 2.1 
  126. * @access public 
  127. * @param mixed $order 
  128. * @return formated product meta key, value text. 
  129. */ 
  130. public function get_product_meta($metadata) { 
  131. //logthis($metadata); 
  132. $attribute = array(); 
  133. foreach ( $metadata as $meta_key => $meta_value ) { 
  134. // Skip hidden core fields 
  135. //logthis('item meta:'); 
  136. //logthis($meta_value); 
  137. if ( in_array( $meta_key, apply_filters( 'woocommerce_hidden_order_itemmeta', array( 
  138. '_qty',  
  139. '_tax_class',  
  140. '_product_id',  
  141. '_variation_id',  
  142. '_line_subtotal',  
  143. '_line_subtotal_tax',  
  144. '_line_total',  
  145. '_line_tax',  
  146. '_line_tax_data',  
  147. ) ) ) ) { 
  148. continue; 
  149.  
  150. // Skip serialised meta 
  151. if ( is_serialized( $meta_value ) ) { 
  152. continue; 
  153.  
  154. // Get attribute data 
  155. if ( taxonomy_exists( wc_sanitize_taxonomy_name( $meta_key ) ) ) { 
  156. $term = get_term_by( 'slug', $meta_value[0], wc_sanitize_taxonomy_name( $meta_key ) ); 
  157. $meta_key = wc_attribute_label( wc_sanitize_taxonomy_name( $meta_key ) ); 
  158. $meta_value[0] = isset( $term->name ) ? $term->name : $meta_value[0]; 
  159. } else { 
  160. $meta_key = apply_filters( 'woocommerce_attribute_label', wc_attribute_label( $meta_key, $_product ), $meta_key ); 
  161.  
  162. array_push($attribute, ' '.$meta_key . ': ' . $meta_value[0]); 
  163. //logthis('attribute'); 
  164. //logthis(explode(', ', $attribute)); 
  165. return implode(', ', $attribute);