diff --git a/includes/EventManager.php b/includes/EventManager.php index bdbc6ab..cad6af5 100644 --- a/includes/EventManager.php +++ b/includes/EventManager.php @@ -23,8 +23,8 @@ class EventManager { '\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\BluehostPlugin', '\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\SiteHealth', '\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\Theme', - '\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\Yith', '\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\Commerce', + '\\NewfoldLabs\\WP\\Module\\Data\\Listeners\\WonderCart', ); /** diff --git a/includes/Listeners/Commerce.php b/includes/Listeners/Commerce.php index 877d83d..ac50a2d 100644 --- a/includes/Listeners/Commerce.php +++ b/includes/Listeners/Commerce.php @@ -19,6 +19,11 @@ public function register_hooks() { 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 ); } /** @@ -81,14 +86,11 @@ public function orders_count( $data ) { */ 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(), - ), - ); + $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", @@ -104,15 +106,12 @@ public function site_cart_views() { * @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() - ), - ); + $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", @@ -135,13 +134,10 @@ public function thank_you_page($order_id ) { 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(), - ), + $data = array( + "product_count" => $qty, + "order_total" => floatval($order->get_total()), + "currency" => get_woocommerce_currency(), ); $this->push( @@ -149,4 +145,108 @@ public function thank_you_page($order_id ) { $data ); } + + /** + * 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( + "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( + "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( + "label_key" => "provider", + "provider" => "stripe", + "page" => $url + ); + if ( $new_option !== $old_option && ! empty( $new_option ) ) { + $this->push( + "payment_connected", + $data + ); + } + + return $new_option; + } + + /** + * PayPal connected + * + * @param string $new_option New value of the yith_ppwc_merchant_data_production option + * @param string $old_option Old value of the yith_ppwc_merchant_data_production option + * + * @return string The new option value + */ + public function paypal_connection( $new_option, $old_option ) { + $url = is_ssl() ? "https://" : "http://"; + $url .= $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; + $data = array( + "label_key" => "provider", + "provider" => "yith_paypal", + "page" => $url + ); + if ( $new_option !== $old_option && ! empty( $new_option ) ) { + $this->push( + "payment_connected", + $data + ); + } + + return $new_option; + } } diff --git a/includes/Listeners/WonderCart.php b/includes/Listeners/WonderCart.php new file mode 100644 index 0000000..428380f --- /dev/null +++ b/includes/Listeners/WonderCart.php @@ -0,0 +1,44 @@ +ID ); + if ($campaign){ + $type = $campaign->get_type(); + + $data = array( + "label_key"=> "type", + "type"=> $type, + ); + + $this->push( + "campaign_created", + $data + ); + } + + return $post; + } +} diff --git a/includes/Listeners/Yith.php b/includes/Listeners/Yith.php deleted file mode 100644 index fe01e63..0000000 --- a/includes/Listeners/Yith.php +++ /dev/null @@ -1,190 +0,0 @@ - "commerce", - "data" => array( - "label_key" => "provider", - "provider" => "yith_paypal", - "page" => $url - ), - ); - if ( $new_option !== $old_option && ! empty( $new_option ) ) { - $this->push( - "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; - } -}