Skip to content

Commit

Permalink
v3.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Jun 18, 2024
1 parent 01d78be commit c5ac9ee
Show file tree
Hide file tree
Showing 16 changed files with 734 additions and 408 deletions.
2 changes: 1 addition & 1 deletion cost-of-goods-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Cost of Goods for WooCommerce
Plugin URI: https://wpfactory.com/item/cost-of-goods-for-woocommerce/
Description: Save product purchase costs (cost of goods) in WooCommerce. Beautifully.
Version: 3.4.5
Version: 3.4.6
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: cost-of-goods-for-woocommerce
Expand Down
2 changes: 1 addition & 1 deletion includes/analytics/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wc-currency', 'wp-hooks', 'wp-i18n'), 'version' => '7b6f317d163d5c7b12c941a24e999608');
<?php return array('dependencies' => array('wc-currency', 'wp-hooks', 'wp-i18n'), 'version' => '88284d9f0100029c3f4db1731212c699');
2 changes: 1 addition & 1 deletion includes/analytics/build/index.js

Large diffs are not rendered by default.

127 changes: 127 additions & 0 deletions includes/analytics/class-alg-wc-cog-analytics-customers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php
/**
* Cost of Goods for WooCommerce - Analytics - Orders.
*
* @version 3.4.6
* @since 3.4.6
* @author WPFactory
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
} // Exit if accessed directly

use Automattic\WooCommerce\Utilities\OrderUtil;

if ( ! class_exists( 'Alg_WC_Cost_of_Goods_Analytics_Customers' ) ) :

class Alg_WC_Cost_of_Goods_Analytics_Customers {

/**
* Constructor.
*
* @version 3.4.6
* @since 3.4.6
*/
function __construct() {
// Script localization info.
add_filter( 'alg_wc_cog_analytics_localization_info', array( $this, 'add_analytics_localization_info' ) );

// Costs.
add_filter( 'woocommerce_analytics_clauses_join_customers_subquery', array( $this, 'add_costs_join_customers' ) );
add_filter( 'woocommerce_analytics_clauses_select_customers_subquery', array( $this, 'add_costs_select_orders_stats_total' ) );

// Profit.
add_filter( 'woocommerce_analytics_clauses_join_customers_subquery', array( $this, 'add_profit_join_customers' ) );
add_filter( 'woocommerce_analytics_clauses_select_customers_subquery', array( $this, 'add_profit_select_orders_stats_total' ) );
}

/**
* add_analytics_localization_info.
*
* @version 3.4.6
* @since 3.4.6
*
* @param $info
*
* @return mixed
*/
function add_analytics_localization_info( $info ) {
$info['cost_and_profit_columns_enabled_on_customers'] = 'yes' ===alg_wc_cog_get_option( 'alg_wc_cog_analytics_customers_cost_and_profit_columns', 'no' );
return $info;
}

/**
* add_costs_select_orders_stats_total.
*
* @version 3.4.6
* @since 3.4.6
*
* @param $clauses
*
* @return mixed
*/
function add_costs_select_orders_stats_total( $clauses ) {
if ( 'yes' === alg_wc_cog_get_option( 'alg_wc_cog_analytics_customers_cost_and_profit_columns', 'no' ) ) {
$clauses[] = alg_wc_cog()->core->analytics->orders->get_order_costs_total_meta_select_clauses();
}
return $clauses;
}

/**
* add_costs_join_customers.
*
* @version 3.4.6
* @since 3.4.6
*
* @param $clauses
*
* @return mixed
*/
function add_costs_join_customers( $clauses ) {
if ( 'yes' === alg_wc_cog_get_option( 'alg_wc_cog_analytics_customers_cost_and_profit_columns', 'no' ) ) {
$clauses[] = alg_wc_cog()->core->analytics->orders->get_order_cost_meta_join_clauses();
}

return $clauses;
}

/**
* add_profit_join_customers.
*
* @version 3.4.6
* @since 3.4.6
*
* @param $clauses
*
* @return mixed
*/
function add_profit_join_customers( $clauses ) {
if ( 'yes' === alg_wc_cog_get_option( 'alg_wc_cog_analytics_customers_cost_and_profit_columns', 'no' ) ) {
$clauses[] = alg_wc_cog()->core->analytics->orders->get_order_profit_meta_join_clauses();
}
return $clauses;
}

/**
* add_profit_select_orders_stats_total.
*
* @version 3.4.6
* @since 3.4.6
*
* @param $clauses
*
* @return mixed
*/
function add_profit_select_orders_stats_total( $clauses ) {
if ( 'yes' === alg_wc_cog_get_option( 'alg_wc_cog_analytics_customers_cost_and_profit_columns', 'no' ) ) {
$clauses[] = alg_wc_cog()->core->analytics->orders->get_order_profit_total_meta_select_clauses();
}
return $clauses;
}

}

endif;

return new Alg_WC_Cost_of_Goods_Analytics_Customers();
89 changes: 71 additions & 18 deletions includes/analytics/class-alg-wc-cog-analytics-orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Analytics - Orders.
*
* @version 3.0.2
* @version 3.4.6
* @since 2.4.5
* @author WPFactory
*/
Expand Down Expand Up @@ -167,7 +167,7 @@ function add_costs_total_reports_column_types( $types ) {
/**
* add_costs_select_orders_stats_total.
*
* @version 2.4.8
* @version 3.4.6
* @since 2.4.1
*
* @param $clauses
Expand All @@ -176,14 +176,45 @@ function add_costs_total_reports_column_types( $types ) {
*/
function add_costs_select_orders_stats_total( $clauses ) {
if ( apply_filters( 'alg_wc_cog_analytics_orders_costs_total_validation', false ) ) {
$clauses[] = ', SUM(order_cost_postmeta.meta_value) AS costs_total';
$clauses[] = $this->get_order_costs_total_meta_select_clauses();
}
// If we need to convert the currency
//$clauses[] = ', SUM(order_cost_postmeta.meta_value * COALESCE(NULLIF(REGEXP_REPLACE(REGEXP_SUBSTR(wpo.option_value, CONCAT(\'"\',\'USD\',currency_postmeta.meta_value,\'"\',\';(s|d):.+?:".*?(?=";)\')), CONCAT(\'"\',\'USD\',currency_postmeta.meta_value,\'"\',\';(s|d):.+?:"\'),\'\'),\'\'),1)) as costs_total';

return $clauses;
}

/**
* get_order_costs_total_select_clauses.
*
* @version 3.4.6
* @since 3.4.6
*
* @return string
*/
function get_order_costs_total_meta_select_clauses() {
return ', SUM(order_cost_postmeta.meta_value) AS costs_total';
}

/**
* get_order_cost_meta_join_clauses.
*
* @version 3.4.6
* @since 3.4.6
*
* @return string
*/
function get_order_cost_meta_join_clauses() {
global $wpdb;
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
$clauses = "LEFT JOIN {$wpdb->prefix}wc_orders_meta order_cost_postmeta ON {$wpdb->prefix}wc_order_stats.order_id = order_cost_postmeta.order_id AND order_cost_postmeta.meta_key = '_alg_wc_cog_order_cost'";
} else {
$clauses = "LEFT JOIN {$wpdb->postmeta} order_cost_postmeta ON {$wpdb->prefix}wc_order_stats.order_id = order_cost_postmeta.post_id AND order_cost_postmeta.meta_key = '_alg_wc_cog_order_cost'";
}

return $clauses;
}

/**
* add_costs_total_column_if_option_is_enabled.
*
Expand Down Expand Up @@ -246,7 +277,7 @@ function add_costs_select_orders_subquery( $clauses ) {
/**
* add_costs_join_orders.
*
* @version 3.0.2
* @version 3.4.6
* @since 2.4.1
*
* @param $clauses
Expand All @@ -255,11 +286,7 @@ function add_costs_select_orders_subquery( $clauses ) {
*/
function add_costs_join_orders( $clauses ) {
global $wpdb;
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
$clauses[] = "LEFT JOIN {$wpdb->prefix}wc_orders_meta order_cost_postmeta ON {$wpdb->prefix}wc_order_stats.order_id = order_cost_postmeta.order_id AND order_cost_postmeta.meta_key = '_alg_wc_cog_order_cost'";
} else {
$clauses[] = "LEFT JOIN {$wpdb->postmeta} order_cost_postmeta ON {$wpdb->prefix}wc_order_stats.order_id = order_cost_postmeta.post_id AND order_cost_postmeta.meta_key = '_alg_wc_cog_order_cost'";
}
$clauses[] = $this->get_order_cost_meta_join_clauses();

if ( 'yes' === get_option( 'alg_wc_cog_analytics_orders_individual_costs', 'no' ) ) {
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
Expand Down Expand Up @@ -303,7 +330,7 @@ function add_profit_total_reports_column_types( $types ) {
/**
* add_profit_select_orders_stats_total.
*
* @version 2.4.1
* @version 3.4.6
* @since 2.4.1
*
* @param $clauses
Expand All @@ -312,7 +339,7 @@ function add_profit_total_reports_column_types( $types ) {
*/
function add_profit_select_orders_stats_total( $clauses ) {
if ( apply_filters( 'alg_wc_cog_analytics_orders_profit_total_validation', false ) ) {
$clauses[] = ', SUM(order_profit_postmeta.meta_value) AS profit_total';
$clauses[] = $this->get_order_profit_total_meta_select_clauses();
}

/*if ( 'yes' !== get_option( 'alg_wc_cog_analytics_orders_cost_profit_totals', 'no' ) ) {
Expand Down Expand Up @@ -342,23 +369,49 @@ function add_profit_select_orders_subquery( $clauses ) {
return $clauses;
}

/**
* get_order_costs_total_select_clauses.
*
* @version 3.4.6
* @since 3.4.6
*
* @return string
*/
function get_order_profit_total_meta_select_clauses() {
return ', SUM(order_profit_postmeta.meta_value) AS profit_total';
}

/**
* get_order_cost_meta_join_clauses.
*
* @version 3.4.6
* @since 3.4.6
*
* @return string
*/
function get_order_profit_meta_join_clauses() {
global $wpdb;
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
$clauses = "LEFT JOIN {$wpdb->prefix}wc_orders_meta order_profit_postmeta ON {$wpdb->prefix}wc_order_stats.order_id = order_profit_postmeta.order_id AND order_profit_postmeta.meta_key = '_alg_wc_cog_order_profit'";
} else {
$clauses = "LEFT JOIN {$wpdb->postmeta} order_profit_postmeta ON {$wpdb->prefix}wc_order_stats.order_id = order_profit_postmeta.post_id AND order_profit_postmeta.meta_key = '_alg_wc_cog_order_profit'";
}

return $clauses;
}

/**
* add_profit_join_orders.
*
* @version 3.0.2
* @version 3.4.6
* @since 2.4.1
*
* @param $clauses
*
* @return array
*/
function add_profit_join_orders( $clauses ) {
global $wpdb;
if ( OrderUtil::custom_orders_table_usage_is_enabled() ) {
$clauses[] = "LEFT JOIN {$wpdb->prefix}wc_orders_meta order_profit_postmeta ON {$wpdb->prefix}wc_order_stats.order_id = order_profit_postmeta.order_id AND order_profit_postmeta.meta_key = '_alg_wc_cog_order_profit'";
} else {
$clauses[] = "LEFT JOIN {$wpdb->postmeta} order_profit_postmeta ON {$wpdb->prefix}wc_order_stats.order_id = order_profit_postmeta.post_id AND order_profit_postmeta.meta_key = '_alg_wc_cog_order_profit'";
}
$clauses[] = $this->get_order_profit_meta_join_clauses();

return $clauses;
}
Expand Down
5 changes: 4 additions & 1 deletion includes/analytics/class-alg-wc-cog-analytics.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Alg_WC_Cost_of_Goods_Analytics {
*
* @since 2.9.4
*
* @var mixed Alg_WC_Cost_of_Goods_Analytics_Orders
* @var Alg_WC_Cost_of_Goods_Analytics_Orders
*/
public $orders;

Expand Down Expand Up @@ -46,6 +46,9 @@ function __construct() {

// Analytics > Products.
require_once('class-alg-wc-cog-analytics-categories.php');

// WooCommerce > Customers.
require_once('class-alg-wc-cog-analytics-customers.php');
}

/**
Expand Down
8 changes: 6 additions & 2 deletions includes/analytics/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Analytics.
*
* @version 2.5.5
* @version 3.4.6
* @since 2.4.5
* @author WPFactory
*/
Expand All @@ -24,4 +24,8 @@ products.init();

// Categories.
import categories from './modules/categories';
categories.init();
categories.init();

// Customers.
import customers from './modules/customers';
customers.init();
Loading

0 comments on commit c5ac9ee

Please sign in to comment.