VariableProductTitle
8 years ago
.gitkeep
8 years ago
WpaeInvalidPhpException.php
8 years ago
WpaeInvalidStringException.php
8 years ago
WpaeMethodNotFoundException.php
8 years ago
WpaePhpInterpreterErrorHandler.php
8 years ago
WpaeString.php
8 years ago
WpaeTooMuchRecursionException.php
8 years ago
WpaeXmlProcessor.php
8 years ago
XmlCsvExport.php
8 years ago
XmlExportACF.php
8 years ago
XmlExportComment.php
8 years ago
XmlExportCpt.php
8 years ago
XmlExportEngine.php
8 years ago
XmlExportFiltering.php
8 years ago
XmlExportMediaGallery.php
8 years ago
XmlExportTaxonomy.php
8 years ago
XmlExportUser.php
8 years ago
XmlExportWooCommerce.php
8 years ago
XmlExportWooCommerceCoupon.php
8 years ago
XmlExportWooCommerceOrder.php
8 years ago
XmlGoogleMerchants.php
8 years ago
XmlSpec.php
8 years ago
XmlExportWooCommerceOrder.php
1689 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! class_exists('XmlExportWooCommerceOrder') ) |
| 4 | { |
| 5 | final class XmlExportWooCommerceOrder |
| 6 | { |
| 7 | public static $is_active = true; |
| 8 | |
| 9 | public static $order_sections = array(); |
| 10 | public static $order_items_per_line = false; |
| 11 | public static $orders_data = null; |
| 12 | public static $exportQuery = null; |
| 13 | |
| 14 | private $init_fields = array( |
| 15 | array( |
| 16 | 'name' => 'Order ID', |
| 17 | 'type' => 'woo_order', |
| 18 | 'options' => 'order', |
| 19 | 'label' => 'ID' |
| 20 | ), |
| 21 | array( |
| 22 | 'name' => 'Order Key', |
| 23 | 'type' => 'woo_order', |
| 24 | 'options' => 'order', |
| 25 | 'label' => '_order_key' |
| 26 | ), |
| 27 | array( |
| 28 | 'name' => 'Title', |
| 29 | 'type' => 'woo_order', |
| 30 | 'options' => 'order', |
| 31 | 'label' => 'post_title' |
| 32 | ) |
| 33 | ); |
| 34 | |
| 35 | private $order_core_fields = array(); |
| 36 | |
| 37 | public function __construct() |
| 38 | { |
| 39 | $this->order_core_fields = array('_prices_include_tax', '_customer_ip_address', '_customer_user_agent', '_created_via', '_order_version', '_payment_method', '_cart_discount_tax', '_order_shipping_tax', '_recorded_sales', '_order_stock_reduced', '_recorded_coupon_usage_counts', '_transaction_id'); |
| 40 | |
| 41 | if ( ! class_exists('WooCommerce') |
| 42 | or ( XmlExportEngine::$exportOptions['export_type'] == 'specific' and ! in_array('shop_order', XmlExportEngine::$post_types) ) |
| 43 | or ( XmlExportEngine::$exportOptions['export_type'] == 'advanced' and strpos(XmlExportEngine::$exportOptions['wp_query'], 'shop_order') === false ) ) { |
| 44 | self::$is_active = false; |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | self::$is_active = true; |
| 49 | |
| 50 | if ( empty(PMXE_Plugin::$session) ) // if cron execution |
| 51 | { |
| 52 | $id = $_GET['export_id']; |
| 53 | $export = new PMXE_Export_Record(); |
| 54 | $export->getById($id); |
| 55 | if ( ! $export->isEmpty() and $export->options['export_to'] == 'csv'){ |
| 56 | $this->init_additional_data(); |
| 57 | } |
| 58 | } |
| 59 | else |
| 60 | { |
| 61 | $this->init_additional_data(); |
| 62 | } |
| 63 | |
| 64 | add_filter("wp_all_export_available_sections", array( &$this, "filter_available_sections" ), 10, 1); |
| 65 | add_filter("wp_all_export_csv_rows", array( &$this, "filter_csv_rows"), 10, 2); |
| 66 | add_filter("wp_all_export_init_fields", array( &$this, "filter_init_fields"), 10, 1); |
| 67 | |
| 68 | self::$order_sections = $this->available_sections(); |
| 69 | |
| 70 | } |
| 71 | |
| 72 | // [FILTERS] |
| 73 | |
| 74 | /** |
| 75 | * |
| 76 | * Filter Init Fields |
| 77 | * |
| 78 | */ |
| 79 | public function filter_init_fields($init_fields){ |
| 80 | return $this->init_fields; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * |
| 85 | * Filter Sections in Available Data |
| 86 | * |
| 87 | */ |
| 88 | public function filter_available_sections($sections){ |
| 89 | return array(); |
| 90 | } |
| 91 | |
| 92 | // [\FILTERS] |
| 93 | |
| 94 | public function init( & $existing_meta_keys = array() ){ |
| 95 | |
| 96 | if ( ! self::$is_active ) return; |
| 97 | |
| 98 | if ( ! empty($existing_meta_keys) ) |
| 99 | { |
| 100 | foreach (self::$order_sections as $slug => $section) : |
| 101 | |
| 102 | foreach ($section['meta'] as $cur_meta_key => $cur_meta_label) |
| 103 | { |
| 104 | foreach ($existing_meta_keys as $key => $record_meta_key) |
| 105 | { |
| 106 | if ( $record_meta_key == $cur_meta_key ) |
| 107 | { |
| 108 | unset($existing_meta_keys[$key]); |
| 109 | break; |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | endforeach; |
| 115 | |
| 116 | foreach ( $this->order_core_fields as $core_field ): |
| 117 | |
| 118 | foreach ($existing_meta_keys as $key => $record_meta_key) |
| 119 | { |
| 120 | if ( $record_meta_key == $core_field ) |
| 121 | { |
| 122 | unset($existing_meta_keys[$key]); |
| 123 | break; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | endforeach; |
| 128 | |
| 129 | foreach ($existing_meta_keys as $key => $record_meta_key) |
| 130 | { |
| 131 | self::$order_sections['cf']['meta'][$record_meta_key] = array( |
| 132 | 'name' => $record_meta_key, |
| 133 | 'label' => $record_meta_key, |
| 134 | 'options' => '', |
| 135 | 'type' => 'cf' |
| 136 | ); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | global $wpdb; |
| 141 | $table_prefix = $wpdb->prefix; |
| 142 | |
| 143 | $product_data = $this->available_order_default_product_data(); |
| 144 | |
| 145 | $meta_keys = $wpdb->get_results("SELECT DISTINCT {$table_prefix}woocommerce_order_itemmeta.meta_key FROM {$table_prefix}woocommerce_order_itemmeta"); |
| 146 | if ( ! empty($meta_keys)){ |
| 147 | foreach ($meta_keys as $meta_key) { |
| 148 | if (strpos($meta_key->meta_key, "pa_") !== 0 and empty(self::$order_sections['cf']['meta'][$meta_key->meta_key]) and empty($product_data[$meta_key->meta_key])) |
| 149 | self::$order_sections['other']['meta'][$meta_key->meta_key] = $this->fix_titles(array( |
| 150 | 'name' => $meta_key->meta_key, |
| 151 | 'label' => $meta_key->meta_key, |
| 152 | 'options' => 'items', |
| 153 | 'type' => 'woo_order' |
| 154 | )); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | foreach ( $this->order_core_fields as $core_field ): |
| 159 | |
| 160 | self::$order_sections['other']['meta'][$core_field] = $this->fix_titles(array( |
| 161 | 'name' => $core_field, |
| 162 | 'label' => $core_field, |
| 163 | 'options' => '', |
| 164 | 'type' => 'cf' |
| 165 | )); |
| 166 | |
| 167 | endforeach; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * |
| 172 | * Helper method to fix fields title |
| 173 | * |
| 174 | */ |
| 175 | protected function fix_titles($field) |
| 176 | { |
| 177 | if (is_array($field)) |
| 178 | { |
| 179 | $field['name'] = $this->fix_title($field['name']); |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | $field = $this->fix_title($field); |
| 184 | } |
| 185 | return $field; |
| 186 | } |
| 187 | /** |
| 188 | * |
| 189 | * Helper method to fix single title |
| 190 | * |
| 191 | */ |
| 192 | protected function fix_title($title) |
| 193 | { |
| 194 | $uc_title = ucwords(trim(str_replace("_", " ", $title))); |
| 195 | |
| 196 | return stripos($uc_title, "width") === false ? str_ireplace(array('id', 'url', 'sku'), array('ID', 'URL', 'SKU'), $uc_title) : $uc_title; |
| 197 | } |
| 198 | |
| 199 | public function init_additional_data(){ |
| 200 | |
| 201 | if ( ! self::$is_active || empty(XmlExportEngine::$exportQuery)) return; |
| 202 | |
| 203 | $in_orders = preg_replace("%(SQL_CALC_FOUND_ROWS|LIMIT.*)%", "", XmlExportEngine::$exportQuery->request); |
| 204 | |
| 205 | if ( ! empty($in_orders) ){ |
| 206 | |
| 207 | global $wpdb; |
| 208 | |
| 209 | $table_prefix = $wpdb->prefix; |
| 210 | |
| 211 | if ( empty(self::$orders_data['line_items_max_count']) ){ |
| 212 | self::$orders_data['line_items_max_count'] = $wpdb->get_var($wpdb->prepare("SELECT max(cnt) as line_items_count FROM ( |
| 213 | SELECT order_id, COUNT(*) as cnt FROM {$table_prefix}woocommerce_order_items |
| 214 | WHERE {$table_prefix}woocommerce_order_items.order_item_type = %s AND {$table_prefix}woocommerce_order_items.order_id IN (". $in_orders .") GROUP BY order_id) AS T3", 'line_item')); |
| 215 | } |
| 216 | |
| 217 | if ( empty(self::$orders_data['taxes'])){ |
| 218 | self::$orders_data['taxes'] = $wpdb->get_results($wpdb->prepare("SELECT order_item_id, order_id, order_item_name FROM {$table_prefix}woocommerce_order_items |
| 219 | WHERE {$table_prefix}woocommerce_order_items.order_item_type = %s AND {$table_prefix}woocommerce_order_items.order_id IN (". $in_orders .") GROUP BY order_item_name", 'tax')); |
| 220 | } |
| 221 | |
| 222 | if ( empty(self::$orders_data['coupons'])){ |
| 223 | self::$orders_data['coupons'] = $wpdb->get_results($wpdb->prepare("SELECT order_item_id, order_id, order_item_name FROM {$table_prefix}woocommerce_order_items |
| 224 | WHERE {$table_prefix}woocommerce_order_items.order_item_type = %s AND {$table_prefix}woocommerce_order_items.order_id IN (". $in_orders .") GROUP BY order_item_name", 'coupon')); |
| 225 | } |
| 226 | |
| 227 | if ( empty(self::$orders_data['fees'])){ |
| 228 | self::$orders_data['fees'] = $wpdb->get_results($wpdb->prepare("SELECT order_item_id, order_id, order_item_name FROM {$table_prefix}woocommerce_order_items |
| 229 | WHERE {$table_prefix}woocommerce_order_items.order_item_type = %s AND {$table_prefix}woocommerce_order_items.order_id IN (". $in_orders .") GROUP BY order_item_name", 'fee')); |
| 230 | } |
| 231 | |
| 232 | if ( empty(self::$orders_data['variations'])){ |
| 233 | self::$orders_data['variations'] = $wpdb->get_results($wpdb->prepare("SELECT meta_key FROM {$table_prefix}woocommerce_order_itemmeta |
| 234 | WHERE {$table_prefix}woocommerce_order_itemmeta.meta_key LIKE %s AND {$table_prefix}woocommerce_order_itemmeta.order_item_id IN ( |
| 235 | SELECT {$table_prefix}woocommerce_order_items.order_item_id FROM {$table_prefix}woocommerce_order_items |
| 236 | WHERE {$table_prefix}woocommerce_order_items.order_item_type = %s AND {$table_prefix}woocommerce_order_items.order_id IN (". $in_orders .") ) GROUP BY meta_key", 'pa_%', 'line_item')); |
| 237 | } |
| 238 | |
| 239 | if ( ! empty(PMXE_Plugin::$session) ) |
| 240 | { |
| 241 | PMXE_Plugin::$session->set('orders_data', self::$orders_data); |
| 242 | PMXE_Plugin::$session->save_data(); |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | private $order_items = null; |
| 248 | private $order_taxes = null; |
| 249 | private $order_shipping = null; |
| 250 | private $order_coupons = null; |
| 251 | private $order_surcharge = null; |
| 252 | private $order_refunds = null; |
| 253 | private $__total_fee_amount = null; |
| 254 | private $__coupons_used = null; |
| 255 | private $order_id = null; |
| 256 | |
| 257 | // csv headers |
| 258 | private $woo = array(); |
| 259 | private $woo_order = array(); |
| 260 | private $acfs = array(); |
| 261 | private $taxes = array(); |
| 262 | private $attributes = array(); |
| 263 | private $articles = array(); |
| 264 | private $exclude_from_filling = array(); |
| 265 | |
| 266 | protected function prepare_export_data( $record, $options, $elId, $preview ){ |
| 267 | |
| 268 | // an array with data to export |
| 269 | $data = array( |
| 270 | 'items' => array(), |
| 271 | 'taxes' => array(), |
| 272 | 'shipping' => array(), |
| 273 | 'coupons' => array(), |
| 274 | 'surcharge' => array() |
| 275 | ); |
| 276 | |
| 277 | global $wpdb; |
| 278 | $table_prefix = $wpdb->prefix; |
| 279 | |
| 280 | $implode_delimiter = XmlExportEngine::$implode; |
| 281 | |
| 282 | if ( empty($this->order_id) or $this->order_id != $record->ID) |
| 283 | { |
| 284 | $this->__coupons_used = array(); |
| 285 | |
| 286 | $this->order_id = $record->ID; |
| 287 | |
| 288 | $all_order_items = $wpdb->get_results("SELECT * FROM {$table_prefix}woocommerce_order_items WHERE order_id = {$record->ID}"); |
| 289 | |
| 290 | if ( ! empty($all_order_items) ) |
| 291 | { |
| 292 | foreach ($all_order_items as $item) |
| 293 | { |
| 294 | switch ($item->order_item_type) |
| 295 | { |
| 296 | case 'line_item': |
| 297 | $this->order_items[] = $item; |
| 298 | break; |
| 299 | case 'tax': |
| 300 | $this->order_taxes[] = $item; |
| 301 | break; |
| 302 | case 'shipping': |
| 303 | $this->order_shipping[] = $item; |
| 304 | break; |
| 305 | case 'coupon': |
| 306 | $this->order_coupons[] = $item; |
| 307 | break; |
| 308 | case 'fee': |
| 309 | $this->order_surcharge[] = $item; |
| 310 | break; |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | $this->order_refunds = $wpdb->get_results("SELECT * FROM {$table_prefix}posts WHERE post_parent = {$record->ID} AND post_type = 'shop_order_refund'"); |
| 316 | } |
| 317 | |
| 318 | if ( ! empty($options['cc_value'][$elId]) ){ |
| 319 | |
| 320 | $is_items_in_list = false; |
| 321 | $is_item_data_in_list = false; |
| 322 | foreach ($options['ids'] as $ID => $value) |
| 323 | { |
| 324 | if ($options['cc_options'][$ID] == 'items') |
| 325 | { |
| 326 | $is_items_in_list = true; |
| 327 | } |
| 328 | if ( strpos($options['cc_label'][$ID], "item_data__") !== false ) |
| 329 | { |
| 330 | $is_item_data_in_list = true; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | $fieldSnipped = ( ! empty($options['cc_php'][$elId]) and ! empty($options['cc_code'][$elId]) ) ? $options['cc_code'][$elId] : false; |
| 335 | |
| 336 | if ( ! $is_items_in_list and $is_item_data_in_list ) |
| 337 | { |
| 338 | if ( ! empty($this->order_items)){ |
| 339 | |
| 340 | foreach ($this->order_items as $n => $order_item) { |
| 341 | |
| 342 | $meta_data = $wpdb->get_results("SELECT * FROM {$table_prefix}woocommerce_order_itemmeta WHERE order_item_id = {$order_item->order_item_id}", ARRAY_A); |
| 343 | |
| 344 | $item_data = array(); |
| 345 | |
| 346 | foreach ($options['ids'] as $subID => $subvalue) |
| 347 | { |
| 348 | if ( strpos($options['cc_label'][$subID], 'item_data__') !== false ) |
| 349 | { |
| 350 | $product_id = ''; |
| 351 | $variation_id = ''; |
| 352 | foreach ($meta_data as $meta) { |
| 353 | if ($meta['meta_key'] == '_variation_id' and ! empty($meta['meta_value'])){ |
| 354 | $variation_id = $meta['meta_value']; |
| 355 | } |
| 356 | if ($meta['meta_key'] == '_product_id' and ! empty($meta['meta_value'])){ |
| 357 | $product_id = $meta['meta_value']; |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | $_product_id = empty($variation_id) ? $product_id : $variation_id; |
| 362 | |
| 363 | $_product = get_post($_product_id); |
| 364 | |
| 365 | // do not export anything if product doesn't exist |
| 366 | if ( ! empty($_product) ) |
| 367 | { |
| 368 | $item_add_data = XmlExportCpt::prepare_data( $_product, XmlExportEngine::$exportOptions, false, $this->acfs, $this->woo, $this->woo_order, ",", $preview, true, $subID ); |
| 369 | |
| 370 | if ( ! empty($item_add_data)) |
| 371 | { |
| 372 | foreach ($item_add_data as $item_add_data_key => $item_add_data_value) { |
| 373 | if ( ! isset($item_data[$item_add_data_key])) $item_data[$item_add_data_key] = $item_add_data_value; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | if ( ! empty($item_data)) $data['items'][] = $item_data; |
| 381 | |
| 382 | } |
| 383 | |
| 384 | $this->order_items = null; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | switch ($options['cc_options'][$elId]) { |
| 389 | |
| 390 | case 'order': |
| 391 | case 'customer': |
| 392 | |
| 393 | $data[$options['cc_name'][$elId]] = ( strpos($options['cc_value'][$elId], "_") === 0 ) ? get_post_meta($record->ID, $options['cc_value'][$elId], true) : $record->{$options['cc_value'][$elId]}; |
| 394 | |
| 395 | switch ($options['cc_value'][$elId]){ |
| 396 | case 'post_title': |
| 397 | $data[$options['cc_name'][$elId]] = str_replace("–", '-', $data[$options['cc_name'][$elId]]); |
| 398 | break; |
| 399 | case 'post_date': |
| 400 | $data[$options['cc_name'][$elId]] = prepare_date_field_value($options['cc_settings'][$elId], get_post_time('U', true, $record->ID), "Ymd"); |
| 401 | break; |
| 402 | case '_completed_date': |
| 403 | $_completed_date = get_post_meta($record->ID, '_completed_date', true); |
| 404 | $_completed_date_unix = empty($_completed_date) ? '' : strtotime($_completed_date); |
| 405 | $data[$options['cc_name'][$elId]] = empty($_completed_date_unix) ? '' : prepare_date_field_value($options['cc_settings'][$elId], $_completed_date_unix, "Ymd"); |
| 406 | break; |
| 407 | case '_customer_user_email': |
| 408 | $customer_user_id = get_post_meta($record->ID, '_customer_user', true); |
| 409 | if ( $customer_user_id ){ |
| 410 | $user = get_user_by( 'id', $customer_user_id ); |
| 411 | if ($user){ |
| 412 | $data[$options['cc_name'][$elId]] = $user->user_email; |
| 413 | } |
| 414 | } |
| 415 | if (empty($data[$options['cc_name'][$elId]])) $data[$options['cc_name'][$elId]] = get_post_meta($record->ID, '_billing_email', true); |
| 416 | break; |
| 417 | } |
| 418 | |
| 419 | $data[$options['cc_name'][$elId]] = pmxe_filter( $data[$options['cc_name'][$elId]], $fieldSnipped); |
| 420 | |
| 421 | break; |
| 422 | } |
| 423 | |
| 424 | } |
| 425 | |
| 426 | return $data; |
| 427 | } |
| 428 | |
| 429 | private $additional_articles = array(); |
| 430 | |
| 431 | public function export_csv( & $article, & $titles, $record, $options, $elId, $preview ){ |
| 432 | |
| 433 | if ( ! self::$is_active ) return; |
| 434 | |
| 435 | $data_to_export = $this->prepare_export_data( $record, $options, $elId, $preview ); |
| 436 | |
| 437 | $implode_delimiter = XmlExportEngine::$implode; |
| 438 | |
| 439 | foreach ($data_to_export as $key => $data) { |
| 440 | |
| 441 | if ( in_array($key, array('items', 'taxes', 'shipping', 'coupons', 'surcharge', 'refunds')) ) |
| 442 | { |
| 443 | if ( ! empty($data)) |
| 444 | { |
| 445 | if ( $key == 'items' and ( $options['order_item_per_row'] or $options['xml_template_type'] == 'custom')) |
| 446 | { |
| 447 | foreach ($data as $item) { |
| 448 | $additional_article = array(); |
| 449 | if ( ! empty($item) ){ |
| 450 | foreach ($item as $item_key => $item_value) { |
| 451 | $final_key = preg_replace("%\s#\d*%", "", $item_key); |
| 452 | $additional_article[$final_key] = $item_value; |
| 453 | if ( ! empty($this->exclude_from_filling[$item_key])){ |
| 454 | unset($this->exclude_from_filling[$item_key]); |
| 455 | $this->exclude_from_filling[$final_key] = 1; |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | if ( ! empty($additional_article) ) |
| 461 | { |
| 462 | if ( empty($this->additional_articles) ) |
| 463 | { |
| 464 | foreach ($additional_article as $item_key => $item_value) { |
| 465 | $article[$item_key] = $item_value; |
| 466 | } |
| 467 | } |
| 468 | $this->additional_articles[] = $additional_article; |
| 469 | } |
| 470 | } |
| 471 | } |
| 472 | else |
| 473 | { |
| 474 | foreach ($data as $n => $item) |
| 475 | { |
| 476 | if ( ! empty($item)) |
| 477 | { |
| 478 | foreach ($item as $item_key => $item_value) |
| 479 | { |
| 480 | $final_key = (strpos($item_key, "#") === false and ! in_array($key, array('taxes', 'shipping', 'coupons', 'surcharge', 'refunds'))) ? $item_key . " #" . ($n + 1) : $item_key; |
| 481 | |
| 482 | if ( ! isset($article[$final_key])) |
| 483 | { |
| 484 | $article[$final_key] = $item_value; |
| 485 | } |
| 486 | else |
| 487 | { |
| 488 | $article[$final_key] .= $implode_delimiter . $item_value; |
| 489 | } |
| 490 | // if ( ! in_array($final_key, $titles) ) $titles[] = $final_key; |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | } |
| 497 | else |
| 498 | { |
| 499 | // $article[$key] = $data; |
| 500 | wp_all_export_write_article( $article, $key, $data ); |
| 501 | // if ( ! in_array($key, $titles) ) $titles[] = $key; |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | public function filter_csv_rows($articles, $options){ |
| 507 | |
| 508 | if ( ! empty($this->additional_articles) and ( $options['order_item_per_row'] or $options['xml_template_type'] == 'custom') ) |
| 509 | { |
| 510 | $base_article = $articles[count($articles) - 1]; |
| 511 | array_shift($this->additional_articles); |
| 512 | if ( ! empty($this->additional_articles ) ){ |
| 513 | foreach ($this->additional_articles as $article) { |
| 514 | if ($options['order_item_fill_empty_columns'] and $options['export_to'] == 'csv') |
| 515 | { |
| 516 | if (!empty($this->exclude_from_filling)){ |
| 517 | foreach ($this->exclude_from_filling as $key => $value) { |
| 518 | $article[$key] = isset($article[$key]) ? $article[$key] : ''; |
| 519 | } |
| 520 | } |
| 521 | foreach ($article as $key => $value) { |
| 522 | unset($base_article[$key]); |
| 523 | } |
| 524 | $articles[] = @array_merge($base_article, $article); |
| 525 | } |
| 526 | else |
| 527 | { |
| 528 | $articles[] = $article; |
| 529 | } |
| 530 | } |
| 531 | $this->additional_articles = array(); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | return $articles; |
| 536 | } |
| 537 | |
| 538 | public function get_element_header( & $headers, $options, $element_key ){ |
| 539 | |
| 540 | switch ($options['cc_value'][$element_key]) |
| 541 | { |
| 542 | // Rate Code (per tax) |
| 543 | case 'tax_order_item_name': |
| 544 | // Rate Percentage (per tax) |
| 545 | case 'tax_rate': |
| 546 | // Amount (per tax) |
| 547 | case 'tax_amount': |
| 548 | |
| 549 | if ( ! empty(self::$orders_data['taxes'])) |
| 550 | { |
| 551 | foreach ( self::$orders_data['taxes'] as $tax) { |
| 552 | // $friendly_name = str_replace("per tax", $this->get_rate_friendly_name($tax->order_item_id), $options['cc_name'][$element_key]); |
| 553 | $friendly_name = str_replace(" (per tax)", "", $options['cc_name'][$element_key]); |
| 554 | if ( ! in_array($friendly_name, $headers)) $headers[] = $friendly_name; |
| 555 | if ( ! in_array("Rate Name", $headers)) $headers[] = "Rate Name"; |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | break; |
| 560 | // Discount Amount (per coupon) |
| 561 | case 'discount_amount': |
| 562 | |
| 563 | if ( ! empty(self::$orders_data['coupons'])) |
| 564 | { |
| 565 | foreach ( self::$orders_data['coupons'] as $coupon) { |
| 566 | // $friendly_name = str_replace("per coupon", $coupon->order_item_name, $options['cc_name'][$element_key]); |
| 567 | $friendly_name = str_replace("(per coupon)", "", $options['cc_name'][$element_key]); |
| 568 | if ( ! in_array($friendly_name, $headers)) $headers[] = $friendly_name; |
| 569 | if ( ! in_array("Coupon Code", $headers)) $headers[] = "Coupon Code"; |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | break; |
| 574 | // Fee Amount (per surcharge) |
| 575 | case 'fee_line_total': |
| 576 | |
| 577 | if ( ! empty(self::$orders_data['fees'])) |
| 578 | { |
| 579 | foreach ( self::$orders_data['fees'] as $fee) { |
| 580 | // $friendly_name = str_replace("Amount (per surcharge)", "(" . $fee->order_item_name . ")", $options['cc_name'][$element_key]); |
| 581 | $friendly_name = str_replace(" (per surcharge)", "", $options['cc_name'][$element_key]); |
| 582 | if ( ! in_array($friendly_name, $headers)) $headers[] = $friendly_name; |
| 583 | if ( ! in_array("Fee Name", $headers)) $headers[] = "Fee Name"; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | break; |
| 588 | |
| 589 | // Product Variation Details |
| 590 | case '__product_variation': |
| 591 | |
| 592 | if ( ! empty(self::$orders_data['line_items_max_count']) and ! empty(self::$orders_data['variations'])) |
| 593 | { |
| 594 | if ( $options['order_item_per_row'] or $options['xml_template_type'] == 'custom'){ |
| 595 | foreach ( self::$orders_data['variations'] as $variation) { |
| 596 | $friendly_name = $options['cc_name'][$element_key] . " (" . sanitize_title(str_replace("pa_", "", $variation->meta_key)) . ")"; |
| 597 | if ( ! in_array($friendly_name, $headers)) $headers[] = $friendly_name; |
| 598 | } |
| 599 | } |
| 600 | else{ |
| 601 | for ($i = 1; $i <= self::$orders_data['line_items_max_count']; $i++){ |
| 602 | foreach ( self::$orders_data['variations'] as $variation) { |
| 603 | $friendly_name = $options['cc_name'][$element_key] . " #" . $i . " (" . sanitize_title(str_replace("pa_", "", $variation->meta_key)) . ")"; |
| 604 | if ( ! in_array($friendly_name, $headers)) $headers[] = $friendly_name; |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | break; |
| 611 | |
| 612 | default: |
| 613 | |
| 614 | switch ($options['cc_options'][$element_key]) |
| 615 | { |
| 616 | // Order's product basic data headers |
| 617 | case 'items': |
| 618 | |
| 619 | if ( $options['order_item_per_row'] or $options['xml_template_type'] == 'custom') |
| 620 | { |
| 621 | if ( ! in_array($options['cc_name'][$element_key], $headers)) $headers[] = $options['cc_name'][$element_key]; |
| 622 | } |
| 623 | else |
| 624 | { |
| 625 | if ( ! empty(self::$orders_data['line_items_max_count'])){ |
| 626 | for ($i = 1; $i <= self::$orders_data['line_items_max_count']; $i++){ |
| 627 | $friendly_name = $options['cc_name'][$element_key] . " #" . $i; |
| 628 | if ( ! in_array($friendly_name, $headers)) $headers[] = $friendly_name; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | break; |
| 634 | |
| 635 | default: |
| 636 | |
| 637 | // Order's product advanced data headers |
| 638 | if ( strpos($options['cc_label'][$element_key], 'item_data__') !== false) |
| 639 | { |
| 640 | $element_label = str_replace("item_data__", "", $options['cc_label'][$element_key]); |
| 641 | |
| 642 | $element_headers = array(); |
| 643 | |
| 644 | $element_name = ( ! empty($options['cc_name'][$element_key]) ) ? $options['cc_name'][$element_key] : 'untitled_' . $element_key; |
| 645 | |
| 646 | switch ($options['cc_type'][$element_key]) |
| 647 | { |
| 648 | case 'woo': |
| 649 | |
| 650 | XmlExportEngine::$woo_export->get_element_header( $element_headers, $options, $element_key ); |
| 651 | |
| 652 | break; |
| 653 | |
| 654 | case 'acf': |
| 655 | |
| 656 | if ( ! empty($this->acfs) ){ |
| 657 | $single_acf_field = array_shift($this->acfs); |
| 658 | if ( is_array($single_acf_field)) |
| 659 | { |
| 660 | foreach ($single_acf_field as $acf_header) { |
| 661 | if ( ! in_array($acf_header, $element_headers)) $element_headers[] = $acf_header; |
| 662 | } |
| 663 | } |
| 664 | else |
| 665 | { |
| 666 | if ( ! in_array($single_acf_field, $element_headers)) $element_headers[] = $single_acf_field; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | break; |
| 671 | |
| 672 | default: |
| 673 | |
| 674 | if ( ! in_array($element_name, $element_headers)) |
| 675 | { |
| 676 | $element_headers[] = $element_name; |
| 677 | } |
| 678 | else |
| 679 | { |
| 680 | $is_added = false; |
| 681 | $i = 0; |
| 682 | do |
| 683 | { |
| 684 | $new_element_name = $element_name . '_' . md5($i); |
| 685 | |
| 686 | if ( ! in_array($new_element_name, $element_headers) ) |
| 687 | { |
| 688 | $element_headers[] = $new_element_name; |
| 689 | $is_added = true; |
| 690 | } |
| 691 | |
| 692 | $i++; |
| 693 | } |
| 694 | while ( ! $is_added ); |
| 695 | } |
| 696 | |
| 697 | // $element_headers[] = $element_name; |
| 698 | |
| 699 | break; |
| 700 | } |
| 701 | |
| 702 | if ( ! empty($element_headers) ) |
| 703 | { |
| 704 | foreach ($element_headers as $header) |
| 705 | { |
| 706 | if ( $options['order_item_per_row'] or $options['xml_template_type'] == 'custom') |
| 707 | { |
| 708 | if ( ! in_array($header, $headers)) $headers[] = $header; |
| 709 | } |
| 710 | else |
| 711 | { |
| 712 | if ( ! empty(self::$orders_data['line_items_max_count'])){ |
| 713 | for ($i = 1; $i <= self::$orders_data['line_items_max_count']; $i++){ |
| 714 | $friendly_name = $header . " #" . $i; |
| 715 | if ( ! in_array($friendly_name, $headers)) $headers[] = $friendly_name; |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | else |
| 723 | { |
| 724 | if ( ! in_array($options['cc_name'][$element_key], $headers)) |
| 725 | { |
| 726 | $headers[] = $options['cc_name'][$element_key]; |
| 727 | } |
| 728 | else |
| 729 | { |
| 730 | $is_added = false; |
| 731 | $i = 0; |
| 732 | do |
| 733 | { |
| 734 | $new_element_name = $options['cc_name'][$element_key] . '_' . md5($i); |
| 735 | |
| 736 | if ( ! in_array($new_element_name, $headers) ) |
| 737 | { |
| 738 | $headers[] = $new_element_name; |
| 739 | $is_added = true; |
| 740 | } |
| 741 | |
| 742 | $i++; |
| 743 | } |
| 744 | while ( ! $is_added ); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | break; |
| 749 | } |
| 750 | |
| 751 | break; |
| 752 | |
| 753 | } |
| 754 | |
| 755 | } |
| 756 | |
| 757 | public function get_rate_friendly_name( $order_item_id ){ |
| 758 | |
| 759 | global $wpdb; |
| 760 | $table_prefix = $wpdb->prefix; |
| 761 | |
| 762 | $rate_details = null; |
| 763 | $meta_data = $wpdb->get_results("SELECT * FROM {$table_prefix}woocommerce_order_itemmeta WHERE order_item_id = {$order_item_id}", ARRAY_A); |
| 764 | foreach ($meta_data as $meta) { |
| 765 | if ($meta['meta_key'] == 'rate_id'){ |
| 766 | $rate_id = $meta['meta_value']; |
| 767 | $rate_details = $wpdb->get_row("SELECT * FROM {$table_prefix}woocommerce_tax_rates WHERE tax_rate_id = {$rate_id}"); |
| 768 | break; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | return $rate_details ? $rate_details->tax_rate_name : ''; |
| 773 | |
| 774 | } |
| 775 | |
| 776 | public function export_xml( & $xmlWriter, $record, $options, $elId, $preview ){ |
| 777 | |
| 778 | if ( ! self::$is_active ) return; |
| 779 | |
| 780 | $data_to_export = $this->prepare_export_data( $record, $options, $elId, $preview ); |
| 781 | |
| 782 | foreach ($data_to_export as $key => $data) { |
| 783 | |
| 784 | if ( in_array($key, array('items', 'taxes', 'shipping', 'coupons', 'surcharge', 'refunds')) ) |
| 785 | { |
| 786 | if ( ! empty($data)){ |
| 787 | $xmlWriter->startElement('Order' . ucfirst($key)); |
| 788 | foreach ($data as $item) { |
| 789 | if ( ! empty($item)){ |
| 790 | $xmlWriter->startElement(preg_replace("%(s|es)$%", "", ucfirst($key))); |
| 791 | foreach ($item as $item_key => $item_value) { |
| 792 | $element_name_ns = ''; |
| 793 | $element_name = str_replace("-", "_", preg_replace('/[^a-z0-9:_]/i', '', preg_replace("%#\d*%", "", $item_key))); |
| 794 | if (strpos($element_name, ":") !== false) |
| 795 | { |
| 796 | $element_name_parts = explode(":", $element_name); |
| 797 | $element_name_ns = (empty($element_name_parts[0])) ? '' : $element_name_parts[0]; |
| 798 | $element_name = (empty($element_name_parts[1])) ? 'untitled_' . $ID : $element_name_parts[1]; |
| 799 | } |
| 800 | $xmlWriter->beginElement($element_name_ns, $element_name, null); |
| 801 | $xmlWriter->writeData($item_value, $element_name); |
| 802 | $xmlWriter->closeElement(); |
| 803 | // $xmlWriter->writeElement(str_replace("-", "_", sanitize_title(preg_replace("%#\d%", "", $item_key))), $item_value); |
| 804 | } |
| 805 | $xmlWriter->closeElement(); |
| 806 | } |
| 807 | } |
| 808 | $xmlWriter->closeElement(); |
| 809 | } |
| 810 | } |
| 811 | else |
| 812 | { |
| 813 | $element_name_ns = ''; |
| 814 | $element_name = str_replace("-", "_", preg_replace('/[^a-z0-9:_]/i', '', $key)); |
| 815 | if (strpos($element_name, ":") !== false) |
| 816 | { |
| 817 | $element_name_parts = explode(":", $element_name); |
| 818 | $element_name_ns = (empty($element_name_parts[0])) ? '' : $element_name_parts[0]; |
| 819 | $element_name = (empty($element_name_parts[1])) ? 'untitled_' . $ID : $element_name_parts[1]; |
| 820 | } |
| 821 | |
| 822 | $xmlWriter = apply_filters('wp_all_export_add_before_element', $xmlWriter, $element_name, XmlExportEngine::$exportID, $record->ID); |
| 823 | |
| 824 | $xmlWriter->beginElement($element_name_ns, $element_name, null); |
| 825 | $xmlWriter->writeData($data, $element_name); |
| 826 | $xmlWriter->closeElement(); |
| 827 | |
| 828 | $xmlWriter = apply_filters('wp_all_export_add_after_element', $xmlWriter, $element_name, XmlExportEngine::$exportID, $record->ID); |
| 829 | } |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | public static function prepare_child_exports( $export, $is_cron = false ) |
| 834 | { |
| 835 | $queue_exports = array(); |
| 836 | |
| 837 | $exportList = new PMXE_Export_List(); |
| 838 | |
| 839 | global $wpdb; |
| 840 | |
| 841 | $table_prefix = $wpdb->prefix; |
| 842 | $pmxe_prefix = PMXE_Plugin::getInstance()->getTablePrefix(); |
| 843 | |
| 844 | $in_orders = $wpdb->prepare("SELECT DISTINCT post_id FROM {$pmxe_prefix}posts WHERE export_id = %d AND iteration = %d", $export->id, $export->iteration - 1); |
| 845 | |
| 846 | foreach ($exportList->getBy('parent_id', $export->id)->convertRecords() as $child_export) |
| 847 | { |
| 848 | |
| 849 | $whereClause = ""; |
| 850 | |
| 851 | switch ($child_export->export_post_type) |
| 852 | { |
| 853 | case 'product': |
| 854 | |
| 855 | if ( $export->options['order_include_poducts']) |
| 856 | { |
| 857 | $queue_exports[] = $child_export->id; |
| 858 | |
| 859 | if ( ! $export->options['order_include_all_poducts'] ) |
| 860 | { |
| 861 | |
| 862 | $in_products = $wpdb->prepare("SELECT order_item_meta.meta_value as product_id FROM {$table_prefix}posts as posts INNER JOIN {$pmxe_prefix}posts AS order_export ON posts.ID = post_id INNER JOIN {$table_prefix}woocommerce_order_items AS order_items ON posts.ID = order_id INNER JOIN {$table_prefix}woocommerce_order_itemmeta AS order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id WHERE order_export.export_id = %d AND order_export.iteration = %d AND order_items.order_item_type = 'line_item' AND order_item_meta.meta_key = '_product_id' GROUP BY product_id", $export->id, $export->iteration - 1); |
| 863 | |
| 864 | $whereClause = " AND ({$table_prefix}posts.ID IN (". $in_products .") OR {$table_prefix}posts.post_parent IN (". $in_products ."))"; |
| 865 | |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | break; |
| 870 | |
| 871 | case 'shop_coupon': |
| 872 | |
| 873 | if ( $export->options['order_include_coupons']) |
| 874 | { |
| 875 | $queue_exports[] = $child_export->id; |
| 876 | |
| 877 | if ( ! $export->options['order_include_all_coupons'] ) |
| 878 | { |
| 879 | $whereClause = " AND {$table_prefix}posts.post_title IN (". $wpdb->prepare("SELECT order_item_name FROM {$table_prefix}woocommerce_order_items |
| 880 | WHERE {$table_prefix}woocommerce_order_items.order_item_type = %s AND {$table_prefix}woocommerce_order_items.order_id IN (". $in_orders .") GROUP BY order_item_name", 'coupon') .")"; |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | break; |
| 885 | |
| 886 | case 'shop_customer': |
| 887 | |
| 888 | if ( $export->options['order_include_customers']) |
| 889 | { |
| 890 | $queue_exports[] = $child_export->id; |
| 891 | |
| 892 | if ( ! $export->options['order_include_all_customers'] ) |
| 893 | { |
| 894 | $whereClause = " AND {$table_prefix}users.ID IN (" . $wpdb->prepare("SELECT meta_value FROM {$table_prefix}postmeta WHERE meta_key = %s AND post_id IN (". $in_orders .") GROUP BY meta_value", "_customer_user") . ")"; |
| 895 | } |
| 896 | } |
| 897 | |
| 898 | break; |
| 899 | |
| 900 | default: |
| 901 | # code... |
| 902 | break; |
| 903 | } |
| 904 | $child_export_options = $child_export->options; |
| 905 | $child_export_options['whereclause'] = $whereClause; |
| 906 | $child_export->set(array( |
| 907 | 'triggered' => $is_cron ? 1 : 0, |
| 908 | 'processing' => 0, |
| 909 | 'exported' => 0, |
| 910 | 'executing' => $is_cron ? 0 : 1, |
| 911 | 'canceled' => 0, |
| 912 | 'options' => $child_export_options |
| 913 | ))->save(); |
| 914 | } |
| 915 | return $queue_exports; |
| 916 | } |
| 917 | |
| 918 | public function get_fields_options( &$fields, $field_keys = array() ){ |
| 919 | |
| 920 | if ( ! self::$is_active ) return; |
| 921 | |
| 922 | foreach (self::$order_sections as $slug => $section) : |
| 923 | if ( ! empty($section['meta'])): |
| 924 | foreach ($section['meta'] as $cur_meta_key => $field) { |
| 925 | |
| 926 | $field_key = (is_array($field)) ? $field['name'] : $field; |
| 927 | |
| 928 | if ( ! in_array($field_key, $field_keys) ) continue; |
| 929 | |
| 930 | $fields['ids'][] = 1; |
| 931 | $fields['cc_label'][] = (is_array($field)) ? $field['label'] : $cur_meta_key; |
| 932 | $fields['cc_php'][] = ''; |
| 933 | $fields['cc_code'][] = ''; |
| 934 | $fields['cc_sql'][] = ''; |
| 935 | $fields['cc_options'][] = (is_array($field)) ? $field['options'] : $slug; |
| 936 | $fields['cc_type'][] = (is_array($field)) ? $field['type'] : 'woo_order'; |
| 937 | $fields['cc_value'][] = (is_array($field)) ? $field['label'] : $cur_meta_key; |
| 938 | $fields['cc_name'][] = $field_key; |
| 939 | $fields['cc_settings'][] = ''; |
| 940 | } |
| 941 | |
| 942 | endif; |
| 943 | if ( ! empty($section['additional']) ) |
| 944 | { |
| 945 | foreach ($section['additional'] as $sub_slug => $sub_section) |
| 946 | { |
| 947 | foreach ($sub_section['meta'] as $field) { |
| 948 | |
| 949 | $field_key = (is_array($field)) ? $field['name'] : $field; |
| 950 | |
| 951 | if ( ! in_array($field_key, $field_keys) ) continue; |
| 952 | |
| 953 | $fields['ids'][] = 1; |
| 954 | $fields['cc_label'][] = 'item_data__' . ((is_array($field)) ? $field['label'] : $field); |
| 955 | $fields['cc_php'][] = ''; |
| 956 | $fields['cc_code'][] = ''; |
| 957 | $fields['cc_sql'][] = ''; |
| 958 | $fields['cc_options'][] = 'item_data'; |
| 959 | $fields['cc_type'][] = (is_array($field)) ? $field['type'] : $sub_slug; |
| 960 | $fields['cc_value'][] = 'item_data__' . ((is_array($field)) ? $field['label'] : $field); |
| 961 | $fields['cc_name'][] = $field_key; |
| 962 | $fields['cc_settings'][] = ''; |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | endforeach; |
| 967 | |
| 968 | } |
| 969 | |
| 970 | public function render( & $i ){ |
| 971 | |
| 972 | if ( ! self::$is_active ) return; |
| 973 | |
| 974 | foreach (self::$order_sections as $slug => $section) : |
| 975 | if ( ! empty($section['meta']) or ! empty($section['additional']) ): |
| 976 | ?> |
| 977 | <p class="wpae-available-fields-group"><?php echo $section['title']; ?><span class="wpae-expander">+</span></p> |
| 978 | <div class="wpae-custom-field"> |
| 979 | <?php if ( ! in_array($slug, array('order', 'customer', 'cf', 'other'))) : ?> |
| 980 | <div class="wpallexport-free-edition-notice"> |
| 981 | <a class="upgrade_link" target="_blank" href="https://www.wpallimport.com/checkout/?edd_action=add_to_cart&download_id=118611&edd_options%5Bprice_id%5D=1&utm_source=wordpress.org&utm_medium=wooco+orders&utm_campaign=free+wp+all+export+plugin"><?php _e('Upgrade to the Pro edition of WP All Export to Export Order Data','wp_all_export_plugin');?></a> |
| 982 | </div> |
| 983 | <?php endif; ?> |
| 984 | <ul> |
| 985 | <?php if ( ! empty($section['meta']) ): ?> |
| 986 | <li <?php if ( ! in_array($slug, array('order', 'customer', 'cf', 'other'))) : ?>class="wpallexport_disabled"<?php endif; ?>> |
| 987 | <div class="default_column" rel=""> |
| 988 | <label class="wpallexport-element-label"><?php echo __("All", "wp_all_export_plugin") . ' ' . $section['title'] . ' ' . __("Data", "wp_all_export_plugin"); ?></label> |
| 989 | <input type="hidden" name="rules[]" value="pmxe_<?php echo $slug;?>"/> |
| 990 | </div> |
| 991 | </li> |
| 992 | <?php |
| 993 | foreach ($section['meta'] as $cur_meta_key => $field) { |
| 994 | $is_auto_field = ( ! empty($field['auto']) or XmlExportEngine::$is_auto_generate_enabled and 'specific' != $this->post['export_type']); |
| 995 | ?> |
| 996 | <li class="pmxe_<?php echo $slug; ?> <?php if ( ! in_array($slug, array('order', 'customer', 'cf', 'other'))) : ?>wpallexport_disabled<?php endif;?>"> |
| 997 | <div class="custom_column" rel="<?php echo ($i + 1);?>"> |
| 998 | <label class="wpallexport-xml-element"><?php echo (is_array($field)) ? $field['name'] : $field; ?></label> |
| 999 | <input type="hidden" name="ids[]" value="1"/> |
| 1000 | <input type="hidden" name="cc_label[]" value="<?php echo (is_array($field)) ? $field['label'] : $cur_meta_key; ?>"/> |
| 1001 | <input type="hidden" name="cc_php[]" value=""/> |
| 1002 | <input type="hidden" name="cc_code[]" value=""/> |
| 1003 | <input type="hidden" name="cc_sql[]" value=""/> |
| 1004 | <input type="hidden" name="cc_options[]" value="<?php echo (is_array($field)) ? $field['options'] : $slug;?>"/> |
| 1005 | <input type="hidden" name="cc_type[]" value="<?php echo (is_array($field)) ? $field['type'] : 'woo_order'; ?>"/> |
| 1006 | <input type="hidden" name="cc_value[]" value="<?php echo (is_array($field)) ? $field['label'] : $cur_meta_key; ?>"/> |
| 1007 | <input type="hidden" name="cc_name[]" value="<?php echo (is_array($field)) ? $field['name'] : $field;?>"/> |
| 1008 | <input type="hidden" name="cc_settings[]" value=""/> |
| 1009 | </div> |
| 1010 | </li> |
| 1011 | <?php |
| 1012 | $i++; |
| 1013 | } |
| 1014 | endif; |
| 1015 | |
| 1016 | if ( ! empty($section['additional']) ) |
| 1017 | { |
| 1018 | foreach ($section['additional'] as $sub_slug => $sub_section) |
| 1019 | { |
| 1020 | ?> |
| 1021 | <li class="available_sub_section"> |
| 1022 | <p class="wpae-available-fields-group"><?php echo $sub_section['title']; ?><span class="wpae-expander">+</span></p> |
| 1023 | <div class="wpae-custom-field"> |
| 1024 | <ul> |
| 1025 | <li class="wpallexport_disabled"> |
| 1026 | <div class="default_column" rel=""> |
| 1027 | <label class="wpallexport-element-label"><?php echo __("All", "wp_all_export_plugin") . ' ' . $sub_section['title']; ?></label> |
| 1028 | <input type="hidden" name="rules[]" value="pmxe_<?php echo $slug;?>_<?php echo $sub_slug;?>"/> |
| 1029 | </div> |
| 1030 | </li> |
| 1031 | <?php |
| 1032 | foreach ($sub_section['meta'] as $field) { |
| 1033 | ?> |
| 1034 | <li class="pmxe_<?php echo $slug; ?>_<?php echo $sub_slug;?> wpallexport_disabled"> |
| 1035 | <div class="custom_column" rel="<?php echo ($i + 1);?>"> |
| 1036 | <label class="wpallexport-xml-element"><?php echo (is_array($field)) ? $field['name'] : $field; ?></label> |
| 1037 | <input type="hidden" name="ids[]" value="1"/> |
| 1038 | <input type="hidden" name="cc_label[]" value="item_data__<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/> |
| 1039 | <input type="hidden" name="cc_php[]" value=""/> |
| 1040 | <input type="hidden" name="cc_code[]" value=""/> |
| 1041 | <input type="hidden" name="cc_sql[]" value=""/> |
| 1042 | <input type="hidden" name="cc_options[]" value="item_data"/> |
| 1043 | <input type="hidden" name="cc_type[]" value="<?php echo (is_array($field)) ? $field['type'] : $sub_slug; ?>"/> |
| 1044 | <input type="hidden" name="cc_value[]" value="item_data__<?php echo (is_array($field)) ? $field['label'] : $field; ?>"/> |
| 1045 | <input type="hidden" name="cc_name[]" value="<?php echo (is_array($field)) ? $field['name'] : $field;?>"/> |
| 1046 | <input type="hidden" name="cc_settings[]" value=""/> |
| 1047 | </div> |
| 1048 | </li> |
| 1049 | <?php |
| 1050 | $i++; |
| 1051 | } |
| 1052 | ?> |
| 1053 | </ul> |
| 1054 | </li> |
| 1055 | <?php |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | ?> |
| 1060 | </ul> |
| 1061 | </div> |
| 1062 | <?php |
| 1063 | endif; |
| 1064 | endforeach; |
| 1065 | } |
| 1066 | |
| 1067 | public function render_new_field(){ |
| 1068 | |
| 1069 | if ( ! self::$is_active ) return; |
| 1070 | |
| 1071 | ?> |
| 1072 | <select class="wp-all-export-chosen-select" name="column_value_type" style="width:350px;"> |
| 1073 | <?php |
| 1074 | foreach (self::$order_sections as $slug => $section) : //if ( in_array($slug, array('taxes', 'fees', 'items', 'notes', 'refunds'))) continue; |
| 1075 | ?> |
| 1076 | <optgroup label="<?php echo $section['title']; ?>"> |
| 1077 | <?php |
| 1078 | foreach ($section['meta'] as $cur_meta_key => $field) |
| 1079 | { |
| 1080 | $field_label = is_array($field) ? $field['label'] : $cur_meta_key; |
| 1081 | $field_type = is_array($field) ? $field['type'] : 'woo_order'; |
| 1082 | $field_name = is_array($field) ? $field['name'] : $field; |
| 1083 | $field_options = is_array($field) ? $field['options'] : $slug; |
| 1084 | ?> |
| 1085 | <option |
| 1086 | value="<?php echo $field_type;?>" |
| 1087 | label="<?php echo $field_label;?>" |
| 1088 | options="<?php echo $field_options; ?>"><?php echo $field_name;?></option> |
| 1089 | <?php |
| 1090 | } |
| 1091 | ?> |
| 1092 | </optgroup> |
| 1093 | <?php |
| 1094 | if ( ! empty($section['additional']) ) |
| 1095 | { |
| 1096 | foreach ($section['additional'] as $sub_slug => $sub_section) |
| 1097 | { |
| 1098 | ?> |
| 1099 | <optgroup label="<?php echo $sub_section['title']; ?>"> |
| 1100 | |
| 1101 | <?php foreach ($sub_section['meta'] as $field): ?> |
| 1102 | |
| 1103 | <?php |
| 1104 | $field_label = 'item_data__' . ( is_array($field) ? $field['label'] : $field ); |
| 1105 | $field_type = is_array($field) ? $field['type'] : $sub_slug; |
| 1106 | $field_name = is_array($field) ? $field['name'] : $field; |
| 1107 | $field_options = 'item_data'; |
| 1108 | ?> |
| 1109 | <option |
| 1110 | value="<?php echo $field_type;?>" |
| 1111 | label="<?php echo $field_label;?>" |
| 1112 | options="<?php echo $field_options; ?>"><?php echo $field_name;?></option> |
| 1113 | |
| 1114 | <?php endforeach; ?> |
| 1115 | |
| 1116 | </optgroup> |
| 1117 | <?php |
| 1118 | } |
| 1119 | } |
| 1120 | |
| 1121 | endforeach; |
| 1122 | |
| 1123 | // Render Available ACF |
| 1124 | XmlExportEngine::$acf_export->render_new_field(); |
| 1125 | |
| 1126 | ?> |
| 1127 | |
| 1128 | <optgroup label="Advanced"> |
| 1129 | <option value="sql" label="sql"><?php _e("SQL Query", "wp_all_export_plugin"); ?></option> |
| 1130 | </optgroup> |
| 1131 | |
| 1132 | </select> |
| 1133 | <?php |
| 1134 | } |
| 1135 | |
| 1136 | public function render_filters(){ |
| 1137 | |
| 1138 | if ( ! self::$is_active ) return; |
| 1139 | |
| 1140 | foreach (self::$order_sections as $slug => $section) : |
| 1141 | ?> |
| 1142 | <optgroup label="<?php echo $section['title']; ?>"> |
| 1143 | <?php |
| 1144 | foreach ($section['meta'] as $cur_meta_key => $field) |
| 1145 | { |
| 1146 | $field_label = is_array($field) ? $field['label'] : $cur_meta_key; |
| 1147 | $field_type = is_array($field) ? $field['type'] : 'woo_order'; |
| 1148 | $field_name = is_array($field) ? $field['name'] : $field; |
| 1149 | $field_options = is_array($field) ? $field['options'] : $slug; |
| 1150 | |
| 1151 | switch ($field_options) |
| 1152 | { |
| 1153 | case 'order': |
| 1154 | case 'customer': |
| 1155 | if ( strpos($field_label, '_') === 0): |
| 1156 | ?> |
| 1157 | <option value="<?php echo 'cf_' . $field_label; ?>"><?php echo $field_name; ?></option> |
| 1158 | <?php |
| 1159 | else: |
| 1160 | ?> |
| 1161 | <option value="<?php echo $field_label; ?>"><?php echo $field_name; ?></option> |
| 1162 | <?php |
| 1163 | endif; |
| 1164 | break; |
| 1165 | case 'notes': |
| 1166 | case 'items': |
| 1167 | case 'taxes': |
| 1168 | case 'fees': |
| 1169 | case 'refunds': |
| 1170 | break; |
| 1171 | default: |
| 1172 | switch ($field_type) |
| 1173 | { |
| 1174 | case 'cf': |
| 1175 | ?> |
| 1176 | <option value="<?php echo 'cf_' . $field_label; ?>"><?php echo $field_name; ?></option> |
| 1177 | <?php |
| 1178 | break; |
| 1179 | case 'cats': |
| 1180 | case 'attr': |
| 1181 | ?> |
| 1182 | <option value="<?php echo 'tx_' . $field_label; ?>"><?php echo $field_name; ?></option> |
| 1183 | <?php |
| 1184 | break; |
| 1185 | default: |
| 1186 | ?> |
| 1187 | <option value="<?php echo $field_label; ?>"><?php echo $field_name; ?></option> |
| 1188 | <?php |
| 1189 | break; |
| 1190 | } |
| 1191 | break; |
| 1192 | } |
| 1193 | } |
| 1194 | ?> |
| 1195 | </optgroup> |
| 1196 | <?php |
| 1197 | |
| 1198 | endforeach; |
| 1199 | |
| 1200 | } |
| 1201 | |
| 1202 | public function available_sections(){ |
| 1203 | |
| 1204 | $sections = array( |
| 1205 | 'order' => array( |
| 1206 | 'title' => __('Order', 'wp_all_export_plugin'), |
| 1207 | 'meta' => $this->available_order_data() |
| 1208 | ), |
| 1209 | 'customer' => array( |
| 1210 | 'title' => __('Customer', 'wp_all_export_plugin'), |
| 1211 | 'meta' => $this->available_customer_data() |
| 1212 | ), |
| 1213 | 'items' => array( |
| 1214 | 'title' => __('Items', 'wp_all_export_plugin'), |
| 1215 | 'meta' => $this->available_order_default_product_data(), |
| 1216 | 'additional' => $this->available_order_items_data() |
| 1217 | ), |
| 1218 | 'taxes' => array( |
| 1219 | 'title' => __('Taxes & Shipping', 'wp_all_export_plugin'), |
| 1220 | 'meta' => $this->available_order_taxes_data() |
| 1221 | ), |
| 1222 | 'fees' => array( |
| 1223 | 'title' => __('Fees & Discounts', 'wp_all_export_plugin'), |
| 1224 | 'meta' => $this->available_order_fees_data() |
| 1225 | ), |
| 1226 | 'notes' => array( |
| 1227 | 'title' => __('Notes', 'wp_all_export_plugin'), |
| 1228 | 'meta' => array( |
| 1229 | 'comment_content' => __('Note Content', 'wp_all_export_plugin'), |
| 1230 | 'comment_date' => __('Note Date', 'wp_all_export_plugin'), |
| 1231 | 'visibility' => __('Note Visibility', 'wp_all_export_plugin'), |
| 1232 | 'comment_author' => __('Note User Name', 'wp_all_export_plugin'), |
| 1233 | 'comment_author_email' => __('Note User Email', 'wp_all_export_plugin') |
| 1234 | ) |
| 1235 | ), |
| 1236 | 'refunds' => array( |
| 1237 | 'title' => __('Refunds', 'wp_all_export_plugin'), |
| 1238 | 'meta' => array( |
| 1239 | '_refund_total' => __('Refund Total', 'wp_all_export_plugin'), |
| 1240 | 'refund_id' => __('Refund ID', 'wp_all_export_plugin'), |
| 1241 | 'refund_amount' => __('Refund Amounts', 'wp_all_export_plugin'), |
| 1242 | 'refund_reason' => __('Refund Reason', 'wp_all_export_plugin'), |
| 1243 | 'refund_date' => __('Refund Date', 'wp_all_export_plugin'), |
| 1244 | 'refund_author_email' => __('Refund Author Email', 'wp_all_export_plugin') |
| 1245 | ) |
| 1246 | ), |
| 1247 | 'cf' => array( |
| 1248 | 'title' => __('Custom Fields', 'wp_all_export_plugin'), |
| 1249 | 'meta' => array() |
| 1250 | ), |
| 1251 | 'other' => array( |
| 1252 | 'title' => __('Other', 'wp_all_export_plugin'), |
| 1253 | 'meta' => array() |
| 1254 | ) |
| 1255 | ); |
| 1256 | |
| 1257 | return apply_filters('wp_all_export_available_order_sections_filter', $sections); |
| 1258 | |
| 1259 | } |
| 1260 | |
| 1261 | /* |
| 1262 | * Define the keys for orders informations to export |
| 1263 | */ |
| 1264 | public function available_order_data() |
| 1265 | { |
| 1266 | $data = array( |
| 1267 | 'ID' => __('Order ID', 'wp_all_export_plugin'), |
| 1268 | '_order_key' => __('Order Key', 'wp_all_export_plugin'), |
| 1269 | 'post_date' => __('Order Date', 'wp_all_export_plugin'), |
| 1270 | '_completed_date' => __('Completed Date', 'wp_all_export_plugin'), |
| 1271 | 'post_title' => __('Title', 'wp_all_export_plugin'), |
| 1272 | 'post_status' => __('Order Status', 'wp_all_export_plugin'), |
| 1273 | '_order_currency' => __('Order Currency', 'wp_all_export_plugin'), |
| 1274 | '_payment_method_title' => __('Payment Method Title', 'wp_all_export_plugin'), |
| 1275 | '_order_total' => __('Order Total', 'wp_all_export_plugin') |
| 1276 | ); |
| 1277 | |
| 1278 | return apply_filters('wp_all_export_available_order_data_filter', $data); |
| 1279 | } |
| 1280 | |
| 1281 | /* |
| 1282 | * Define the keys for general product informations to export |
| 1283 | */ |
| 1284 | public function available_order_default_product_data() |
| 1285 | { |
| 1286 | |
| 1287 | $data = array( |
| 1288 | '_product_id' => __('Product ID', 'wp_all_export_plugin'), |
| 1289 | '__product_sku' => __('SKU', 'wp_all_export_plugin'), |
| 1290 | '__product_title' => __('Product Name', 'wp_all_export_plugin'), |
| 1291 | '__product_variation' => __('Product Variation Details', 'wp_all_export_plugin'), |
| 1292 | '_qty' => __('Quantity', 'wp_all_export_plugin'), |
| 1293 | '_line_subtotal' => __('Item Cost', 'wp_all_export_plugin'), |
| 1294 | '_line_total' => __('Item Total', 'wp_all_export_plugin'), |
| 1295 | '_line_subtotal_tax' => __('Item Tax', 'wp_all_export_plugin'), |
| 1296 | '_line_tax' => __('Item Tax Total', 'wp_all_export_plugin'), |
| 1297 | '_line_tax_data' => __('Item Tax Data', 'wp_all_export_plugin') |
| 1298 | ); |
| 1299 | |
| 1300 | return apply_filters('wp_all_export_available_order_default_product_data_filter', $data); |
| 1301 | } |
| 1302 | |
| 1303 | public function available_order_items_data() |
| 1304 | { |
| 1305 | |
| 1306 | $data = XmlExportEngine::$woo_export->get_all_fields_for_order_items(); |
| 1307 | |
| 1308 | return apply_filters('wp_all_export_available_order_additional_product_data_filter', $data); |
| 1309 | } |
| 1310 | |
| 1311 | public function available_order_taxes_data(){ |
| 1312 | |
| 1313 | $data = array( |
| 1314 | 'tax_order_item_name' => __('Rate Code (per tax)', 'wp_all_export_plugin'), |
| 1315 | 'tax_rate' => __('Rate Percentage (per tax)', 'wp_all_export_plugin'), |
| 1316 | 'tax_amount' => __('Amount (per tax)', 'wp_all_export_plugin'), |
| 1317 | '_order_tax' => __('Total Tax Amount', 'wp_all_export_plugin'), |
| 1318 | 'shipping_order_item_name' => __('Shipping Method', 'wp_all_export_plugin'), |
| 1319 | '_order_shipping' => __('Shipping Cost', 'wp_all_export_plugin'), |
| 1320 | '_order_shipping_taxes' => __('Shipping Taxes', 'wp_all_export_plugin') |
| 1321 | ); |
| 1322 | |
| 1323 | return apply_filters('wp_all_export_available_order_default_taxes_data_filter', $data); |
| 1324 | } |
| 1325 | |
| 1326 | public function available_order_fees_data(){ |
| 1327 | |
| 1328 | $data = array( |
| 1329 | 'discount_amount' => __('Discount Amount (per coupon)', 'wp_all_export_plugin'), |
| 1330 | '__coupons_used' => __('Coupons Used', 'wp_all_export_plugin'), |
| 1331 | '_cart_discount' => __('Total Discount Amount', 'wp_all_export_plugin'), |
| 1332 | 'fee_line_total' => __('Fee Amount (per surcharge)', 'wp_all_export_plugin'), |
| 1333 | '__total_fee_amount' => __('Total Fee Amount', 'wp_all_export_plugin'), |
| 1334 | '__fee_tax_data' => __('Fee Taxes', 'wp_all_export_plugin'), |
| 1335 | ); |
| 1336 | |
| 1337 | return apply_filters('wp_all_export_available_order_fees_data_filter', $data); |
| 1338 | } |
| 1339 | |
| 1340 | public function available_customer_data() |
| 1341 | { |
| 1342 | |
| 1343 | $main_fields = array( |
| 1344 | '_customer_user' => __('Customer User ID', 'wp_all_export_plugin'), |
| 1345 | 'post_excerpt' => __('Customer Note', 'wp_all_export_plugin') |
| 1346 | ); |
| 1347 | |
| 1348 | $data = array_merge($main_fields, $this->available_billing_information_data(), $this->available_shipping_information_data()); |
| 1349 | |
| 1350 | return apply_filters('wp_all_export_available_user_data_filter', $data); |
| 1351 | |
| 1352 | } |
| 1353 | |
| 1354 | public function available_billing_information_data() |
| 1355 | { |
| 1356 | |
| 1357 | $keys = array( |
| 1358 | '_billing_first_name', '_billing_last_name', '_billing_company', |
| 1359 | '_billing_address_1', '_billing_address_2', '_billing_city', |
| 1360 | '_billing_postcode', '_billing_country', '_billing_state', |
| 1361 | '_billing_email', '_customer_user_email', '_billing_phone' |
| 1362 | ); |
| 1363 | |
| 1364 | $data = $this->generate_friendly_titles($keys, 'billing'); |
| 1365 | |
| 1366 | return apply_filters('wp_all_export_available_billing_information_data_filter', $data); |
| 1367 | |
| 1368 | } |
| 1369 | |
| 1370 | public function available_shipping_information_data() |
| 1371 | { |
| 1372 | |
| 1373 | $keys = array( |
| 1374 | '_shipping_first_name', '_shipping_last_name', '_shipping_company', |
| 1375 | '_shipping_address_1', '_shipping_address_2', '_shipping_city', |
| 1376 | '_shipping_postcode', '_shipping_country', '_shipping_state' |
| 1377 | ); |
| 1378 | |
| 1379 | $data = $this->generate_friendly_titles($keys, 'shipping'); |
| 1380 | |
| 1381 | return apply_filters('wp_all_export_available_shipping_information_data_filter', $data); |
| 1382 | |
| 1383 | } |
| 1384 | |
| 1385 | public function generate_friendly_titles($keys, $keyword = ''){ |
| 1386 | $data = array(); |
| 1387 | foreach ($keys as $key) { |
| 1388 | |
| 1389 | $key1 = $this->fix_titles(str_replace('_', ' ', $key)); |
| 1390 | $key2 = ''; |
| 1391 | |
| 1392 | if(strpos($key1, $keyword)!== false) |
| 1393 | { |
| 1394 | $key1 = str_replace($keyword, '', $key1); |
| 1395 | $key2 = ' ('.__($keyword, 'wp_all_export_plugin').')'; |
| 1396 | } |
| 1397 | |
| 1398 | $data[$key] = __(trim($key1), 'wp_all_export_plugin').$key2; |
| 1399 | |
| 1400 | if ( '_billing_email' == $key ) $data[$key] = __('Billing Email Address', 'wp_all_export_plugin'); |
| 1401 | if ( '_customer_user_email' == $key) $data[$key] = __('Customer Account Email Address', 'wp_all_export_plugin'); |
| 1402 | |
| 1403 | } |
| 1404 | return $data; |
| 1405 | } |
| 1406 | |
| 1407 | public static function prepare_import_template( $exportOptions, &$templateOptions, $element_name, $ID ) |
| 1408 | { |
| 1409 | |
| 1410 | if ( ! self::$is_active ) return; |
| 1411 | |
| 1412 | $options = $exportOptions; |
| 1413 | |
| 1414 | $element_type = $options['cc_value'][$ID]; |
| 1415 | |
| 1416 | $is_xml_template = $options['export_to'] == 'xml'; |
| 1417 | |
| 1418 | $implode_delimiter = XmlExportEngine::$implode; |
| 1419 | |
| 1420 | $billing_keys = array( |
| 1421 | '_billing_first_name', '_billing_last_name', '_billing_company', |
| 1422 | '_billing_address_1', '_billing_address_2', '_billing_city', |
| 1423 | '_billing_postcode', '_billing_country', '_billing_state', |
| 1424 | '_billing_email', '_billing_phone' |
| 1425 | ); |
| 1426 | |
| 1427 | $shipping_keys = array( |
| 1428 | '_shipping_first_name', '_shipping_last_name', '_shipping_company', |
| 1429 | '_shipping_address_1', '_shipping_address_2', '_shipping_city', |
| 1430 | '_shipping_postcode', '_shipping_country', '_shipping_state' |
| 1431 | ); |
| 1432 | |
| 1433 | switch ($element_type) |
| 1434 | { |
| 1435 | case 'ID': |
| 1436 | $templateOptions['unique_key'] = '{'. $element_name .'[1]}'; |
| 1437 | $templateOptions['tmp_unique_key'] = '{'. $element_name .'[1]}'; |
| 1438 | break; |
| 1439 | |
| 1440 | case 'post_title': |
| 1441 | $templateOptions['title'] = '{'. $element_name .'[1]}'; |
| 1442 | $templateOptions['is_update_title'] = 1; |
| 1443 | break; |
| 1444 | |
| 1445 | case 'post_status': |
| 1446 | $templateOptions['is_update_status'] = 1; |
| 1447 | $templateOptions['pmwi_order']['status'] = 'xpath'; |
| 1448 | $templateOptions['pmwi_order']['status_xpath'] = '{'. $element_name .'[1]}'; |
| 1449 | break; |
| 1450 | |
| 1451 | case 'post_date': |
| 1452 | $templateOptions['is_update_dates'] = 1; |
| 1453 | $templateOptions['pmwi_order']['date'] = '{'. $element_name .'[1]}'; |
| 1454 | break; |
| 1455 | |
| 1456 | case '_customer_user_email': |
| 1457 | $templateOptions['pmwi_order']['billing_source_match_by'] = 'email'; |
| 1458 | $templateOptions['pmwi_order']['billing_source_email'] = '{'. $element_name .'[1]}'; |
| 1459 | $templateOptions['pmwi_order']['is_update_billing_details'] = 1; |
| 1460 | $templateOptions['pmwi_order']['is_update_shipping_details'] = 1; |
| 1461 | //$templateOptions['pmwi_order']['guest' . $element_type] = '{'. $element_name .'[1]}'; |
| 1462 | break; |
| 1463 | |
| 1464 | case 'post_excerpt': |
| 1465 | $templateOptions['is_update_excerpt'] = 1; |
| 1466 | $templateOptions['pmwi_order']['customer_provided_note'] = '{'. $element_name .'[1]}'; |
| 1467 | break; |
| 1468 | |
| 1469 | case '_transaction_id': |
| 1470 | $templateOptions['pmwi_order']['transaction_id'] = '{'. $element_name .'[1]}'; |
| 1471 | break; |
| 1472 | |
| 1473 | case '_payment_method': |
| 1474 | $templateOptions['pmwi_order']['payment_method'] = 'xpath'; |
| 1475 | $templateOptions['pmwi_order']['payment_method_xpath'] = '{'. $element_name .'[1]}'; |
| 1476 | $templateOptions['pmwi_order']['is_update_payment'] = 1; |
| 1477 | break; |
| 1478 | |
| 1479 | case '__product_sku': |
| 1480 | $templateOptions['pmwi_order']['is_update_products'] = 1; |
| 1481 | $templateOptions['pmwi_order']['products_repeater_mode'] = $options['export_to']; |
| 1482 | if ($is_xml_template) |
| 1483 | { |
| 1484 | $templateOptions['pmwi_order']['products_repeater_mode_foreach'] = '{OrderItems[1]/Item}'; |
| 1485 | $templateOptions['pmwi_order']['products'][0]['sku'] = '{'. $element_name .'[1]}'; |
| 1486 | } |
| 1487 | else |
| 1488 | { |
| 1489 | $templateOptions['pmwi_order']['products_repeater_mode_separator'] = $implode_delimiter; |
| 1490 | |
| 1491 | if ( $options['order_item_per_row'] or $options['xml_template_type'] == 'custom') { |
| 1492 | $templateOptions['pmwi_order']['products'][0]['sku'] = '{'. $element_name .'[1]}'; |
| 1493 | } |
| 1494 | else{ |
| 1495 | $templateOptions['pmwi_order']['products'][0]['sku'] = '{'. $element_name .'1[1]}'; |
| 1496 | } |
| 1497 | } |
| 1498 | break; |
| 1499 | |
| 1500 | case '_qty': |
| 1501 | |
| 1502 | if ($is_xml_template) |
| 1503 | { |
| 1504 | $templateOptions['pmwi_order']['products'][0]['qty'] = '{'. $element_name .'[1]}'; |
| 1505 | } |
| 1506 | else |
| 1507 | { |
| 1508 | $templateOptions['pmwi_order']['products_repeater_mode_separator'] = $implode_delimiter; |
| 1509 | |
| 1510 | if ( $options['order_item_per_row'] or $options['xml_template_type'] == 'custom') { |
| 1511 | $templateOptions['pmwi_order']['products'][0]['qty'] = '{'. $element_name .'[1]}'; |
| 1512 | } |
| 1513 | else{ |
| 1514 | $templateOptions['pmwi_order']['products'][0]['qty'] = '{'. $element_name .'1[1]}'; |
| 1515 | } |
| 1516 | } |
| 1517 | break; |
| 1518 | |
| 1519 | // prepare template for fee line items |
| 1520 | case 'fee_line_total': |
| 1521 | $templateOptions['pmwi_order']['is_update_fees'] = 1; |
| 1522 | $templateOptions['pmwi_order']['fees_repeater_mode'] = $options['export_to']; |
| 1523 | if ($is_xml_template) |
| 1524 | { |
| 1525 | $templateOptions['pmwi_order']['fees_repeater_mode_foreach'] = '{OrderSurcharge[1]/Surcharge}'; |
| 1526 | $templateOptions['pmwi_order']['fees'][0]['name'] = '{FeeName[1]}'; |
| 1527 | $templateOptions['pmwi_order']['fees'][0]['amount'] = '{'.$element_name.'[1]}'; |
| 1528 | } |
| 1529 | else |
| 1530 | { |
| 1531 | $templateOptions['pmwi_order']['fees_repeater_mode_separator'] = $implode_delimiter; |
| 1532 | $templateOptions['pmwi_order']['fees'][0]['name'] = '{feename[1]}'; |
| 1533 | $templateOptions['pmwi_order']['fees'][0]['amount'] = '{'.$element_name.'[1]}'; |
| 1534 | } |
| 1535 | break; |
| 1536 | |
| 1537 | // prepare template for coupon line items |
| 1538 | case 'discount_amount': |
| 1539 | $templateOptions['pmwi_order']['is_update_coupons'] = 1; |
| 1540 | $templateOptions['pmwi_order']['coupons_repeater_mode'] = $options['export_to']; |
| 1541 | $templateOptions['pmwi_order']['coupons'][0]['amount_tax'] = ''; |
| 1542 | if ($is_xml_template) |
| 1543 | { |
| 1544 | $templateOptions['pmwi_order']['coupons_repeater_mode_foreach'] = '{OrderCoupons[1]/Coupon}'; |
| 1545 | $templateOptions['pmwi_order']['coupons'][0]['code'] = '{CouponCode[1]}'; |
| 1546 | $templateOptions['pmwi_order']['coupons'][0]['amount'] = '[str_replace("-","",{'.$element_name.'[1]})]'; |
| 1547 | } |
| 1548 | else |
| 1549 | { |
| 1550 | $templateOptions['pmwi_order']['coupons_repeater_mode_separator'] = $implode_delimiter; |
| 1551 | $templateOptions['pmwi_order']['coupons'][0]['code'] = '{couponcode[1]}'; |
| 1552 | $templateOptions['pmwi_order']['coupons'][0]['amount'] = '[str_replace("-","",{'.$element_name.'[1]})]'; |
| 1553 | } |
| 1554 | break; |
| 1555 | |
| 1556 | // prepare template for shipping line items |
| 1557 | case 'shipping_order_item_name': |
| 1558 | $templateOptions['pmwi_order']['is_update_shipping'] = 1; |
| 1559 | $templateOptions['pmwi_order']['shipping_repeater_mode'] = $options['export_to']; |
| 1560 | $templateOptions['pmwi_order']['shipping'][0]['name'] = '{'. $element_name.'[1]}'; |
| 1561 | $templateOptions['pmwi_order']['shipping'][0]['class'] = 'xpath'; |
| 1562 | $templateOptions['pmwi_order']['shipping'][0]['class_xpath'] = '{'. $element_name .'[1]}'; |
| 1563 | |
| 1564 | if ($is_xml_template) |
| 1565 | { |
| 1566 | $templateOptions['pmwi_order']['shipping_repeater_mode_foreach'] = '{OrderShipping[1]/Shipping}'; |
| 1567 | } |
| 1568 | else |
| 1569 | { |
| 1570 | $templateOptions['pmwi_order']['shipping_repeater_mode_separator'] = $implode_delimiter; |
| 1571 | } |
| 1572 | break; |
| 1573 | // shipping cost |
| 1574 | case '_order_shipping': |
| 1575 | $templateOptions['pmwi_order']['shipping'][0]['amount'] = '{'. $element_name .'[1]}'; |
| 1576 | break; |
| 1577 | |
| 1578 | // prepare template for tax line items |
| 1579 | case 'tax_order_item_name': |
| 1580 | $templateOptions['pmwi_order']['is_update_taxes'] = 1; |
| 1581 | $templateOptions['pmwi_order']['taxes_repeater_mode'] = $options['export_to']; |
| 1582 | $templateOptions['pmwi_order']['taxes'][0]['shipping_tax_amount'] = ''; |
| 1583 | $templateOptions['pmwi_order']['taxes'][0]['code'] = 'xpath'; |
| 1584 | $templateOptions['pmwi_order']['taxes'][0]['code_xpath'] = '{'. str_replace("pertax", "", $element_name) .'[1]}'; |
| 1585 | |
| 1586 | if ($is_xml_template) |
| 1587 | { |
| 1588 | $templateOptions['pmwi_order']['taxes_repeater_mode_foreach'] = '{OrderTaxes[1]/Tax}'; |
| 1589 | } |
| 1590 | else |
| 1591 | { |
| 1592 | $templateOptions['pmwi_order']['taxes_repeater_mode_separator'] = $implode_delimiter; |
| 1593 | } |
| 1594 | break; |
| 1595 | |
| 1596 | case 'tax_rate': |
| 1597 | $templateOptions['pmwi_order']['taxes'][0]['tax_code'] = 'xpath'; |
| 1598 | $templateOptions['pmwi_order']['taxes'][0]['tax_code_xpath'] = '{ratename[1]}'; |
| 1599 | break; |
| 1600 | |
| 1601 | case 'tax_amount': |
| 1602 | $templateOptions['pmwi_order']['taxes'][0]['tax_amount'] = '{'. str_replace("pertax", "", $element_name).'[1]}'; |
| 1603 | break; |
| 1604 | |
| 1605 | // order notes |
| 1606 | case 'comment_content': |
| 1607 | case 'comment_date': |
| 1608 | $templateOptions['pmwi_order']['is_update_notes'] = 1; |
| 1609 | $templateOptions['pmwi_order']['notes_repeater_mode'] = 'csv'; |
| 1610 | $templateOptions['pmwi_order']['notes_repeater_mode_separator'] = $implode_delimiter; |
| 1611 | $templateOptions['pmwi_order']['notes'][0][str_replace('comment_', '', $element_type)] = '{'. $element_name .'[1]}'; |
| 1612 | break; |
| 1613 | case 'visibility': |
| 1614 | $templateOptions['pmwi_order']['notes'][0]['visibility'] = 'xpath'; |
| 1615 | $templateOptions['pmwi_order']['notes'][0]['visibility_xpath'] = '{'. $element_name .'[1]}'; |
| 1616 | break; |
| 1617 | case 'comment_author': |
| 1618 | $templateOptions['pmwi_order']['notes'][0]['username'] = '{'. $element_name .'[1]}'; |
| 1619 | break; |
| 1620 | case 'comment_author_email': |
| 1621 | $templateOptions['pmwi_order']['notes'][0]['email'] = '{'. $element_name .'[1]}'; |
| 1622 | break; |
| 1623 | // Order Total |
| 1624 | case '_order_total': |
| 1625 | $templateOptions['pmwi_order']['order_total_logic'] = 'manually'; |
| 1626 | $templateOptions['pmwi_order']['order_total_xpath'] = '{'. $element_name .'[1]}'; |
| 1627 | break; |
| 1628 | // Order Refunds |
| 1629 | case 'refund_amount': |
| 1630 | case 'refund_reason': |
| 1631 | case 'refund_date': |
| 1632 | $templateOptions['pmwi_order']['is_update_refunds'] = 1; |
| 1633 | if ($is_xml_template) |
| 1634 | { |
| 1635 | $templateOptions['pmwi_order']['order_' . $element_type] = '{OrderRefunds[1]/Refund/'.$element_name.'[1]}'; |
| 1636 | } |
| 1637 | else |
| 1638 | { |
| 1639 | $templateOptions['pmwi_order']['order_' . $element_type] = '{'. $element_name .'[1]}'; |
| 1640 | } |
| 1641 | break; |
| 1642 | case 'refund_author_email': |
| 1643 | $templateOptions['pmwi_order']['order_refund_issued_email'] = '{'. $element_name .'[1]}'; |
| 1644 | $templateOptions['pmwi_order']['order_refund_issued_match_by'] = 'email'; |
| 1645 | if ($is_xml_template) |
| 1646 | { |
| 1647 | $templateOptions['pmwi_order']['order_refund_issued_email'] = '{OrderRefunds[1]/Refund/'.$element_name.'[1]}'; |
| 1648 | } |
| 1649 | else |
| 1650 | { |
| 1651 | $templateOptions['pmwi_order']['order_refund_issued_email'] = '{'. $element_name .'[1]}'; |
| 1652 | } |
| 1653 | break; |
| 1654 | default: |
| 1655 | if ( in_array($element_type, $billing_keys)){ |
| 1656 | $templateOptions['pmwi_order']['guest' . $element_type] = '{'. $element_name .'[1]}'; |
| 1657 | } |
| 1658 | if ( in_array($element_type, $shipping_keys)){ |
| 1659 | $templateOptions['pmwi_order'][ltrim($element_type, '_')] = '{'. $element_name .'[1]}'; |
| 1660 | } |
| 1661 | break; |
| 1662 | } |
| 1663 | |
| 1664 | } |
| 1665 | |
| 1666 | /** |
| 1667 | * __get function. |
| 1668 | * |
| 1669 | * @access public |
| 1670 | * @param mixed $key |
| 1671 | * @return mixed |
| 1672 | */ |
| 1673 | public function __get( $key ) { |
| 1674 | return $this->get( $key ); |
| 1675 | } |
| 1676 | |
| 1677 | /** |
| 1678 | * Get a session variable |
| 1679 | * |
| 1680 | * @param string $key |
| 1681 | * @param mixed $default used if the session variable isn't set |
| 1682 | * @return mixed value of session variable |
| 1683 | */ |
| 1684 | public function get( $key, $default = null ) { |
| 1685 | return isset( $this->{$key} ) ? $this->{$key} : $default; |
| 1686 | } |
| 1687 | |
| 1688 | } |
| 1689 | } |