Changeset 2845940
- Timestamp:
- 01/10/2023 09:01:06 AM (3 years ago)
- Location:
- viaads
- Files:
-
- 15 added
- 6 edited
-
tags/1.0.6 (added)
-
tags/1.0.6/apikey.php (added)
-
tags/1.0.6/externalJS.php (added)
-
tags/1.0.6/handleEmailGuid.php (added)
-
tags/1.0.6/hooks (added)
-
tags/1.0.6/hooks/addCart.php (added)
-
tags/1.0.6/hooks/pageLook.php (added)
-
tags/1.0.6/hooks/removeCart.php (added)
-
tags/1.0.6/http.php (added)
-
tags/1.0.6/js (added)
-
tags/1.0.6/js/viaads_handleEmailGuid.js (added)
-
tags/1.0.6/readme.txt (added)
-
tags/1.0.6/sync.php (added)
-
tags/1.0.6/userAgent.php (added)
-
tags/1.0.6/viaads.php (added)
-
trunk/hooks/addCart.php (modified) (3 diffs)
-
trunk/hooks/pageLook.php (modified) (2 diffs)
-
trunk/hooks/removeCart.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/sync.php (modified) (1 diff)
-
trunk/viaads.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
viaads/trunk/hooks/addCart.php
r2841526 r2845940 9 9 defined( 'ABSPATH' ) || exit; 10 10 11 //add_action( 'woocommerce_add_cart_item_data', 'addToCartViaAds', 100000, 3 );12 11 add_action( 'woocommerce_add_to_cart', 'ViaAds\\ViaAds_addToCart', 100000, 6 ); 13 12 … … 79 78 $shopEvent->Product_id = $product_id; 80 79 $shopEvent->Product_variant_id = $variation_id; 81 $shopEvent->Price = number_format( $product->get_price(), 2, ".", ",");80 $shopEvent->Price = $product->get_price(); 82 81 } 83 82 … … 87 86 $data->Shop_event = $shopEvent; 88 87 $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' ); 90 89 91 90 ViaAds_PostToUrlEvent( "https://integration.viaads.dk/woocommerce/event", $data ); -
viaads/trunk/hooks/pageLook.php
r2841526 r2845940 72 72 $shopEvent->Product_sku = $product->get_sku(); 73 73 $shopEvent->Product_id = $product->get_id(); 74 $shopEvent->Price = number_format( $product->get_price(), 2, ".", ",");74 $shopEvent->Price = $product->get_price(); 75 75 76 76 $data->ApiKey = get_option( "viaads_api_key" ); … … 92 92 ViaAds_PostToUrlEvent( "https://integration.viaads.dk/error", $error_object ); 93 93 } 94 //Save data to file95 /*$myfile = fopen( $_SERVER[ 'DOCUMENT_ROOT' ] . '/wp-content/plugins/marlin/BehaviorTracking/data1.txt', "a" );96 fwrite( $myfile, json_encode( $data ) . "\n" );97 fclose( $myfile );*/98 94 } -
viaads/trunk/hooks/removeCart.php
r2841526 r2845940 2 2 3 3 namespace ViaAds; 4 4 5 use stdClass; 5 6 use DateTime; 6 7 use Exception; 7 8 8 defined( 'ABSPATH') || exit;9 defined('ABSPATH') || exit; 9 10 10 add_action( 'woocommerce_remove_cart_item', 'ViaAds\\ViaAds_removeFromCart', 100000, 2);11 add_action('woocommerce_remove_cart_item', 'ViaAds\\ViaAds_removeFromCart', 100000, 2); 11 12 12 function ViaAds_removeFromCart( $cart_item_key, $cart ) { 13 function ViaAds_removeFromCart($cart_item_key, $cart) 14 { 13 15 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); 16 21 } 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 } 18 27 } 19 28 20 //Get product21 $product = wc_get_product( $productId );22 29 //guid//email//emailGuid 23 if (!isset($_COOKIE[ 'ViaAds'])) {30 if (!isset($_COOKIE['ViaAds'])) { 24 31 return; 25 32 } 26 33 27 $cookieValue = sanitize_text_field($_COOKIE[ 'ViaAds']);34 $cookieValue = sanitize_text_field($_COOKIE['ViaAds']); 28 35 29 $cookieValues = explode( "//", $cookieValue);36 $cookieValues = explode("//", $cookieValue); 30 37 $data = new stdClass(); 31 38 32 39 //ClientInfo 33 40 $clientInfo = new stdClass(); 34 $ip = sanitize_text_field($_SERVER[ 'HTTP_X_FORWARDED_FOR']);41 $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']); 35 42 $clientInfo->ip = $ip; 36 43 37 44 //User Agent 38 45 $userAgentFile = realpath(dirname(plugin_dir_path(__FILE__)) . '/userAgent.php'); 39 if ($userAgentFile) {40 require_once( $userAgentFile);46 if ($userAgentFile) { 47 require_once($userAgentFile); 41 48 $ua = ViaAds_getBrowser(); 42 49 $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']; 47 54 $data->user_agent = $userAgent; 48 55 } … … 50 57 //ProductPageUrl 51 58 $productPageUrl = new stdClass(); 52 $productPageUrl->full = get_permalink( $productId);59 $productPageUrl->full = get_permalink($productId); 53 60 54 61 //Email … … 57 64 $email = ( string )$current_user->user_email; 58 65 $customer = new stdClass(); 59 if ( strlen( $email ) > 4) {66 if (strlen($email) > 4) { 60 67 $customer->Email = $email; 61 68 } else { 62 $customer->Email = $cookieValues[ 1];69 $customer->Email = $cookieValues[1]; 63 70 } 64 71 65 $customer->Session_id = $cookieValues[ 0];66 $customer->Email_guid = $cookieValues[ 2];72 $customer->Session_id = $cookieValues[0]; 73 $customer->Email_guid = $cookieValues[2]; 67 74 $data->customer = $customer; 68 75 … … 70 77 $shopEvent = new stdClass(); 71 78 $shopEvent->Event_type = "RemoveCart"; 72 if (!is_bool($product)) {79 if (!is_bool($product)) { 73 80 $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']; 77 84 } 78 85 79 $data->ApiKey = get_option( "viaads_api_key");86 $data->ApiKey = get_option("viaads_api_key"); 80 87 $data->client = $clientInfo; 81 88 $data->url = $productPageUrl; 82 89 $data->Shop_event = $shopEvent; 83 90 $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) { 88 95 $error_object = new stdClass(); 89 96 $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'])); 92 99 $error_object->Url = wp_http_validate_url($currentPageUrl); 93 100 94 ViaAds_PostToUrlEvent( "https://integration.viaads.dk/error", $error_object);101 ViaAds_PostToUrlEvent("https://integration.viaads.dk/error", $error_object); 95 102 } 96 103 } -
viaads/trunk/readme.txt
r2842484 r2845940 4 4 Requires at least: 5.4 5 5 Tested up to: 6.1 6 Stable tag: 1.0. 56 Stable tag: 1.0.6 7 7 Requires PHP: 7.0 8 8 License: GPLv3 -
viaads/trunk/sync.php
r2842484 r2845940 341 341 $order_item_object->Sku = $item->get_product()->get_sku(); 342 342 // 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(); 344 345 // Quantity 345 346 $order_item_object->Quantity = round( $item->get_quantity() ); 346 347 // 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(); 350 354 351 355 array_push( $orderItems, $order_item_object ); -
viaads/trunk/viaads.php
r2842484 r2845940 3 3 * Plugin Name: ViaAds 4 4 * Description: Plugin der muliggør forbindelsen til ViaAds / Plug-in enabling the connection to ViaAds. 5 * Version: 1.0. 55 * Version: 1.0.6 6 6 * Author: ViaAds 7 7 * Author URI: https://www.viaads.dk/
Note: See TracChangeset
for help on using the changeset viewer.