Skip to content

Commit

Permalink
Merge pull request #40 from sumathi3399/PRESS4-360-events-data
Browse files Browse the repository at this point in the history
PRESS4-360 |  Events data
  • Loading branch information
circlecube authored Oct 4, 2023
2 parents f679aa5 + 30917ec commit 4303c90
Showing 4 changed files with 169 additions and 215 deletions.
2 changes: 1 addition & 1 deletion includes/EventManager.php
Original file line number Diff line number Diff line change
@@ -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',
);

/**
148 changes: 124 additions & 24 deletions includes/Listeners/Commerce.php
Original file line number Diff line number Diff line change
@@ -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,18 +134,119 @@ 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(
"site_thank_you_view",
$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;
}
}
44 changes: 44 additions & 0 deletions includes/Listeners/WonderCart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace NewfoldLabs\WP\Module\Data\Listeners;

/**
* Monitors WonderCart events
*/
class WonderCart extends Listener {

/**
* Register the hooks for the listener
*
* @return void
*/
public function register_hooks() {
add_action('rest_after_insert_yith_campaign', array( $this, 'register_campaign' ), 10 );
}

/**
* 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(
"label_key"=> "type",
"type"=> $type,
);

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

return $post;
}
}
Loading

0 comments on commit 4303c90

Please sign in to comment.