function eStoreMyInArray($array, $value, $key) { //loop through the array foreach ($array as $val) { //if $val is an array cal myInArray again with $val as array input if (is_array($val)) { if (eStoreMyInArray($val, $value, $key)) { return true; } } else { if ($array[$key] == $value) { return true; } } } return false; }
function eStore_load_customers_data_into_array_between_dates($start_date, $end_date) { global $wpdb, $wp_eStore_config; global $customer_table_name; $eStore_customers_data = array(); $resultset = $wpdb->get_results("SELECT * FROM {$customer_table_name} WHERE date BETWEEN '{$start_date}' AND '{$end_date}'", OBJECT); foreach ($resultset as $row) { $individual_customer_data = array('id' => $row->id, 'first_name' => $row->first_name, 'last_name' => $row->last_name, 'email_address' => $row->email_address, 'purchased_product_id' => $row->purchased_product_id, 'txn_id' => $row->txn_id, 'date' => $row->date, 'sale_amount' => $row->sale_amount, 'coupon_code_used' => $row->coupon_code_used, 'purchase_qty' => $row->purchase_qty, 'ipaddress' => $row->ipaddress, 'product_name' => $row->product_name); array_push($eStore_customers_data, $individual_customer_data); } $wp_eStore_config->setValue('eStore_customers_data_between_dates', $eStore_customers_data); $eStore_customers_data_unique_txn = eStore_remove_duplicate_array_value_based_on_key($eStore_customers_data, 'txn_id'); $wp_eStore_config->setValue('eStore_customers_data_between_dates_unique_txns', $eStore_customers_data_unique_txn); //purchase amount by date value $item_purchase_stats_by_date = array(); foreach ($eStore_customers_data as $row) { $current_row_index_value = $row['date']; $sale_amt = $row['sale_amount']; $purchase_qty = $row['purchase_qty']; if ($sale_amt < 0) { continue; } //Tally up the array based on date $value = $row['date']; $key = "date"; if (!eStoreMyInArray($item_purchase_stats_by_date, $value, $key)) { if (!empty($sale_amt)) { if (empty($purchase_qty)) { $purchase_qty = 1; } // Add the new sale item by date in the array $item_details = array('date' => $current_row_index_value, 'qty_sold' => $purchase_qty, 'sale_total' => $sale_amt); array_push($item_purchase_stats_by_date, $item_details); } } else { //Add the qty_sold and sale amount for this date foreach ($item_purchase_stats_by_date as $key => $item) { if ($item['date'] == $current_row_index_value) { $item['qty_sold'] = $item['qty_sold'] + $purchase_qty; $item['sale_total'] = $item['sale_total'] + $sale_amt; unset($item_purchase_stats_by_date[$key]); array_push($item_purchase_stats_by_date, $item); } } } } $wp_eStore_config->setValue('eStore_purchase_by_date_data_between_dates', $item_purchase_stats_by_date); $wp_eStore_config->saveConfig(); }