Skip to content

Commit

Permalink
Merge branch 'main' into PRESS4-502
Browse files Browse the repository at this point in the history
* main:
  `use function WP_Forge\Helpers\dataGet;` Fix #61
  Require `wp-forge/helpers`
  fixing linting issues
  passing only the array keys instead of entire values
  delete useless autogen comment
  Linting/spacing
  Add `server_path` to `get_core_data()` using `ABSPATH`
  Add WP_Mock for tests
  • Loading branch information
circlecube committed Mar 13, 2024
2 parents b3a0f2c + e5b234c commit 0563923
Show file tree
Hide file tree
Showing 9 changed files with 2,810 additions and 435 deletions.
10 changes: 9 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"bootstrap.php"
]
},
"autoload-dev": {
"psr-4": {
"NewfoldLabs\\WP\\Module\\Data\\": "tests/phpunit/includes/"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
Expand All @@ -44,11 +49,14 @@
"lint": "Check files against coding standards."
},
"require": {
"wp-forge/wp-upgrade-handler": "^1.0",
"newfold-labs/wp-module-loader": "^1.0",
"wp-forge/helpers": "^2.0",
"wp-forge/wp-query-builder": "^1.0",
"wp-forge/wp-upgrade-handler": "^1.0",
"wpscholar/url": "^1.2"
},
"require-dev": {
"10up/wp_mock": "^0.4.2",
"newfold-labs/wp-php-standards": "^1.2"
}
}
2,911 changes: 2,572 additions & 339 deletions composer.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion includes/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace NewfoldLabs\WP\Module\Data;

use wpscholar\Url;
use function WP_Forge\Helpers\dataGet;

/**
* Main class for the data plugin module
Expand Down Expand Up @@ -128,7 +129,7 @@ public function authenticate( $status ) {
'method' => $_SERVER['REQUEST_METHOD'],
'url' => Url::getCurrentUrl(),
'body' => file_get_contents( 'php://input' ),
'timestamp' => data_get( getallheaders(), 'X-Timestamp' ),
'timestamp' => dataGet( getallheaders(), 'X-Timestamp' ),
);

$hash = hash( 'sha256', wp_json_encode( $data ) );
Expand Down
5 changes: 3 additions & 2 deletions includes/HiiveConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ public function get_core_data() {
$data = array(
'brand' => sanitize_title( $container->plugin()->brand ),
'cache_level' => intval( get_option( 'newfold_cache_level', 2 ) ),
'cloudflare' => get_option( 'newfold_cloudflare_enabled', false ),
'data' => NFD_DATA_MODULE_VERSION,
'cloudflare' => get_option( 'newfold_cloudflare_enabled', false ),
'data' => defined( 'NFD_DATA_MODULE_VERSION' ) ? constant( 'NFD_DATA_MODULE_VERSION' ) : '0.0',
'email' => get_option( 'admin_email' ),
'hostname' => gethostname(),
'mysql' => $wpdb->db_version(),
Expand All @@ -279,6 +279,7 @@ public function get_core_data() {
'url' => get_site_url(),
'username' => get_current_user(),
'wp' => $wp_version,
'server_path' => defined( 'ABSPATH' ) ? constant( 'ABSPATH' ) : '',
);

return apply_filters( 'newfold_wp_data_module_core_data_filter', $data );
Expand Down
184 changes: 92 additions & 92 deletions includes/Listeners/Commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ public function register_hooks() {
add_action( 'woocommerce_order_status_processing', array( $this, 'on_payment' ), 10, 2 );
add_filter( 'newfold_wp_data_module_cron_data_filter', array( $this, 'products_count' ) );
add_filter( 'newfold_wp_data_module_cron_data_filter', array( $this, 'orders_count' ) );
add_filter('woocommerce_before_cart', array( $this, 'site_cart_views'));
add_filter('woocommerce_before_checkout_form', array( $this, 'checkout_views'));
add_filter('woocommerce_thankyou', array( $this, 'thank_you_page'));
add_filter( 'woocommerce_before_cart', array( $this, 'site_cart_views' ) );
add_filter( 'woocommerce_before_checkout_form', array( $this, 'checkout_views' ) );
add_filter( 'woocommerce_thankyou', array( $this, 'thank_you_page' ) );
add_filter( 'pre_update_option_nfd_ecommerce_captive_flow_razorpay', array( $this, 'razorpay_connection' ), 10, 2 );
add_filter( 'pre_update_option_nfd_ecommerce_captive_flow_shippo', array( $this, 'shippo_connection' ), 10, 2 );
add_filter( 'pre_update_option_nfd_ecommerce_captive_flow_stripe', array( $this, 'stripe_connection' ), 10, 2 );
// Paypal Connection
add_filter( 'pre_update_option_yith_ppwc_merchant_data_production', array( $this, 'paypal_connection' ), 10, 2 );
add_filter('update_option_ewc4wp_sso_account_status', array($this, 'ecomdash_connected'));
add_filter( 'update_option_ewc4wp_sso_account_status', array( $this, 'ecomdash_connected' ) );
add_filter( 'woocommerce_update_product', array( $this, 'product_created_or_updated' ), 100, 2 );
add_action('update_option_woocommerce_custom_orders_table_enabled', array($this, 'woocommerce_hpos_enabled'), 10, 3 );
add_action( 'update_option_woocommerce_custom_orders_table_enabled', array( $this, 'woocommerce_hpos_enabled' ), 10, 3 );
}

/**
* On Payment, send data to Hiive
*
* @param int $order_id
* @param \WC_Order $order
* @param int $order_id
* @param \WC_Order $order
*
* @return void
*/
Expand All @@ -47,13 +47,12 @@ public function on_payment( $order_id, \WC_Order $order ) {
);

$this->push( 'woocommerce_order_status_processing', $data );

}

/**
* Products Count
*
* @param string $data Array of data to be sent to Hiive
* @param string $data Array of data to be sent to Hiive
*
* @return string Array of data
*/
Expand All @@ -71,7 +70,7 @@ public function products_count( $data ) {
/**
* Orders Count
*
* @param string $data Array of data to be sent to Hiive
* @param string $data Array of data to be sent to Hiive
*
* @return string Array of data
*/
Expand All @@ -92,17 +91,17 @@ public function orders_count( $data ) {
* @return void
*/
public function site_cart_views() {
if( WC()->cart->get_cart_contents_count() !== 0){
$data = array(
"product_count" => WC()->cart->get_cart_contents_count(),
"cart_total" => floatval(WC()->cart->get_cart_contents_total()),
"currency" => get_woocommerce_currency(),
);
if ( WC()->cart->get_cart_contents_count() !== 0 ) {
$data = array(
'product_count' => WC()->cart->get_cart_contents_count(),
'cart_total' => floatval( WC()->cart->get_cart_contents_total() ),
'currency' => get_woocommerce_currency(),
);

$this->push(
"site_cart_view",
$data
);
$this->push(
'site_cart_view',
$data
);
}
}

Expand All @@ -114,41 +113,41 @@ public function site_cart_views() {
*/
public function checkout_views() {
$data = array(
"product_count" => WC()->cart->get_cart_contents_count(),
"cart_total" => floatval(WC()->cart->get_cart_contents_total()),
"currency" => get_woocommerce_currency(),
"payment_method" => WC()->payment_gateways()->get_available_payment_gateways()
'product_count' => WC()->cart->get_cart_contents_count(),
'cart_total' => floatval( WC()->cart->get_cart_contents_total() ),
'currency' => get_woocommerce_currency(),
'payment_method' => array_keys( WC()->payment_gateways()->get_available_payment_gateways() ),
);

$this->push(
"site_checkout_view",
'site_checkout_view',
$data
);
}

/**
* Thank you page, send data to Hiive
*
* @param int $order_id
* @param int $order_id
*
* @return void
*/
public function thank_you_page($order_id ) {
$order = wc_get_order( $order_id );
public function thank_you_page( $order_id ) {
$order = wc_get_order( $order_id );
$line_items = $order->get_items();

// This loops over line items
foreach ( $line_items as $item ) {
$qty = $item['qty'];
}
$data = array(
"product_count" => $qty,
"order_total" => floatval($order->get_total()),
"currency" => get_woocommerce_currency(),
'product_count' => $qty,
'order_total' => floatval( $order->get_total() ),
'currency' => get_woocommerce_currency(),
);

$this->push(
"site_thank_you_view",
'site_thank_you_view',
$data
);
}
Expand All @@ -162,16 +161,16 @@ public function thank_you_page($order_id ) {
* @return string The new option value
*/
public function razorpay_connection( $new_option, $old_option ) {
$url = is_ssl() ? "https://" : "http://";
$url = is_ssl() ? 'https://' : 'http://';
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = array(
"label_key" => "provider",
"provider" => "razorpay",
"page" => $url
'label_key' => 'provider',
'provider' => 'razorpay',
'page' => $url,
);
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
$this->push(
"payment_connected",
'payment_connected',
$data
);
}
Expand All @@ -188,16 +187,16 @@ public function razorpay_connection( $new_option, $old_option ) {
* @return string The new option value
*/
public function shippo_connection( $new_option, $old_option ) {
$url = is_ssl() ? "https://" : "http://";
$url = is_ssl() ? 'https://' : 'http://';
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = array(
"label_key" => "provider",
"provider" => "shippo",
"page" => $url
'label_key' => 'provider',
'provider' => 'shippo',
'page' => $url,
);
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
$this->push(
"shipping_connected",
'shipping_connected',
$data
);
}
Expand All @@ -214,16 +213,16 @@ public function shippo_connection( $new_option, $old_option ) {
* @return string The new option value
*/
public function stripe_connection( $new_option, $old_option ) {
$url = is_ssl() ? "https://" : "http://";
$url = is_ssl() ? 'https://' : 'http://';
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = array(
"label_key" => "provider",
"provider" => "stripe",
"page" => $url
'label_key' => 'provider',
'provider' => 'stripe',
'page' => $url,
);
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
$this->push(
"payment_connected",
'payment_connected',
$data
);
}
Expand All @@ -240,16 +239,16 @@ public function stripe_connection( $new_option, $old_option ) {
* @return string The new option value
*/
public function paypal_connection( $new_option, $old_option ) {
$url = is_ssl() ? "https://" : "http://";
$url = is_ssl() ? 'https://' : 'http://';
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = array(
"label_key" => "provider",
"provider" => "yith_paypal",
"page" => $url
'label_key' => 'provider',
'provider' => 'yith_paypal',
'page' => $url,
);
if ( $new_option !== $old_option && ! empty( $new_option ) ) {
$this->push(
"payment_connected",
'payment_connected',
$data
);
}
Expand All @@ -265,66 +264,67 @@ public function paypal_connection( $new_option, $old_option ) {
*
* @return string The new option value
*/
public function ecomdash_connected($new_option, $old_option) {
public function ecomdash_connected( $new_option, $old_option ) {
if ( $new_option !== $old_option && ! empty( $new_option ) && $new_option === 'connected' ) {
$url = is_ssl() ? "https://" : "http://";
$url = is_ssl() ? 'https://' : 'http://';
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$data = array(
"url" => $url
'url' => $url,
);
$this->push(
"ecomdash_connected",
'ecomdash_connected',
$data
);
}
}
return $new_option;
}

/**
* Product added, send data to Hiive
* @param string $product_id id of post which is being savedPost ObjectOld value of the yith_ppwc_merchant_data_production option
* @param WP_POST $product details of the product
* @return void
*/
public function product_created_or_updated($product_id, $product) {
$data = array(
"label_key" => "product_type",
"product_type" => $product->product_type,
"post_id" => $product_id
);

$this->push(
"product_created",
$data
);
}
* Product added, send data to Hiive
*
* @param string $product_id id of post which is being savedPost ObjectOld value of the yith_ppwc_merchant_data_production option
* @param WP_POST $product details of the product
* @return void
*/
public function product_created_or_updated( $product_id, $product ) {
$data = array(
'label_key' => 'product_type',
'product_type' => $product->product_type,
'post_id' => $product_id,
);

$this->push(
'product_created',
$data
);
}

/**
* HPOS (High Performance Order Storage) is enabled
* Send data to hiive
* @param string $old_value Old value of woocommerce_custom_orders_table_enabled
* @param string $new_value New value of woocommerce_custom_orders_table_enabled
* @param option name of the option being updated
* @return void
*/
public function woocommerce_hpos_enabled($old_value, $new_value, $option) {
if ( $new_value !== $old_value && ! empty( $new_value )) {
$url = is_ssl() ? "https://" : "http://";
* HPOS (High Performance Order Storage) is enabled
* Send data to hiive
* @param string $old_value Old value of woocommerce_custom_orders_table_enabled
* @param string $new_value New value of woocommerce_custom_orders_table_enabled
* @param option name of the option being updated
* @return void
*/
public function woocommerce_hpos_enabled( $old_value, $new_value, $option ) {
if ( $new_value !== $old_value && ! empty( $new_value ) ) {
$url = is_ssl() ? 'https://' : 'http://';
$url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$type = ($new_value === 'yes') ? 'hpos':'legacy';
$type = ( $new_value === 'yes' ) ? 'hpos' : 'legacy';

$data = array(
"label_key" => $option,
"type" => $type,
"page" => $url
'label_key' => $option,
'type' => $type,
'page' => $url,
);

$this->push(
"changed_woo_order_storage_type",
'changed_woo_order_storage_type',
$data
);
}
}
}
}
Loading

0 comments on commit 0563923

Please sign in to comment.