Skip to content

Commit

Permalink
v2.9.8
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed May 16, 2023
1 parent 12219af commit ee6fbbf
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 953 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
.github export-ignore
README.md export-ignore
composer.lock export-ignore
# Analytics
includes/analytics/README.md export-ignore
includes/analytics/package.json export-ignore
includes/analytics/package-lock.json export-ignore
includes/analytics/package-lock.json export-ignore
includes/analytics/pnpm-lock.yaml export-ignore
includes/analytics/node_modules/
includes/analytics/webpack.config.js
includes/analytics/.prettierrc.json export-ignore
Expand Down
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.9.7
Version: 2.9.8
Author: WPFactory
Author URI: https://wpfactory.com
Text Domain: cost-of-goods-for-woocommerce
Domain Path: /langs
Copyright: © 2023 WPFactory
WC tested up to: 7.6
WC tested up to: 7.7
License: GNU General Public License v3.0
License URI: http://www.gnu.org/licenses/gpl-3.0.html
*/
Expand Down Expand Up @@ -72,7 +72,7 @@ final class Alg_WC_Cost_of_Goods {
* @var string
* @since 1.0.0
*/
public $version = '2.9.7';
public $version = '2.9.8';

/**
* @var Alg_WC_Cost_of_Goods The single instance of the class
Expand Down
1 change: 1 addition & 0 deletions includes/analytics/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package-lock.json
pnpm-lock.yaml

# Directories/files that may be generated by this project
node_modules/
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' => '54ce6c25bee7b0d37361e394bb420d1e');
<?php return array('dependencies' => array('wc-currency', 'wp-hooks', 'wp-i18n'), 'version' => 'c0714b7b3b4e9ba7bd0dc855ff0ee60a');
859 changes: 1 addition & 858 deletions includes/analytics/build/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion includes/analytics/build/index.js.map

This file was deleted.

30 changes: 24 additions & 6 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 2.4.8
* @version 2.9.8
* @since 2.4.5
* @author WPFactory
*/
Expand Down Expand Up @@ -56,8 +56,6 @@ function __construct() {
add_filter( 'woocommerce_admin_orders_report_export_column_names', array( $this, 'add_profit_columns_names_to_export' ), PHP_INT_MAX, 2 );
add_filter( 'alg_wc_cog_analytics_orders_profit_total_validation', array( $this, 'add_profit_total_column_if_option_is_enabled' ) );



// Test, Debug
// woocommerce_analytics_orders_stats_select_query
// woocommerce_analytics_orders_stats_query_args
Expand All @@ -84,7 +82,7 @@ function __construct() {
/**
* add_analytics_localization_info.
*
* @version 2.4.5
* @version 2.9.8
* @since 2.4.5
*
* @param $info
Expand All @@ -94,6 +92,8 @@ function __construct() {
function add_analytics_localization_info( $info ) {
$info['cost_and_profit_totals_enabled_on_orders'] = 'yes' === get_option( 'alg_wc_cog_analytics_orders_cost_profit_totals', 'no' );
$info['cost_and_profit_columns_enabled_on_orders'] = 'yes' === get_option( 'alg_wc_cog_analytics_orders', 'no' );
$info['individual_order_costs_enabled'] = 'yes' === get_option( 'alg_wc_cog_analytics_orders_individual_costs', 'no' );

return $info;
}

Expand Down Expand Up @@ -169,7 +169,7 @@ function add_profit_total_column_if_option_is_enabled($validation){
/**
* add_costs_select_orders_subquery.
*
* @version 2.4.1
* @version 2.9.8
* @since 2.4.1
*
* @param $clauses
Expand All @@ -180,13 +180,21 @@ function add_costs_select_orders_subquery( $clauses ) {
if ( 'yes' === get_option( 'alg_wc_cog_analytics_orders', 'no' ) ) {
$clauses[] = ', IFNULL(order_cost_postmeta.meta_value, 0) AS order_cost';
}

if ( 'yes' === get_option( 'alg_wc_cog_analytics_orders_individual_costs', 'no' ) ) {
$clauses[] = ', IFNULL(items_cost_pm.meta_value, 0) AS items_cost';
$clauses[] = ', IFNULL(shipping_cost_pm.meta_value, 0) AS shipping_cost';
$clauses[] = ', IFNULL(gateway_cost_pm.meta_value, 0) AS gateway_cost';
$clauses[] = ', IFNULL(extra_cost_per_orders_pm.meta_value, 0) + IFNULL(extra_cost_all_orders_pm.meta_value, 0) + IFNULL(extra_cost_from_meta_pm.meta_value, 0) AS extra_cost';
$clauses[] = ', IFNULL(shipping_classes_cost_pm.meta_value, 0) AS shipping_classes_cost';
}
return $clauses;
}

/**
* add_costs_join_orders.
*
* @version 2.4.1
* @version 2.9.8
* @since 2.4.1
*
* @param $clauses
Expand All @@ -197,6 +205,16 @@ function add_costs_join_orders( $clauses ) {
global $wpdb;
$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'";

if ( 'yes' === get_option( 'alg_wc_cog_analytics_orders_individual_costs', 'no' ) ) {
$clauses[] = "LEFT JOIN {$wpdb->postmeta} items_cost_pm ON {$wpdb->prefix}wc_order_stats.order_id = items_cost_pm.post_id AND items_cost_pm.meta_key = '_alg_wc_cog_order_items_cost'";
$clauses[] = "LEFT JOIN {$wpdb->postmeta} shipping_cost_pm ON {$wpdb->prefix}wc_order_stats.order_id = shipping_cost_pm.post_id AND shipping_cost_pm.meta_key = '_alg_wc_cog_order_shipping_cost'";
$clauses[] = "LEFT JOIN {$wpdb->postmeta} gateway_cost_pm ON {$wpdb->prefix}wc_order_stats.order_id = gateway_cost_pm.post_id AND gateway_cost_pm.meta_key = '_alg_wc_cog_order_gateway_cost'";
$clauses[] = "LEFT JOIN {$wpdb->postmeta} extra_cost_per_orders_pm ON {$wpdb->prefix}wc_order_stats.order_id = extra_cost_per_orders_pm.post_id AND extra_cost_per_orders_pm.meta_key = '_alg_wc_cog_order_extra_cost_per_order'";
$clauses[] = "LEFT JOIN {$wpdb->postmeta} extra_cost_all_orders_pm ON {$wpdb->prefix}wc_order_stats.order_id = extra_cost_all_orders_pm.post_id AND extra_cost_all_orders_pm.meta_key = '_alg_wc_cog_order_extra_cost'";
$clauses[] = "LEFT JOIN {$wpdb->postmeta} extra_cost_from_meta_pm ON {$wpdb->prefix}wc_order_stats.order_id = extra_cost_from_meta_pm.post_id AND extra_cost_from_meta_pm.meta_key = '_alg_wc_cog_order_extra_cost_from_meta'";
$clauses[] = "LEFT JOIN {$wpdb->postmeta} shipping_classes_cost_pm ON {$wpdb->prefix}wc_order_stats.order_id = shipping_classes_cost_pm.post_id AND shipping_classes_cost_pm.meta_key = '_alg_wc_cog_order_shipping_classes_cost'";

}
// If we need to get something fron the options database
//$clauses[] = "JOIN {$wpdb->options} wpo ON option_name LIKE '%alg_wc_cog_currencies_rates%'";
return $clauses;
Expand Down
7 changes: 4 additions & 3 deletions includes/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
"test:unit": "wp-scripts test-unit-js"
},
"devDependencies": {
"@woocommerce/currency": "3.1.0",
"@woocommerce/dependency-extraction-webpack-plugin": "1.4.0",
"@babel/runtime": "7.0.0",
"@woocommerce/currency": "^3.2.1",
"@woocommerce/dependency-extraction-webpack-plugin": "1.6.0",
"@woocommerce/eslint-plugin": "1.1.0",
"@wordpress/scripts": "^12.2.1"
"@wordpress/scripts": "^12.6.1"
}
}
142 changes: 108 additions & 34 deletions includes/analytics/src/modules/orders.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,112 @@ const storeCurrency = CurrencyFactory(wcSettings.currency);
Formatting.setStoreCurrency(storeCurrency);

let orders = {
getHeaders: function (reportTableData) {
const costAndProfitHeaders = [
{
label: __('Cost', 'cost-of-goods-for-woocommerce'),
key: 'order_cost',
isNumeric: true,
//isSortable: true,
},
{
label: __('Profit', 'cost-of-goods-for-woocommerce'),
key: 'order_profit',
isNumeric: true,
//isSortable: true,
},
];
let headers = [...reportTableData.headers, ...costAndProfitHeaders];
if (alg_wc_cog_analytics_obj.individual_order_costs_enabled) {
const individualCostsHeaders = [
{
label: __('Items cost', 'cost-of-goods-for-woocommerce'),
key: 'items_cost',
isNumeric: true,
//isSortable: true,
},
{
label: __('Shipping cost', 'cost-of-goods-for-woocommerce'),
key: 'shipping_cost',
isNumeric: true,
//isSortable: true,
},
{
label: __('Gateway cost', 'cost-of-goods-for-woocommerce'),
key: 'gateway_cost',
isNumeric: true,
//isSortable: true,
},
{
label: __('Extra cost', 'cost-of-goods-for-woocommerce'),
key: 'extra_cost',
isNumeric: true,
//isSortable: true,
},
{
label: __('Shipping classes cost', 'cost-of-goods-for-woocommerce'),
key: 'shipping_classes_cost',
isNumeric: true,
//isSortable: true,
},
];
headers = [...reportTableData.headers, ...individualCostsHeaders, ...costAndProfitHeaders];
}
return headers;
},

getRows:function(reportTableData){
const newRows = reportTableData.rows.map((row, index) => {
const order = reportTableData.items.data[index];
let costAndProfit = [
{
display: storeCurrency.formatAmount(order.order_cost),
value: order.order_cost,
type: 'currency'
},
{
display: storeCurrency.formatAmount(order.order_profit),
value: order.order_profit,
type: 'currency'
},
];
let newRow = [...row,...costAndProfit];
if (alg_wc_cog_analytics_obj.individual_order_costs_enabled) {
let individualCosts = [
{
display: storeCurrency.formatAmount(order.items_cost),
value: order.items_cost,
type: 'currency'
},
{
display: storeCurrency.formatAmount(order.shipping_cost),
value: order.shipping_cost,
type: 'currency'
},
{
display: storeCurrency.formatAmount(order.gateway_cost),
value: order.gateway_cost,
type: 'currency'
},
{
display: storeCurrency.formatAmount(order.extra_cost),
value: order.extra_cost,
type: 'currency'
},
{
display: storeCurrency.formatAmount(order.shipping_classes_cost),
value: order.shipping_classes_cost,
type: 'currency'
},
]
console.log(order)
newRow = [...row,...individualCosts,...costAndProfit];
}
return newRow;
});
return newRows;
},

init: function () {
// Reports table
addFilter(
Expand All @@ -29,38 +135,6 @@ let orders = {
) {
return reportTableData;
}
const newHeaders = [
...reportTableData.headers,
{
label: __('Cost', 'cost-of-goods-for-woocommerce'),
key: 'order_cost',
isNumeric: true,
//isSortable: true,
},
{
label: __('Profit', 'cost-of-goods-for-woocommerce'),
key: 'order_profit',
isNumeric: true,
//isSortable: true,
},
];
const newRows = reportTableData.rows.map((row, index) => {
const order = reportTableData.items.data[index];
const newRow = [
...row,
{
display: storeCurrency.formatAmount(order.order_cost),
value: order.order_cost,
type: 'currency'
},
{
display: storeCurrency.formatAmount(order.order_profit),
value: order.order_profit,
type: 'currency'
},
];
return newRow;
});
const newSummary = [
...reportTableData.summary,
{
Expand All @@ -69,8 +143,8 @@ let orders = {
},
];
reportTableData.summary = newSummary;
reportTableData.headers = newHeaders;
reportTableData.rows = newRows;
reportTableData.headers = this.getHeaders(reportTableData);
reportTableData.rows = this.getRows(reportTableData)//newRows;
return reportTableData;
}
);
Expand Down
13 changes: 11 additions & 2 deletions includes/settings/class-alg-wc-cog-settings-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Cost of Goods for WooCommerce - Tools Section Settings.
*
* @version 2.9.3
* @version 2.9.8
* @since 1.4.0
* @author WPFactory
*/
Expand Down Expand Up @@ -71,7 +71,7 @@ function get_import_tool_cron_info() {
/**
* get_settings.
*
* @version 2.9.3
* @version 2.9.8
* @since 1.4.0
* @todo [later] better descriptions
* @todo [maybe] add "PHP time limit" option, i.e. `set_time_limit()`
Expand Down Expand Up @@ -413,6 +413,15 @@ function get_settings() {
'id' => 'alg_wc_cog_analytics_orders_cost_profit_totals',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => '',
'custom_attributes' => apply_filters( 'alg_wc_cog_settings', array( 'disabled' => 'disabled' ) ),
),
array(
'desc' => __( 'Add columns for individual elements from the costs total', 'cost-of-goods-for-woocommerce' ),
'desc_tip' => __( 'Adds items, shipping, gateway, shipping classes and extra costs.', 'cost-of-goods-for-woocommerce' ),
'id' => 'alg_wc_cog_analytics_orders_individual_costs',
'default' => 'no',
'type' => 'checkbox',
'checkboxgroup' => 'end',
'custom_attributes' => apply_filters( 'alg_wc_cog_settings', array( 'disabled' => 'disabled' ) ),
),
Expand Down
Loading

0 comments on commit ee6fbbf

Please sign in to comment.