Skip to content

Commit

Permalink
v2.5.5
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Apr 18, 2022
1 parent 36fdabb commit ad475ac
Show file tree
Hide file tree
Showing 18 changed files with 510 additions and 787 deletions.
6 changes: 3 additions & 3 deletions cost-of-goods-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
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: 2.5.4
Version: 2.5.5
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: cost-of-goods-for-woocommerce
Domain Path: /langs
Copyright: © 2022 WPFactory
WC tested up to: 6.3
WC tested up to: 6.4
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
Expand Down Expand Up @@ -64,7 +64,7 @@ final class Alg_WC_Cost_of_Goods {
* @since 1.0.0
*/

public $version = '2.5.4';
public $version = '2.5.5';

/**
* @var Alg_WC_Cost_of_Goods The single instance of the class
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' => '788d1a21f794f9834f9046d4d5b938c9');
<?php return array('dependencies' => array('wc-currency', 'wp-hooks', 'wp-i18n'), 'version' => 'ea283f2cd9aa815da8c265d9e059f11d');
675 changes: 1 addition & 674 deletions includes/analytics/build/index.js

Large diffs are not rendered by default.

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

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

if ( ! class_exists( 'Alg_WC_Cost_of_Goods_Analytics_Categories' ) ) :

class Alg_WC_Cost_of_Goods_Analytics_Categories {

/**
* Constructor.
*
* @version 2.5.5
* @since 2.5.5
*
*/
function __construct() {
// Costs
add_filter( 'woocommerce_analytics_clauses_join_categories_subquery', array( $this, 'add_costs_to_categories_join_clauses' ) );
add_filter( 'woocommerce_analytics_clauses_select_categories_subquery', array( $this, 'add_costs_to_select_categories_subquery' ) );
add_filter( 'alg_wc_cog_analytics_product_cost_totals', array( $this, 'change_product_clause_based_on_categories_totals_option' ) );
add_filter( 'alg_wc_cog_analytics_product_cost_select', array( $this, 'change_product_clause_based_on_categories_columns_option' ) );
add_filter( 'alg_wc_cog_analytics_product_cost_select_subquery', array( $this, 'change_product_clause_based_on_categories_columns_option' ) );
// Profit
add_filter( 'woocommerce_analytics_clauses_select_categories_subquery', array( $this, 'add_profit_to_select_categories_subquery' ) );
add_filter( 'alg_wc_cog_analytics_product_profit_totals', array( $this, 'change_product_clause_based_on_categories_totals_option' ) );
add_filter( 'alg_wc_cog_analytics_product_cost_join', array( $this, 'change_product_clause_based_on_categories_totals_option' ) );
add_filter( 'alg_wc_cog_analytics_product_profit_select', array( $this, 'change_product_clause_based_on_categories_columns_option' ) );
add_filter( 'alg_wc_cog_analytics_product_profit_subquery', array( $this, 'change_product_clause_based_on_categories_columns_option' ) );
// Script localization info.
add_filter( 'alg_wc_cog_analytics_localization_info', array( $this, 'add_analytics_localization_info' ) );
}

/**
* change_product_clause_based_on_categories_totals_option.
*
* @version 2.5.5
* @since 2.5.5
*
* @param $enabled
*
* @return bool
*/
function change_product_clause_based_on_categories_totals_option( $enabled ) {
$enabled = 'yes' === get_option( 'alg_wc_cog_cost_and_profit_totals_on_categories_tab', 'no' ) ? true : $enabled;
return $enabled;
}

/**
* change_product_clause_based_on_categories_columns_option.
*
* @version 2.5.5
* @since 2.5.5
*
* @param $enabled
*
* @return bool
*/
function change_product_clause_based_on_categories_columns_option( $enabled ) {
$enabled = 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_categories_tab', 'no' ) ? true : $enabled;
return $enabled;
}

/**
* add_costs_to_categories_join_clauses.
*
* @version 2.5.5
* @since 2.5.5
*
* @param $clauses
*
* @return array
*/
function add_costs_to_categories_join_clauses( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_categories_tab', 'no' ) ) {
global $wpdb;
$clauses[] = "LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta alg_cog_oimc ON {$wpdb->prefix}wc_order_product_lookup.order_item_id = alg_cog_oimc.order_item_id AND alg_cog_oimc.meta_key = '_alg_wc_cog_item_cost'";
}
return $clauses;
}

/**
* add_costs_to_select_categories_subquery.
*
* @version 2.5.5
* @since 2.5.5
*
* @param $clauses
*
* @return array
*/
function add_costs_to_select_categories_subquery( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_categories_tab', 'no' ) ) {
$clauses[] = ', SUM(IFNULL(alg_cog_oimc.meta_value * product_qty, 0)) AS cost';
}
return $clauses;
}

/**
* add_profit_to_select_categories_subquery.
*
* @version 2.5.5
* @since 2.5.5
*
* @param $clauses
*
* @return array
*/
function add_profit_to_select_categories_subquery( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_categories_tab', 'no' ) ) {
global $wpdb;
$clauses[] = ", IFNULL((SUM({$wpdb->prefix}wc_order_product_lookup.product_net_revenue) - SUM(alg_cog_oimc.meta_value * product_qty)), 0) AS profit";
}
return $clauses;
}

/**
* add_analytics_localization_info.
*
* @version 2.5.5
* @since 2.5.5
*
* @param $info
*
* @return mixed
*/
function add_analytics_localization_info( $info ) {
$info['cost_and_profit_totals_enabled_on_categories'] = 'yes' === get_option( 'alg_wc_cog_cost_and_profit_totals_on_categories_tab', 'no' );
$info['cost_and_profit_columns_enabled_on_categories'] = 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_categories_tab', 'no' );
return $info;
}


}

endif;

return new Alg_WC_Cost_of_Goods_Analytics_Categories();
43 changes: 21 additions & 22 deletions includes/analytics/class-alg-wc-cog-analytics-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Analytics - Products.
*
* @version 2.5.1
* @version 2.5.5
* @since 2.5.1
* @author WPFactory
*/
Expand Down Expand Up @@ -43,34 +43,33 @@ function __construct() {
/**
* add_costs_total_to_select_products_stats_total.
*
* @version 2.5.1
* @version 2.5.5
* @since 2.5.1
*
* @param $clauses
*
* @return array
*/
function add_costs_total_to_select_products_stats_total( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_totals_on_products_tab', 'no' ) ) {
$clauses[] = ', SUM(alg_cog_oimc.meta_value) AS costs_total';
if ( apply_filters( 'alg_wc_cog_analytics_product_cost_totals', 'yes' === get_option( 'alg_wc_cog_cost_and_profit_totals_on_products_tab', 'no' ) ) ) {
$clauses[] = ', SUM(alg_cog_oimc.meta_value * product_qty) AS costs_total';
}
return $clauses;
}

/**
* add_profit_total_to_select_products_stats_total.
*
* @version 2.5.1
* @version 2.5.5
* @since 2.5.1
*
* @param $clauses
*
* @return array
*/
function add_profit_total_to_select_products_stats_total( $clauses ) {
global $wpdb;
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_totals_on_products_tab', 'no' ) ) {
$clauses[] = ", SUM(IFNULL({$wpdb->prefix}wc_order_product_lookup.product_net_revenue - alg_cog_oimc.meta_value, 0)) AS profit_total";
if ( apply_filters( 'alg_wc_cog_analytics_product_profit_totals', 'yes' === get_option( 'alg_wc_cog_cost_and_profit_totals_on_products_tab', 'no' ) ) ) {
$clauses[] = ", SUM(wp_wc_order_product_lookup.product_net_revenue - alg_cog_oimc.meta_value * product_qty) AS profit_total";
}
return $clauses;
}
Expand All @@ -86,7 +85,7 @@ function add_profit_total_to_select_products_stats_total( $clauses ) {
* @return array
*/
function add_profit_to_select_products( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) {
if ( apply_filters( 'alg_wc_cog_analytics_product_profit_select', 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) ) {
$clauses[] = ', profit';
}
return $clauses;
Expand All @@ -95,33 +94,33 @@ function add_profit_to_select_products( $clauses ) {
/**
* add_profit_to_select_products_subquery.
*
* @version 2.5.1
* @version 2.5.5
* @since 2.5.1
*
* @param $clauses
*
* @return array
*/
function add_profit_to_select_products_subquery( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) {
if ( apply_filters( 'alg_wc_cog_analytics_product_profit_subquery', 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) ) {
global $wpdb;
$clauses[] = ", SUM(IFNULL({$wpdb->prefix}wc_order_product_lookup.product_net_revenue - alg_cog_oimc.meta_value, 0)) AS profit";
$clauses[] = ", IFNULL((SUM({$wpdb->prefix}wc_order_product_lookup.product_net_revenue) - SUM(alg_cog_oimc.meta_value * product_qty)), 0) AS profit";
}
return $clauses;
}

/**
* add_costs_to_join_products.
*
* @version 2.5.1
* @version 2.5.5
* @since 2.5.1
*
* @param $clauses
*
* @return array
*/
function add_costs_to_join_products( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) {
if ( apply_filters( 'alg_wc_cog_analytics_product_cost_join', 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) ) {
global $wpdb;
$clauses[] = "LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta alg_cog_oimc ON {$wpdb->prefix}wc_order_product_lookup.order_item_id = alg_cog_oimc.order_item_id AND alg_cog_oimc.meta_key = '_alg_wc_cog_item_cost'";
}
Expand All @@ -131,32 +130,32 @@ function add_costs_to_join_products( $clauses ) {
/**
* add_costs_to_select_products_subquery.
*
* @version 2.5.1
* @version 2.5.5
* @since 2.5.1
*
* @param $clauses
*
* @return array
*/
function add_costs_to_select_products_subquery( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) {
$clauses[] = ', SUM(IFNULL(alg_cog_oimc.meta_value, 0)) AS cost';
if ( apply_filters( 'alg_wc_cog_analytics_product_cost_select_subquery', 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) ) {
$clauses[] = ', SUM(IFNULL(alg_cog_oimc.meta_value * product_qty, 0)) AS cost';
}
return $clauses;
}

/**
* add_costs_to_select_products.
*
* @version 2.5.1
* @version 2.5.5
* @since 2.5.1
*
* @param $clauses
*
* @return array
*/
function add_costs_to_select_products( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) {
if ( apply_filters( 'alg_wc_cog_analytics_product_cost_select', 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' ) ) ) {
$clauses[] = ', cost';
}
return $clauses;
Expand All @@ -165,16 +164,16 @@ function add_costs_to_select_products( $clauses ) {
/**
* add_analytics_localization_info.
*
* @version 2.5.1
* @version 2.5.5
* @since 2.5.1
*
* @param $info
*
* @return mixed
*/
function add_analytics_localization_info( $info ) {
$info['cost_and_profit_totals_enabled_on_products'] = 'yes' === get_option( 'alg_wc_cog_cost_and_profit_totals_on_products_tab', 'no' );
$info['cost_and_profit_columns_enabled_on_products'] = 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' );
$info['product_cost_and_profit_totals_enabled'] = 'yes' === get_option( 'alg_wc_cog_cost_and_profit_totals_on_products_tab', 'no' );
$info['product_cost_and_profit_columns_enabled'] = 'yes' === get_option( 'alg_wc_cog_cost_and_profit_column_on_products_tab', 'no' );
return $info;
}

Expand Down
Loading

0 comments on commit ad475ac

Please sign in to comment.