diff --git a/composer.lock b/composer.lock index 067f543..5aab94d 100644 --- a/composer.lock +++ b/composer.lock @@ -417,6 +417,142 @@ }, "time": "2022-10-24T09:00:36+00:00" }, + { + "name": "phpcsstandards/phpcsextra", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSExtra.git", + "reference": "61a9be9f74a53735f7c421d7de8dc64fa80488e6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSExtra/zipball/61a9be9f74a53735f7c421d7de8dc64fa80488e6", + "reference": "61a9be9f74a53735f7c421d7de8dc64fa80488e6", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.1" + }, + "require-dev": { + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "phpcsstandards/phpcsdevtools": "^1.2.1", + "phpunit/phpunit": "^4.5 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSExtra/graphs/contributors" + } + ], + "description": "A collection of sniffs and standards for use with PHP_CodeSniffer.", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "standards", + "static analysis" + ], + "support": { + "issues": "https://github.com/PHPCSStandards/PHPCSExtra/issues", + "source": "https://github.com/PHPCSStandards/PHPCSExtra" + }, + "time": "2023-07-19T19:40:11+00:00" + }, + { + "name": "phpcsstandards/phpcsutils", + "version": "1.0.8", + "source": { + "type": "git", + "url": "https://github.com/PHPCSStandards/PHPCSUtils.git", + "reference": "69465cab9d12454e5e7767b9041af0cd8cd13be7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHPCSStandards/PHPCSUtils/zipball/69465cab9d12454e5e7767b9041af0cd8cd13be7", + "reference": "69465cab9d12454e5e7767b9041af0cd8cd13be7", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7 || ^1.0", + "php": ">=5.4", + "squizlabs/php_codesniffer": "^3.7.1 || 4.0.x-dev@dev" + }, + "require-dev": { + "ext-filter": "*", + "php-parallel-lint/php-console-highlighter": "^1.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", + "phpcsstandards/phpcsdevcs": "^1.1.6", + "yoast/phpunit-polyfills": "^1.0.5 || ^2.0.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-stable": "1.x-dev", + "dev-develop": "1.x-dev" + } + }, + "autoload": { + "classmap": [ + "PHPCSUtils/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "LGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Juliette Reinders Folmer", + "homepage": "https://github.com/jrfnl", + "role": "lead" + }, + { + "name": "Contributors", + "homepage": "https://github.com/PHPCSStandards/PHPCSUtils/graphs/contributors" + } + ], + "description": "A suite of utility functions for use with PHP_CodeSniffer", + "homepage": "https://phpcsutils.com/", + "keywords": [ + "PHP_CodeSniffer", + "phpcbf", + "phpcodesniffer-standard", + "phpcs", + "phpcs3", + "standards", + "static analysis", + "tokens", + "utility" + ], + "support": { + "docs": "https://phpcsutils.com/", + "issues": "https://github.com/PHPCSStandards/PHPCSUtils/issues", + "source": "https://github.com/PHPCSStandards/PHPCSUtils" + }, + "time": "2023-07-16T21:39:41+00:00" + }, { "name": "squizlabs/php_codesniffer", "version": "3.7.2", @@ -476,30 +612,38 @@ }, { "name": "wp-coding-standards/wpcs", - "version": "2.3.0", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/WordPress/WordPress-Coding-Standards.git", - "reference": "7da1894633f168fe244afc6de00d141f27517b62" + "reference": "bb792cb331472b82c5d7f28fb9b8ec2d20f68826" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/7da1894633f168fe244afc6de00d141f27517b62", - "reference": "7da1894633f168fe244afc6de00d141f27517b62", + "url": "https://api.github.com/repos/WordPress/WordPress-Coding-Standards/zipball/bb792cb331472b82c5d7f28fb9b8ec2d20f68826", + "reference": "bb792cb331472b82c5d7f28fb9b8ec2d20f68826", "shasum": "" }, "require": { + "ext-filter": "*", + "ext-libxml": "*", + "ext-tokenizer": "*", + "ext-xmlreader": "*", "php": ">=5.4", - "squizlabs/php_codesniffer": "^3.3.1" + "phpcsstandards/phpcsextra": "^1.1.0", + "phpcsstandards/phpcsutils": "^1.0.8", + "squizlabs/php_codesniffer": "^3.7.2" }, "require-dev": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.5 || ^0.6", + "php-parallel-lint/php-console-highlighter": "^1.0.0", + "php-parallel-lint/php-parallel-lint": "^1.3.2", "phpcompatibility/php-compatibility": "^9.0", - "phpcsstandards/phpcsdevtools": "^1.0", + "phpcsstandards/phpcsdevtools": "^1.2.0", "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "suggest": { - "dealerdirect/phpcodesniffer-composer-installer": "^0.6 || This Composer plugin will sort out the PHPCS 'installed_paths' automatically." + "ext-iconv": "For improved results", + "ext-mbstring": "For improved results" }, "type": "phpcodesniffer-standard", "notification-url": "https://packagist.org/downloads/", @@ -516,6 +660,7 @@ "keywords": [ "phpcs", "standards", + "static analysis", "wordpress" ], "support": { @@ -523,7 +668,7 @@ "source": "https://github.com/WordPress/WordPress-Coding-Standards", "wiki": "https://github.com/WordPress/WordPress-Coding-Standards/wiki" }, - "time": "2020-05-13T23:57:56+00:00" + "time": "2023-08-21T14:28:38+00:00" } ], "aliases": [], diff --git a/src/Listeners/Commerce.php b/src/Listeners/Commerce.php index e2947fc..877d83d 100644 --- a/src/Listeners/Commerce.php +++ b/src/Listeners/Commerce.php @@ -16,6 +16,9 @@ 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')); } /** @@ -70,4 +73,80 @@ public function orders_count( $data ) { return $data; } + + /** + * Site Cart View, send data to Hiive + * + * @return void + */ + public function site_cart_views() { + if( WC()->cart->get_cart_contents_count() !== 0){ + $data = array( + "category" => "commerce", + "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 + ); + } + } + + + /** + * Checkout view, send data to Hiive + * + * @return void + */ + public function checkout_views() { + $data = array( + "category" => "commerce", + "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() + ), + ); + + $this->push( + "site_checkout_view", + $data + ); + } + + /** + * Thank you page, send data to Hiive + * + * @param int $order_id + * + * @return void + */ + 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( + "category" => "commerce", + "data" => array( + "product_count" => $qty, + "order_total" => floatval($order->get_total()), + "currency" => get_woocommerce_currency(), + ), + ); + + $this->push( + "site_thank_you_view", + $data + ); + } } diff --git a/src/Listeners/Yith.php b/src/Listeners/Yith.php index 66ec25a..fe01e63 100644 --- a/src/Listeners/Yith.php +++ b/src/Listeners/Yith.php @@ -15,6 +15,11 @@ class Yith extends Listener { public function register_hooks() { // Paypal Connection add_filter( 'pre_update_option_yith_ppwc_merchant_data_production', array( $this, 'paypal_connection' ), 10, 2 ); + 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 ); + add_action('rest_after_insert_yith_campaign', array( $this, 'register_campaign' ), 10 ); + add_filter('toplevel_page_newfold-ecomdash', array($this, 'ecomdash_connected')); } /** @@ -26,15 +31,160 @@ public function register_hooks() { * @return string The new option value */ public function paypal_connection( $new_option, $old_option ) { - if ( $new_option !== $old_option && ! empty( $new_option ) ) { + $url = is_ssl() ? "https://" : "http://"; + $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $data = array( + "category" => "commerce", + "data" => array( + "label_key" => "provider", + "provider" => "yith_paypal", + "page" => $url + ), + ); + if ( $new_option !== $old_option && ! empty( $new_option ) ) { $this->push( - 'yith_payment_connected', - array( - 'provider' => 'paypal', - ) + "payment_connected", + $data ); } return $new_option; } + + /** + * Razorpay connected + * + * @param string $new_option New value of the razorpay_data_production option + * @param string $old_option Old value of the razorpay_data_production option + * + * @return string The new option value + */ + public function razorpay_connection( $new_option, $old_option ) { + $url = is_ssl() ? "https://" : "http://"; + $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $data = array( + "category" => "commerce", + "data" => array( + "label_key" => "provider", + "provider" => "razorpay", + "page" => $url + ), + ); + if ( $new_option !== $old_option && ! empty( $new_option ) ) { + $this->push( + "payment_connected", + $data + ); + } + + return $new_option; + } + + /** + * Shippo connected + * + * @param string $new_option New value of the shippo_data option + * @param string $old_option Old value of the shippo_data option + * + * @return string The new option value + */ + public function shippo_connection( $new_option, $old_option ) { + $url = is_ssl() ? "https://" : "http://"; + $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $data = array( + "category" => "commerce", + "data" => array( + "label_key" => "provider", + "provider" => "shippo", + "page" => $url + ), + ); + if ( $new_option !== $old_option && ! empty( $new_option ) ) { + $this->push( + "shpping_connected", + $data + ); + } + + return $new_option; + } + + /** + * Stripe connected + * + * @param string $new_option New value of the stripe_data_production option + * @param string $old_option Old value of the stripe_data_production option + * + * @return string The new option value + */ + public function stripe_connection( $new_option, $old_option ) { + $url = is_ssl() ? "https://" : "http://"; + $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $data = array( + "category" => "commerce", + "data" => array( + "label_key" => "provider", + "provider" => "stripe", + "page" => $url + ), + ); + if ( $new_option !== $old_option && ! empty( $new_option ) ) { + $this->push( + "payment_connected", + $data + ); + } + + return $new_option; + } + + /** + * Ecomdash connected + * + * @return void + */ + public function ecomdash_connected() { + $isecomdash_connected = \get_option( 'ewc4wp_sso_account_status', '' ); + if($isecomdash_connected === 'connected'){ + $url = is_ssl() ? "https://" : "http://"; + $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $data = array( + "category" => "commerce", + "data" => array( + "url" => $url + ), + ); + + $this->push( + "ecomdash_connected", + $data + ); + } + } + + /** + * Campaign created + * + * @param string $post + * + * @return string The post value + */ + public function register_campaign( $post){ + $campaign = yith_sales_get_campaign( $post->ID ); + if ($campaign){ + $type = $campaign->get_type(); + $data = array( + "category"=> "wonder_cart", + "data"=> array( + "label_key"=> "type", + "type"=> $type, + ), + ); + $this->push( + "campaign_created", + $data + ); + } + return $post; + } }