IsImportAllowed.php
2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace Wpae\App\Specification;
class IsImportAllowed
{
public function isSatisfied($item)
{
$is_re_import_allowed = true;
if ( ! empty($item['options']['ids']) )
{
if (in_array('shop_order', $item['options']['cpt']) and class_exists('WooCommerce')) {
$required_fields = array('woo_order' => 'id');
}
else {
$required_fields = array('id' => 'id');
}
// re-import products
if ((in_array('product', $item['options']['cpt']) or $item['options']['export_type'] == 'advanced') and class_exists('WooCommerce') and (empty($item['options']['wp_query_selector']) or $item['options']['wp_query_selector'] == 'wp_query')) {
$required_fields['woo'] = '_sku';
$required_fields['cats'] = 'product_type';
$required_fields['parent'] = 'parent';
}
if ((in_array('users', $item['options']['cpt']) or $item['options']['export_type'] == 'advanced') and (!empty($item['options']['wp_query_selector']) and $item['options']['wp_query_selector'] == 'wp_user_query')) {
$required_fields['user_email'] = 'user_email';
$required_fields['user_login'] = 'user_login';
}
if ($item['options']['export_type'] == 'advanced' and (empty($item['options']['wp_query_selector']) or $item['options']['wp_query_selector'] == 'wp_query')){
$required_fields['post_type'] = 'post_type';
}
$defined_fields = array();
foreach ($item['options']['ids'] as $ID => $value)
{
foreach ($required_fields as $type => $field)
{
if (strtolower($item['options']['cc_type'][$ID]) == $type && strtolower($item['options']['cc_label'][$ID]) == strtolower($field)){
$defined_fields[] = $field;
}
}
}
foreach ($required_fields as $type => $field) {
if ( ! in_array($field, $defined_fields) ){
$is_re_import_allowed = false;
break;
}
}
}
return $is_re_import_allowed;
}
}