WCML_Products_UI

Created by OnTheGo Systems.

Defined (1)

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

/inc/template-classes/class-wcml-products-ui.php  
  1. class WCML_Products_UI extends WPML_Templates_Factory { 
  2.  
  3. private $woocommerce_wpml; 
  4. private $sitepress; 
  5.  
  6. function __construct( &$woocommerce_wpml, &$sitepress ) { 
  7. parent::__construct(); 
  8.  
  9. $this->woocommerce_wpml = $woocommerce_wpml; 
  10. $this->sitepress = $sitepress; 
  11.  
  12. public function get_model() { 
  13.  
  14. $active_languages = $this->sitepress->get_active_languages(); 
  15. $product_data = $this->get_products_data(); 
  16. $pagination_url = $this->get_pagination_url(); 
  17. $filter_url = $this->get_filter_url(); 
  18. $pn = $this->get_current_page_number(); 
  19. $last = $this->get_last_page_num( $product_data[ 'products_count' ] ); 
  20. $slang = $this->get_source_language(); 
  21. $search = isset( $_GET[ 'cat' ] ) ? true : false; 
  22. $title_sort = isset( $_GET['ts'] ) ? $_GET['ts'] == 'asc' ? 'desc' : 'asc' : 'asc'; 
  23. $date_sort = isset( $_GET['ds'] ) ? $_GET['ds'] == 'asc' ? 'desc' : 'asc' : 'asc'; 
  24.  
  25. $model = array( 
  26. 'data' => array( 
  27. 'products' => $product_data[ 'products' ],  
  28. 'slang' => $slang,  
  29. 'search' => $search 
  30. ),  
  31. 'strings' => array( 
  32. 'image' => __( 'Image', 'woocommerce-multilingual' ),  
  33. 'product' => __( 'Product', 'woocommerce-multilingual' ),  
  34. 'type' => __( 'Type', 'woocommerce-multilingual' ),  
  35. 'date' => __( 'Date', 'woocommerce-multilingual' ),  
  36. 'categories' => __( 'Categories', 'woocommerce-multilingual' ),  
  37. 'no_products' => __( 'No products found', 'woocommerce-multilingual' ),  
  38. 'draft' => __( 'Draft', 'woocommerce-multilingual' ),  
  39. 'private' => __( 'Private', 'woocommerce-multilingual' ),  
  40. 'pending' => __( 'Pending', 'woocommerce-multilingual' ),  
  41. 'future' => __( 'Scheduled', 'woocommerce-multilingual' ),  
  42. 'parent' => __( 'Parent product: %s', 'woocommerce-multilingual' ),  
  43. 'edit_item' => __( 'Edit this item', 'woocommerce-multilingual' ),  
  44. 'edit' => __( 'Edit', 'woocommerce-multilingual' ),  
  45. 'view_link' => __( 'View "%s"', 'woocommerce-multilingual' ),  
  46. 'view' => __( 'View', 'woocommerce-multilingual' ),  
  47. 'published' => __( 'Published', 'woocommerce-multilingual' ),  
  48. 'modified' => __( 'Last Modified', 'woocommerce-multilingual' ),  
  49. ),  
  50. 'filter_urls' => array( 
  51. 'product' => $filter_url.'&ts='.$title_sort,  
  52. 'product_sorted' => isset( $_GET['ts']) ? ' sorted '.$_GET['ts'] : '',  
  53. 'date' => $filter_url.'&ds='.$date_sort,  
  54. 'date_sorted' => isset( $_GET['ds'] ) ? ' sorted '.$_GET['ds'] : '',  
  55. ),  
  56. 'filter' => array( 
  57. 'display' => ! isset( $_GET['prid'] ) && ! $this->get_current_translator_id() ? true : false,  
  58. 'slang' => $slang,  
  59. 'active_languages' => $active_languages,  
  60. 'categories' => $this->get_products_categories( $slang ),  
  61. 'category_from_filter' => isset( $_GET['cat'] ) ? $_GET['cat'] : false,  
  62. 'trst' => isset( $_GET['trst'] ) ? $_GET['trst'] : false,  
  63. 'st' => isset( $_GET['st'] ) ? $_GET['st'] : false,  
  64. 'search_text' => isset( $_GET['s'] ) ? $_GET['s'] : '',  
  65. 'all_statuses' => $this->get_wc_statuses(),  
  66. 'products_admin_url' => admin_url( 'admin.php?page=wpml-wcml&tab=products' ),  
  67. 'pagination_url' => $pagination_url,  
  68. 'search' => $search,  
  69. 'strings' => array( 
  70. 'all_lang' => __( 'All languages', 'woocommerce-multilingual' ),  
  71. 'all_cats' => __( 'All categories', 'woocommerce-multilingual' ),  
  72. 'all_trnsl_stats' => __( 'All translation statuses', 'woocommerce-multilingual' ),  
  73. 'not_trnsl' => __( 'Not translated or needs updating', 'woocommerce-multilingual' ),  
  74. 'need_upd' => __( 'Needs updating', 'woocommerce-multilingual' ),  
  75. 'in_progress' => __( 'Translation in progress', 'woocommerce-multilingual' ),  
  76. 'complete' => __( 'Translation complete', 'woocommerce-multilingual' ),  
  77. 'all_stats' => __( 'All statuses', 'woocommerce-multilingual' ),  
  78. 'filter' => __( 'Filter', 'woocommerce-multilingual' ),  
  79. 'reset' => __( 'Reset', 'woocommerce-multilingual' ),  
  80. 'search' => __( 'Search', 'woocommerce-multilingual' ),  
  81. ),  
  82. ),  
  83. 'languages_flags' => $this->woocommerce_wpml->products->get_translation_flags( $active_languages, $slang, $this->get_current_job_language() ),  
  84. 'request_uri' => $_SERVER["REQUEST_URI"],  
  85. 'nonces' => array( 
  86. 'upd_product' => wp_create_nonce( 'update_product_actions' ),  
  87. 'get_product_data' => wp_create_nonce( 'wcml_product_data' ),  
  88. ),  
  89. 'pagination' => array( 
  90. 'display' => $product_data[ 'products' ] && ! isset( $_GET['prid'] ) && $last > 1 ? true: false,  
  91. 'products_count' => $product_data[ 'products_count' ],  
  92. 'pn' => $pn,  
  93. 'last' => $last,  
  94. 'pagination_url' => $pagination_url,  
  95. 'pagination_first' => $pagination_url.'1',  
  96. 'pagination_prev' => $pagination_url . ( (int) $pn > 1 ? $pn - 1 : $pn ),  
  97. 'pagination_next' => $pagination_url . ( (int) $pn < $last ? $pn + 1 : $last ),  
  98. 'pagination_last' => $pagination_url . $last,  
  99. 'show' => !isset( $_GET['prid'] ) && isset( $last ) && $last > 1 ? true : false,  
  100. 'strings' => array( 
  101. 'items' => __( '%d items', 'woocommerce-multilingual' ),  
  102. 'first' => __( 'Go to the first page', 'woocommerce-multilingual' ),  
  103. 'previous' => __( 'Go to the previous page', 'woocommerce-multilingual' ),  
  104. 'select' => __( 'Select Page', 'woocommerce-multilingual' ),  
  105. 'current' => __( 'Current page', 'woocommerce-multilingual' ),  
  106. 'of' => __( 'of', 'woocommerce-multilingual' ),  
  107. 'next' => __( 'Go to the next page', 'woocommerce-multilingual' ),  
  108. 'last' => __( 'Go to the last page', 'woocommerce-multilingual' ),  
  109. ); 
  110.  
  111. return $model; 
  112.  
  113. public function get_products_data() { 
  114.  
  115. $active_languages = $this->sitepress->get_active_languages(); 
  116.  
  117. $products_info = $this->get_product_info_from_self_edit_mode(); 
  118. if( !$products_info ) { 
  119. $products_info = $this->get_product_info_for_translators(); 
  120. if( !$products_info ) { 
  121. $products_info = $this->get_products_from_filter(); 
  122.  
  123. if( !$products_info && current_user_can( 'wpml_operate_woocommerce_multilingual' ) ) { 
  124. $products_info = array(); 
  125. $products_info[ 'products' ] = $this->get_product_list( $this->get_current_page_number(), $this->get_page_limit(), $this->get_source_language() ); 
  126. $products_info[ 'products_count' ] = $this->get_products_count( $this->get_source_language() ); 
  127.  
  128. $slang = $this->get_source_language(); 
  129. $products = $products_info[ 'products' ]; 
  130.  
  131. foreach( $products as $key => $product ) { 
  132.  
  133. $products[ $key ]->edit_post_link = get_edit_post_link( $product->ID ); 
  134.  
  135. if( has_post_thumbnail( $product->ID ) ) { 
  136. $products[ $key ]->post_thumbnail = get_the_post_thumbnail_url( $product->ID, array( 150, 150 ) ); 
  137. }else{ 
  138. $products[ $key ]->post_thumbnail = wc_placeholder_img_src(); 
  139.  
  140. $original_product_lang = $this->woocommerce_wpml->products->get_original_product_language( $product->ID ); 
  141.  
  142. if ( ! $slang ) { 
  143. $original_lang = $original_product_lang; 
  144. } else { 
  145. $original_lang = $slang; 
  146.  
  147. $products[ $key ]->orig_flag_url = $this->sitepress->get_flag_url( $original_lang ); 
  148.  
  149. if( $product->post_parent != 0 ) { 
  150. $products[ $key ]->parent_title = get_the_title( $product->post_parent ); 
  151.  
  152. $products[ $key ]->view_link = get_post_permalink( $product->ID ); 
  153.  
  154.  
  155. if ( isset( $current_translator ) ) { 
  156. $prod_lang = $original_product_lang; 
  157. } else { 
  158. $prod_lang = $slang; 
  159.  
  160. $trid = $this->sitepress->get_element_trid( $product->ID, 'post_' . $product->post_type ); 
  161. $product_translations = $this->sitepress->get_element_translations( $trid, 'post_' . $product->post_type, true, true ); 
  162.  
  163. ob_start(); 
  164. $this->woocommerce_wpml->products->get_translation_statuses( $product->ID, $product_translations, $active_languages, $prod_lang, $trid, $this->get_current_job_language() ); 
  165. $products[ $key ]->translation_statuses = ob_get_contents(); 
  166. ob_end_clean(); 
  167.  
  168. $products[ $key ]->categories_list = $this->get_categories_list( $product->ID, $this->get_cat_url() ); 
  169.  
  170. $prod = wc_get_product( $product->ID ); 
  171. $products[ $key ]->icon_class = WooCommerce_Functions_Wrapper::get_product_type( $product->ID ); 
  172.  
  173. if ( $prod->is_virtual() ) { 
  174. $products[ $key ]->icon_class = 'virtual'; 
  175. } else if ( $prod->is_downloadable() ) { 
  176. $products[ $key ]->icon_class = 'downloadable'; 
  177.  
  178. if ( $product->post_status == "publish" ) { 
  179. $products[ $key ]->formated_date = date(' Y/m/d', strtotime( $product->post_date ) ); 
  180. }else{ 
  181. $products[ $key ]->formated_date = date(' Y/m/d', strtotime( $product->post_modified ) ); 
  182.  
  183.  
  184. return array( 'products' => $products, 'products_count' => $products_info[ 'products_count' ] ); 
  185.  
  186. public function get_product_info_from_self_edit_mode() { 
  187.  
  188. if ( isset( $_GET[ 'prid' ] ) ) { 
  189.  
  190. $prid = sanitize_text_field( $_GET[ 'prid' ] ); 
  191.  
  192. if ( ! $this->woocommerce_wpml->products->is_original_product( $prid ) ) { 
  193. $products[] = get_post( $this->woocommerce_wpml->products->get_original_product_id( $prid ) ); 
  194. } else { 
  195. $products[] = get_post( $prid ); 
  196. $products_count = 1; 
  197.  
  198. return array( 'products' => $products, 'products_count' => $products_count ); 
  199.  
  200. return false; 
  201.  
  202.  
  203. public function get_product_info_for_translators() { 
  204. global $iclTranslationManagement; 
  205.  
  206. if ( ! current_user_can( 'wpml_operate_woocommerce_multilingual' ) ) { 
  207.  
  208. $icl_translation_filter[ 'translator_id' ] = $this->get_current_translator_id(); 
  209. $icl_translation_filter[ 'include_unassigned' ] = true; 
  210. $icl_translation_filter[ 'limit_no' ] = $this->get_page_limit(); 
  211. $translation_jobs = $iclTranslationManagement->get_translation_jobs( (array) $icl_translation_filter ); 
  212. $products = array(); 
  213. $products_count = 0; 
  214.  
  215. foreach ( $translation_jobs as $translation_job ) { 
  216. if ( $translation_job->original_post_type == 'post_product' && ! array_key_exists( $translation_job->original_doc_id, $products ) ) { 
  217. $products[ $translation_job->original_doc_id ] = get_post( $translation_job->original_doc_id ); 
  218. $products_count ++; 
  219.  
  220. return array( 'products' => $products, 'products_count' => $products_count ); 
  221.  
  222. return false; 
  223.  
  224. /** 
  225. * get list of products 
  226. * $page - number of page; 
  227. * $limit - limit product on one page; 
  228. * if($page = 0 && $limit=0) return all products; 
  229. * return array; 
  230. */ 
  231. public function get_product_list( $page = 1, $limit = 20, $slang ) { 
  232. global $wpdb; 
  233.  
  234. $sql = "SELECT p.ID, p.post_parent FROM $wpdb->posts AS p 
  235. LEFT JOIN {$wpdb->prefix}icl_translations AS icl ON icl.element_id = p.id 
  236. WHERE p.post_type = 'product' AND p.post_status IN ('publish', 'future', 'draft', 'pending', 'private') 
  237. AND icl.element_type= 'post_product' AND icl.source_language_code IS NULL"; 
  238.  
  239. if($slang) { 
  240. $sql .= " AND icl.language_code = %s "; 
  241. $sql = $wpdb->prepare( $sql, $slang ); 
  242.  
  243. $sql .= ' ORDER BY p.id DESC'; 
  244.  
  245. $products = $wpdb->get_results( $sql ); 
  246.  
  247. return $this->display_hierarchical( $products, $page, $limit); 
  248.  
  249. public function display_hierarchical( $products, $pagenum, $per_page ) { 
  250. global $wpdb; 
  251.  
  252. $output_products = array(); 
  253. $top_level_products = array(); 
  254. $children_products = array(); 
  255.  
  256. if( !empty( $products ) ) { 
  257.  
  258. foreach ($products as $product) { 
  259. // catch and repair bad products 
  260. if ($product->post_parent == $product->ID) { 
  261. $product->post_parent = 0; 
  262. $wpdb->update($wpdb->posts, array('post_parent' => 0), array('ID' => $product->ID)); 
  263.  
  264. if (0 == $product->post_parent) { 
  265. $top_level_products[] = $product->ID; 
  266. } else { 
  267. $children_products[$product->post_parent][] = $product->ID; 
  268.  
  269. $count = 0; 
  270. $start = ($pagenum - 1) * $per_page; 
  271. $end = $start + $per_page; 
  272.  
  273. foreach ($top_level_products as $product_id) { 
  274. if ($count >= $end) 
  275. break; 
  276.  
  277. if ($count >= $start) { 
  278. $output_products[] = get_post($product_id); 
  279.  
  280. if (isset($children_products[$product_id])) { 
  281. foreach ($children_products[$product_id] as $children) { 
  282. $output_products[] = get_post($children); 
  283. $count++; 
  284. unset($children_products[$product_id]); 
  285. } else { 
  286. if (isset($children_products[$product_id])) { 
  287. $count += count($children_products[$product_id]); 
  288.  
  289. $count++; 
  290.  
  291. return $output_products; 
  292.  
  293. /** 
  294. * get products count 
  295. */ 
  296. public function get_products_count( $slang ) { 
  297. global $wpdb; 
  298.  
  299. $sql = "SELECT count(p.id) FROM $wpdb->posts AS p 
  300. LEFT JOIN {$wpdb->prefix}icl_translations AS icl ON icl.element_id = p.id 
  301. WHERE p.post_type = 'product' AND p.post_status IN ('publish', 'future', 'draft', 'pending', 'private') 
  302. AND icl.element_type= 'post_product' AND icl.source_language_code IS NULL"; 
  303.  
  304. if( $slang ) { 
  305. $sql .= " AND icl.language_code = %s "; 
  306. $count = $wpdb->get_var( $wpdb->prepare( $sql, $slang ) ); 
  307. }else{ 
  308. $count = $wpdb->get_var( $sql ); 
  309.  
  310. return (int)$count; 
  311.  
  312. /** 
  313. * get products from search 
  314. * $title - product name 
  315. * $category - product category 
  316. */ 
  317. public function get_products_from_filter( ) { 
  318. global $wpdb; 
  319.  
  320. $title = isset( $_GET['s'] ) ? $_GET['s'] : ''; 
  321. $category = isset( $_GET['cat'] ) ? $_GET['cat'] : null; 
  322. $translation_status = isset( $_GET['trst'] ) ? $_GET['trst'] : false; 
  323. $product_status = isset( $_GET['st'] ) ? $_GET['st'] : false; 
  324. $slang = $this->get_source_language(); 
  325. $page = $this->get_current_page_number(); 
  326. $limit = $this->get_page_limit(); 
  327. $title_sort = isset( $_GET['ts'] ) ? $_GET['ts'] : false; 
  328. $date_sort = isset( $_GET['ds'] ) ? $_GET['ds'] : false; 
  329.  
  330. if( empty($title) && is_null( $category ) && !$title_sort && !$date_sort ) { 
  331. return false; 
  332.  
  333. $current_language = $slang; 
  334. $prepare_arg = array(); 
  335. $prepare_arg[] = '%'.$title.'%'; 
  336. if( $slang ) { 
  337. $prepare_arg[] = $current_language; 
  338.  
  339. $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM $wpdb->posts AS p"; 
  340.  
  341. if($category) { 
  342. $sql .= " LEFT JOIN $wpdb->term_relationships AS tx ON tx.object_id = p.id"; 
  343.  
  344. $sql .= " LEFT JOIN {$wpdb->prefix}icl_translations AS t ON t.element_id = p.id"; 
  345.  
  346. if(in_array($translation_status, array('not', 'need_update', 'in_progress', 'complete'))) { 
  347.  
  348. foreach($this->sitepress->get_active_languages() as $lang) { 
  349.  
  350. if( $lang['code'] == $slang ) continue; 
  351.  
  352. $tbl_alias_suffix = str_replace('-', '_', $lang['code']); 
  353. $sql .= " LEFT JOIN {$wpdb->prefix}icl_translations iclt_{$tbl_alias_suffix} 
  354. ON iclt_{$tbl_alias_suffix}.trid=t.trid "; 
  355.  
  356. $sql .= " AND iclt_{$tbl_alias_suffix}.language_code='{$lang['code']}'\n"; 
  357.  
  358. $sql .= " LEFT JOIN {$wpdb->prefix}icl_translation_status iclts_{$tbl_alias_suffix} 
  359. ON iclts_{$tbl_alias_suffix}.translation_id=iclt_{$tbl_alias_suffix}.translation_id\n"; 
  360.  
  361.  
  362.  
  363. $sql .= " WHERE p.post_title LIKE '%s' AND p.post_type = 'product' AND t.element_type = 'post_product' AND t.source_language_code IS NULL"; 
  364.  
  365. if( $slang ) { 
  366. $sql .= " AND t.language_code = %s"; 
  367.  
  368. if( $product_status && $product_status != 'all' ) { 
  369. $sql .= " AND p.post_status = %s "; 
  370. $prepare_arg[] = $product_status; 
  371. }else{ 
  372. $sql .= " AND p.post_status NOT IN ('trash', 'auto-draft', 'inherit') "; 
  373.  
  374. if($category) { 
  375. $sql .= " AND tx.term_taxonomy_id = %d "; 
  376. $prepare_arg[] = $category; 
  377.  
  378. if(in_array($translation_status, array('not', 'need_update', 'in_progress', 'complete'))) { 
  379. $sql .= " AND ("; 
  380. switch($translation_status) { 
  381. case 'not': 
  382. foreach($this->sitepress->get_active_languages() as $lang) { 
  383. if($lang['code'] == $slang) continue; 
  384. $tbl_alias_suffix = str_replace('-', '_', $lang['code']); 
  385. $sql .= sprintf( "( p.ID iN (  
  386. SELECT iclt_orig.element_id  
  387. FROM {$wpdb->prefix}icl_translations iclt_orig  
  388. LEFT JOIN {$wpdb->prefix}icl_translations iclt_%s  
  389. ON iclt_%s.trid= iclt_orig.trid AND  
  390. iclt_%s.language_code='%s'  
  391. WHERE iclt_orig.source_language_code IS NULL AND  
  392. iclt_%s.element_id IS NULL AND 
  393. iclt_%s.element_type IN ('post_product', 'post_product_variation')  
  394. )  
  395. ) OR ",  
  396. esc_sql( $tbl_alias_suffix ), esc_sql( $tbl_alias_suffix ), esc_sql( $tbl_alias_suffix ),  
  397. esc_sql( $lang['code'] ), esc_sql( $tbl_alias_suffix ), esc_sql( $tbl_alias_suffix ) 
  398. ); 
  399. break; 
  400. case ( $translation_status == 'need_update' || $translation_status == 'not' ): 
  401. foreach($this->sitepress->get_active_languages() as $lang) { 
  402. if($lang['code'] == $slang) continue; 
  403. $tbl_alias_suffix = str_replace('-', '_', $lang['code']); 
  404. $sql .= "( iclts_{$tbl_alias_suffix}.needs_update = 1 ) OR\n"; 
  405. break; 
  406. case 'in_progress': 
  407. foreach($this->sitepress->get_active_languages() as $lang) { 
  408. if($lang['code'] == $slang) continue; 
  409. $tbl_alias_suffix = str_replace('-', '_', $lang['code']); 
  410. $sql .= "( iclts_{$tbl_alias_suffix}.status = ".ICL_TM_IN_PROGRESS.") OR\n"; 
  411. break; 
  412. case 'complete': 
  413. foreach($this->sitepress->get_active_languages() as $lang) { 
  414. if($lang['code'] == $slang) continue; 
  415. $tbl_alias_suffix = str_replace('-', '_', $lang['code']); 
  416. $sql .= "( (iclts_{$tbl_alias_suffix}.status = ".ICL_TM_COMPLETE." OR iclts_{$tbl_alias_suffix}.status = ".ICL_TM_DUPLICATE.") AND iclts_{$tbl_alias_suffix}.needs_update = 0 ) OR\n"; 
  417. break; 
  418. $sql = substr($sql, 0, -3); 
  419. $sql .= " ) "; 
  420.  
  421. if( $title_sort ) { 
  422. $sql .= " ORDER BY p.post_title ".$title_sort ; 
  423. }elseif( $date_sort ) { 
  424. $sql .= " ORDER BY p.post_date ".$date_sort ; 
  425. }else{ 
  426. $sql .= " ORDER BY p.id DESC "; 
  427.  
  428. $sql .= " LIMIT ".($page-1)*$limit.", ".$limit; 
  429.  
  430. $data = array(); 
  431.  
  432. $data['products'] = $wpdb->get_results($wpdb->prepare($sql, $prepare_arg)); 
  433. $data['count'] = $wpdb->get_var("SELECT FOUND_ROWS()"); 
  434.  
  435. return array( 'products' => $data['products'], 'products_count' => $data['count'] ); 
  436.  
  437. public function get_pagination_url() { 
  438.  
  439. $pagination_url = admin_url( 'admin.php?'. http_build_query( $_GET ). '&paged=' ); 
  440.  
  441. return $pagination_url; 
  442.  
  443. public function get_filter_url() { 
  444.  
  445. $filters_array = $_GET; 
  446. if( isset($filters_array['ts'] ) ) { 
  447. unset( $filters_array['ts'] ); 
  448. unset( $filters_array['ds'] ); 
  449. }elseif( isset($filters_array['ds'] ) ) { 
  450. unset( $filters_array['ds'] ); 
  451. unset( $filters_array['ts'] ); 
  452.  
  453. $filter_url = admin_url( 'admin.php?'. http_build_query( $filters_array ) ); 
  454.  
  455. return $filter_url; 
  456.  
  457. public function get_cat_url() { 
  458.  
  459. $filters_array = $_GET; 
  460. if( isset($filters_array['cat'] ) ) { 
  461. unset( $filters_array['cat'] ); 
  462.  
  463. $filter_cat_url = admin_url( 'admin.php?'. http_build_query( $filters_array ) ); 
  464.  
  465. return $filter_cat_url; 
  466.  
  467. public function get_current_job_language() { 
  468. global $iclTranslationManagement; 
  469.  
  470. if ( isset( $_GET[ 'job_id' ] ) ) { 
  471. $job_id = $_GET[ 'job_id' ]; 
  472.  
  473. $job = $iclTranslationManagement->get_translation_job( $job_id ); 
  474.  
  475. return $job->language_code; 
  476. }else{ 
  477. return false; 
  478.  
  479. public function get_wc_statuses() { 
  480. $all_statuses = get_post_stati(); 
  481. //unset unnecessary statuses 
  482. unset( $all_statuses['trash'], $all_statuses['auto-draft'], $all_statuses['inherit'], $all_statuses['wc-pending'], $all_statuses['wc-processing'], $all_statuses['wc-on-hold'], $all_statuses['wc-completed'], $all_statuses['wc-cancelled'], $all_statuses['wc-refunded'], $all_statuses['wc-failed'], $all_statuses['wc-active'], $all_statuses['wc-switched'], $all_statuses['wc-expired'], $all_statuses['wc-pending-cancel'] ); 
  483.  
  484. return $all_statuses; 
  485.  
  486. public function get_current_page_number() { 
  487. $pn = isset( $_GET['paged'] ) ? $_GET['paged'] : 1; 
  488.  
  489. return $pn; 
  490.  
  491. public function get_page_limit() { 
  492. $lm = ( isset( $_GET['lm'] ) && $_GET['lm'] > 0 ) ? $_GET['lm'] : 20; 
  493.  
  494. return $lm; 
  495.  
  496. public function get_source_language() { 
  497. $slang = isset( $_GET['slang'] ) && $_GET['slang'] != 'all' ? $_GET['slang'] : false; 
  498.  
  499. return $slang; 
  500.  
  501. public function get_last_page_num( $products_count ) { 
  502.  
  503. $last = 1; 
  504.  
  505. if ( $this->get_page_limit() ) { 
  506. $last = $this->get_product_last_page( $products_count, $this->get_page_limit() ); 
  507.  
  508. return $last; 
  509.  
  510.  
  511. /** 
  512. * get pages count 
  513. * $limit - limit product on one page; 
  514. */ 
  515. public function get_product_last_page($count, $limit) { 
  516. $last = ceil((int)$count/(int)$limit); 
  517. return (int)$last; 
  518.  
  519. public function get_current_translator_id() { 
  520. global $iclTranslationManagement; 
  521.  
  522. $translator_id = false; 
  523.  
  524. if ( ! current_user_can( 'wpml_operate_woocommerce_multilingual' ) ) { 
  525. $current_translator = $iclTranslationManagement->get_current_translator(); 
  526. $translator_id = $current_translator->translator_id; 
  527.  
  528. return $translator_id; 
  529.  
  530. public function get_categories_list( $product_id, $filter_cat_url ) { 
  531. $product_categories = wp_get_object_terms( $product_id, 'product_cat' ); 
  532. $categories_list = array(); 
  533. foreach( $product_categories as $key => $product_category ) { 
  534. $categories_list[$key]['href'] = $filter_cat_url.'&cat='.$product_category->term_id; 
  535. $categories_list[$key]['name'] = $product_category->name.( array_key_exists( $key+1, $product_categories ) ? ', ': '' ); 
  536.  
  537. return $categories_list; 
  538.  
  539. public function get_products_categories( $slang = false ) { 
  540. global $wpdb; 
  541.  
  542. $sql = "SELECT tt.term_taxonomy_id, tt.term_id, t.name FROM $wpdb->term_taxonomy AS tt 
  543. LEFT JOIN $wpdb->terms AS t ON tt.term_id = t.term_id 
  544. LEFT JOIN {$wpdb->prefix}icl_translations AS icl ON icl.element_id = tt.term_taxonomy_id 
  545. WHERE tt.taxonomy = 'product_cat' AND icl.element_type= 'tax_product_cat' "; 
  546.  
  547. if ( $slang ) { 
  548. $sql .= " AND icl.language_code = %s "; 
  549. $product_categories = $wpdb->get_results( $wpdb->prepare( $sql, $slang ) ); 
  550. } else { 
  551. $sql .= "AND icl.source_language_code IS NULL"; 
  552. $product_categories = $wpdb->get_results( $sql ); 
  553.  
  554. return $product_categories; 
  555.  
  556.  
  557. public function init_template_base_dir() { 
  558. $this->template_paths = array( 
  559. WCML_PLUGIN_PATH . '/templates/products-list/',  
  560. ); 
  561.  
  562. public function get_template() { 
  563. return 'products.twig';