コード例 #1
0
function sm_array_recursive_diff($array1, $array2)
{
    $array_diff = array();
    foreach ($array1 as $key => $value) {
        if (array_key_exists($key, $array2)) {
            if (is_array($value)) {
                $recursive_diff = sm_array_recursive_diff($value, $array2[$key]);
                if (count($recursive_diff)) {
                    $array_diff[$key] = $recursive_diff;
                }
            } else {
                if ($value != $array2[$key]) {
                    $array_diff[$key] = $value;
                }
            }
        } else {
            $array_diff[$key] = $value;
        }
    }
    return $array_diff;
}
コード例 #2
0
 public function products_dashboard_model($dashboard_model)
 {
     global $wpdb;
     $visible_columns = array('ID', 'post_title', '_sku', '_regular_price', '_sale_price', '_sale_price_dates_from', '_sale_price_dates_to', '_stock', 'post_status', 'post_content', 'product_cat', 'product_attributes', '_length', '_width', '_height', '_visibility', '_tax_status', 'product_type');
     $column_model =& $dashboard_model[$this->dashboard_key]['columns'];
     $dashboard_model[$this->dashboard_key]['tables']['posts']['where']['post_type'] = array('product', 'product_variation');
     $dashboard_model[$this->dashboard_key]['treegrid'] = true;
     //for setting the treegrid
     $attr_col_index = sm_multidimesional_array_search('custom/product_attributes', 'src', $column_model);
     $attributes_val = array();
     $attributes_label = array();
     if (empty($attr_col_index)) {
         //Query to get the attribute name
         $query_attribute_label = "SELECT attribute_name, attribute_label, attribute_type\n\t\t                                FROM {$wpdb->prefix}woocommerce_attribute_taxonomies";
         $results_attribute_label = $wpdb->get_results($query_attribute_label, 'ARRAY_A');
         $attribute_label_count = $wpdb->num_rows;
         if ($attribute_label_count > 0) {
             foreach ($results_attribute_label as $results_attribute_label1) {
                 $attributes_label['pa_' . $results_attribute_label1['attribute_name']]['lbl'] = $results_attribute_label1['attribute_label'];
                 $attributes_label['pa_' . $results_attribute_label1['attribute_name']]['type'] = $results_attribute_label1['attribute_type'];
             }
         }
     }
     foreach ($column_model as $key => &$column) {
         if (empty($column['src'])) {
             continue;
         }
         $src_exploded = explode("/", $column['src']);
         if (empty($src_exploded)) {
             $src = $column['src'];
         }
         if (sizeof($src_exploded) > 2) {
             $cond = explode("=", $src_exploded[1]);
             if (sizeof($cond) == 2) {
                 $src = $cond[1];
             }
         } else {
             $src = $src_exploded[1];
         }
         //Code for unsetting the position for hidden columns
         if (!empty($column['position'])) {
             unset($column['position']);
         }
         $position = array_search($src, $visible_columns);
         if ($position !== false) {
             $column['position'] = $position;
             $column['hidden'] = false;
         } else {
             $column['hidden'] = true;
         }
         // key:true
         if (!empty($src)) {
             if (substr($src, 0, 3) == 'pa_') {
                 $attributes_val[$src] = array();
                 $attributes_val[$src]['lbl'] = !empty($attributes_label[$src]['lbl']) ? $attributes_label[$src]['lbl'] : $src;
                 $attributes_val[$src]['val'] = $column['values'];
                 $attributes_val[$src]['type'] = !empty($attributes_label[$src]['type']) ? $attributes_label[$src]['type'] : $src;
                 unset($column_model[$key]);
             } else {
                 if ($src == 'product_cat') {
                     $column['type'] = 'multilist';
                     $column['editable'] = false;
                 } else {
                     if ($src == 'ID') {
                         $column['key'] = true;
                         //for tree grid
                     } else {
                         if ($src == '_sale_price_dates_from' || $src == '_sale_price_dates_to') {
                             $column['type'] = 'datetime';
                         } else {
                             if ($src == '_visibility') {
                                 $column['values'] = array('visible' => __('Catalog & Search', Smart_Manager::$text_domain), 'catalog' => __('Catalog', Smart_Manager::$text_domain), 'search' => __('Search', Smart_Manager::$text_domain), 'hidden' => __('Hidden', Smart_Manager::$text_domain));
                             } else {
                                 if ($src == '_tax_status') {
                                     $column['values'] = array('taxable' => __('Taxable', Smart_Manager::$text_domain), 'shipping' => __('Shipping only', Smart_Manager::$text_domain), 'none' => __('None', Smart_Manager::$text_domain));
                                 } else {
                                     if ($src == '_stock_status') {
                                         $column['values'] = array('instock' => __('In stock', Smart_Manager::$text_domain), 'outofstock' => __('Out of stock', Smart_Manager::$text_domain));
                                     } else {
                                         if ($src == '_tax_class') {
                                             $column['values'] = array('' => __('Standard', Smart_Manager::$text_domain), 'reduced-rate' => __('Reduced Rate', Smart_Manager::$text_domain), 'zero-rate' => __('Zero Rate', Smart_Manager::$text_domain));
                                         } else {
                                             if ($src == '_backorders') {
                                                 $column['values'] = array('no' => __('Do Not Allow', Smart_Manager::$text_domain), 'notify' => __('Allow, but notify customer', Smart_Manager::$text_domain), 'yes' => __('Allow', Smart_Manager::$text_domain));
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if (empty($attr_col_index)) {
         $index = sizeof($column_model);
         //Code for including custom columns for product dashboard
         $column_model[$index] = array();
         $column_model[$index]['src'] = 'custom/product_attributes';
         $column_model[$index]['index'] = sanitize_title(str_replace('/', '_', $column_model[$index]['src']));
         // generate slug using the wordpress function if not given
         $column_model[$index]['name'] = __(ucwords(str_replace('_', ' ', 'attributes')), Smart_Manager::$text_domain);
         $column_model[$index]['type'] = 'serialized';
         $column_model[$index]['hidden'] = true;
         $column_model[$index]['editable'] = false;
         $column_model[$index]['width'] = 100;
         $position = array_search('product_attributes', $visible_columns);
         if ($position !== false) {
             $column_model[$index]['position'] = $position;
             $column_model[$index]['hidden'] = false;
         } else {
             $column_model[$index]['hidden'] = true;
         }
         //Code for assigning attr. values
         $column_model[$index]['values'] = $attributes_val;
     }
     // Load from cache
     $dashboard_model_saved = get_transient('sm_dashboard_model_' . $this->dashboard_key);
     if (!empty($dashboard_model_saved)) {
         $col_model_diff = sm_array_recursive_diff($dashboard_model_saved, $dashboard_model);
     }
     //clearing the transients before return
     if (!empty($col_model_diff)) {
         delete_transient('sm_dashboard_model_' . $this->dashboard_key);
     }
     return $dashboard_model;
 }