Plugin Directory

Changeset 2845940


Ignore:
Timestamp:
01/10/2023 09:01:06 AM (3 years ago)
Author:
viaads
Message:

Performance Update

Location:
viaads
Files:
15 added
6 edited

Legend:

Unmodified
Added
Removed
  • viaads/trunk/hooks/addCart.php

    r2841526 r2845940  
    99defined( 'ABSPATH' ) || exit;
    1010
    11 //add_action( 'woocommerce_add_cart_item_data', 'addToCartViaAds', 100000, 3 );
    1211add_action( 'woocommerce_add_to_cart', 'ViaAds\\ViaAds_addToCart', 100000, 6 );
    1312
     
    7978            $shopEvent->Product_id = $product_id;
    8079            $shopEvent->Product_variant_id = $variation_id;
    81             $shopEvent->Price = number_format( $product->get_price(), 2, ".", "," );
     80            $shopEvent->Price = $product->get_price();
    8281        }
    8382
     
    8786        $data->Shop_event = $shopEvent;
    8887        $date = new DateTime();
    89         $data->Event_date = $date->format( 'Y-m-d\TH:i:s' );       
     88        $data->Event_date = $date->format( 'Y-m-d\TH:i:s' );
    9089
    9190        ViaAds_PostToUrlEvent( "https://integration.viaads.dk/woocommerce/event", $data );
  • viaads/trunk/hooks/pageLook.php

    r2841526 r2845940  
    7272        $shopEvent->Product_sku = $product->get_sku();
    7373        $shopEvent->Product_id = $product->get_id();
    74         $shopEvent->Price = number_format( $product->get_price(), 2, ".", "," );
     74        $shopEvent->Price = $product->get_price();
    7575
    7676        $data->ApiKey = get_option( "viaads_api_key" );
     
    9292        ViaAds_PostToUrlEvent( "https://integration.viaads.dk/error", $error_object );
    9393    }
    94     //Save data to file
    95     /*$myfile = fopen( $_SERVER[ 'DOCUMENT_ROOT' ] . '/wp-content/plugins/marlin/BehaviorTracking/data1.txt', "a" );
    96     fwrite( $myfile, json_encode( $data ) . "\n" );
    97     fclose( $myfile );*/
    9894}
  • viaads/trunk/hooks/removeCart.php

    r2841526 r2845940  
    22
    33namespace ViaAds;
     4
    45use stdClass;
    56use DateTime;
    67use Exception;
    78
    8 defined( 'ABSPATH' ) || exit;
     9defined('ABSPATH') || exit;
    910
    10 add_action( 'woocommerce_remove_cart_item', 'ViaAds\\ViaAds_removeFromCart', 100000, 2 );
     11add_action('woocommerce_remove_cart_item', 'ViaAds\\ViaAds_removeFromCart', 100000, 2);
    1112
    12 function ViaAds_removeFromCart( $cart_item_key, $cart ) {
     13function ViaAds_removeFromCart($cart_item_key, $cart)
     14{
    1315    try {
    14         if ( $cart->cart_contents[ $cart_item_key ][ 'variation_id' ] != 0 ) {
    15             $productId = $cart->cart_contents[ $cart_item_key ][ 'variation_id' ];
     16        //Product
     17        $variationId = $cart->cart_contents[$cart_item_key]['variation_id'];
     18        $productId = $cart->cart_contents[$cart_item_key]['product_id'];
     19        if ($variationId != "" && is_numeric($variationId) && $variationId != 0) {
     20            $product = wc_get_product($variationId);
    1621        } else {
    17             $productId = $cart->cart_contents[ $cart_item_key ][ 'product_id' ];
     22            $product = wc_get_product($productId);
     23            if (is_bool($product)) {
     24                $_pf = new WC_Product_Factory();
     25                $product = $_pf->get_product($productId);
     26            }
    1827        }
    1928
    20         //Get product
    21         $product = wc_get_product( $productId );
    2229        //guid//email//emailGuid
    23         if(!isset($_COOKIE[ 'ViaAds' ])) {
     30        if (!isset($_COOKIE['ViaAds'])) {
    2431            return;
    2532        }
    2633
    27         $cookieValue = sanitize_text_field($_COOKIE[ 'ViaAds' ]);
     34        $cookieValue = sanitize_text_field($_COOKIE['ViaAds']);
    2835
    29         $cookieValues = explode( "//", $cookieValue );
     36        $cookieValues = explode("//", $cookieValue);
    3037        $data = new stdClass();
    3138
    3239        //ClientInfo
    3340        $clientInfo = new stdClass();
    34         $ip = sanitize_text_field($_SERVER[ 'HTTP_X_FORWARDED_FOR' ]);
     41        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
    3542        $clientInfo->ip = $ip;
    3643
    3744        //User Agent
    3845        $userAgentFile = realpath(dirname(plugin_dir_path(__FILE__)) . '/userAgent.php');
    39         if($userAgentFile) {
    40             require_once( $userAgentFile );
     46        if ($userAgentFile) {
     47            require_once($userAgentFile);
    4148            $ua = ViaAds_getBrowser();
    4249            $userAgent = new stdClass();
    43             $userAgent->device_name = $ua[ 'platform' ];
    44             $userAgent->name = $ua[ 'name' ];
    45             $userAgent->original = $_SERVER[ 'HTTP_USER_AGENT' ];
    46             $userAgent->version = $ua[ 'version' ];
     50            $userAgent->device_name = $ua['platform'];
     51            $userAgent->name = $ua['name'];
     52            $userAgent->original = $_SERVER['HTTP_USER_AGENT'];
     53            $userAgent->version = $ua['version'];
    4754            $data->user_agent = $userAgent;
    4855        }
     
    5057        //ProductPageUrl
    5158        $productPageUrl = new stdClass();
    52         $productPageUrl->full = get_permalink( $productId );
     59        $productPageUrl->full = get_permalink($productId);
    5360
    5461        //Email
     
    5764        $email = ( string )$current_user->user_email;
    5865        $customer = new stdClass();
    59         if ( strlen( $email ) > 4 ) {
     66        if (strlen($email) > 4) {
    6067            $customer->Email = $email;
    6168        } else {
    62             $customer->Email = $cookieValues[ 1 ];
     69            $customer->Email = $cookieValues[1];
    6370        }
    6471
    65         $customer->Session_id = $cookieValues[ 0 ];
    66         $customer->Email_guid = $cookieValues[ 2 ];
     72        $customer->Session_id = $cookieValues[0];
     73        $customer->Email_guid = $cookieValues[2];
    6774        $data->customer = $customer;
    6875
     
    7077        $shopEvent = new stdClass();
    7178        $shopEvent->Event_type = "RemoveCart";
    72         if(!is_bool($product)) {
     79        if (!is_bool($product)) {
    7380            $shopEvent->Product_sku = $product->get_sku();
    74             $shopEvent->Price = number_format( $product->get_price(), 2, ".", "," );
    75             $shopEvent->Product_id = $cart->cart_contents[ $cart_item_key ][ 'product_id' ];
    76             $shopEvent->Product_variant_id = $cart->cart_contents[ $cart_item_key ][ 'variation_id' ];
     81            $shopEvent->Price = $product->get_price();
     82            $shopEvent->Product_id = $cart->cart_contents[$cart_item_key]['product_id'];
     83            $shopEvent->Product_variant_id = $cart->cart_contents[$cart_item_key]['variation_id'];
    7784        }
    7885
    79         $data->ApiKey = get_option( "viaads_api_key" );
     86        $data->ApiKey = get_option("viaads_api_key");
    8087        $data->client = $clientInfo;
    8188        $data->url = $productPageUrl;
    8289        $data->Shop_event = $shopEvent;
    8390        $date = new DateTime();
    84         $data->Event_date = $date->format( 'Y-m-d\TH:i:s' );
    85        
    86         ViaAds_PostToUrlEvent( "https://integration.viaads.dk/woocommerce/event", $data );
    87     } catch ( Exception $e ) {
     91        $data->Event_date = $date->format('Y-m-d\TH:i:s');
     92
     93        ViaAds_PostToUrlEvent("https://integration.viaads.dk/woocommerce/event", $data);
     94    } catch (Exception $e) {
    8895        $error_object = new stdClass();
    8996        $error_object->Error = $e->getMessage();
    90        
    91         $currentPageUrl = sanitize_url( home_url( $_SERVER['REQUEST_URI'] ) );
     97
     98        $currentPageUrl = sanitize_url(home_url($_SERVER['REQUEST_URI']));
    9299        $error_object->Url = wp_http_validate_url($currentPageUrl);
    93100
    94         ViaAds_PostToUrlEvent( "https://integration.viaads.dk/error", $error_object );
     101        ViaAds_PostToUrlEvent("https://integration.viaads.dk/error", $error_object);
    95102    }
    96103}
  • viaads/trunk/readme.txt

    r2842484 r2845940  
    44Requires at least: 5.4
    55Tested up to: 6.1
    6 Stable tag: 1.0.5
     6Stable tag: 1.0.6
    77Requires PHP: 7.0
    88License: GPLv3
  • viaads/trunk/sync.php

    r2842484 r2845940  
    341341            $order_item_object->Sku = $item->get_product()->get_sku();
    342342            // Price
    343             $order_item_object->Price = number_format( $item->get_subtotal() / $item->get_quantity(), 2, ".", "" );
     343            //$order_item_object->Price = number_format( $item->get_subtotal() / $item->get_quantity(), 2, ".", "" );
     344            $order_item_object->Price = $item->get_subtotal() / $item->get_quantity();
    344345            // Quantity
    345346            $order_item_object->Quantity = round( $item->get_quantity() );
    346347            // Total
    347             $order_item_object->Total_price = number_format( $item->get_total(), 2, ".", "" );
    348             $order_item_object->Total_price_tax = number_format( $item->get_total_tax(), 2, ".", "" );
    349             $order_item_object->Total_price_tax_included = number_format( $item->get_total() + $item->get_total_tax(), 2, ".", "" );
     348            //$order_item_object->Total_price = number_format( $item->get_total(), 2, ".", "" );
     349            $order_item_object->Total_price = $item->get_total();
     350            //$order_item_object->Total_price_tax = number_format( $item->get_total_tax(), 2, ".", "" );
     351            $order_item_object->Total_price_tax = $item->get_total_tax();
     352            //$order_item_object->Total_price_tax_included = number_format( $item->get_total() + $item->get_total_tax(), 2, ".", "" );
     353            $order_item_object->Total_price_tax_included = $item->get_total() + $item->get_total_tax();
    350354
    351355            array_push( $orderItems, $order_item_object );
  • viaads/trunk/viaads.php

    r2842484 r2845940  
    33 * Plugin Name: ViaAds
    44 * Description: Plugin der muliggør forbindelsen til ViaAds / Plug-in enabling the connection to ViaAds.
    5  * Version: 1.0.5
     5 * Version: 1.0.6
    66 * Author: ViaAds
    77 * Author URI: https://www.viaads.dk/
Note: See TracChangeset for help on using the changeset viewer.