Changeset 2846806
- Timestamp:
- 01/11/2023 02:03:16 PM (3 years ago)
- Location:
- viaads
- Files:
-
- 15 added
- 5 edited
-
tags/1.0.7 (added)
-
tags/1.0.7/apikey.php (added)
-
tags/1.0.7/externalJS.php (added)
-
tags/1.0.7/handleEmailGuid.php (added)
-
tags/1.0.7/hooks (added)
-
tags/1.0.7/hooks/addCart.php (added)
-
tags/1.0.7/hooks/pageLook.php (added)
-
tags/1.0.7/hooks/removeCart.php (added)
-
tags/1.0.7/http.php (added)
-
tags/1.0.7/js (added)
-
tags/1.0.7/js/viaads_handleEmailGuid.js (added)
-
tags/1.0.7/readme.txt (added)
-
tags/1.0.7/sync.php (added)
-
tags/1.0.7/userAgent.php (added)
-
tags/1.0.7/viaads.php (added)
-
trunk/hooks/addCart.php (modified) (1 diff)
-
trunk/hooks/pageLook.php (modified) (3 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/sync.php (modified) (27 diffs)
-
trunk/viaads.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
viaads/trunk/hooks/addCart.php
r2845940 r2846806 28 28 return; 29 29 } 30 31 30 $cookieValue = sanitize_text_field($_COOKIE[ 'ViaAds' ]); 32 31 -
viaads/trunk/hooks/pageLook.php
r2845940 r2846806 14 14 try { 15 15 //Get product 16 global $product; 17 if ( !isset( $product ) ) { 16 if ( is_product() ) { 17 global $post; 18 $product_id = $post->ID; 19 } else { 18 20 return; 19 21 } 20 $product = new WC_Product( get_page_by_path( $product, OBJECT, 'product' )->ID ); 22 $product = wc_get_product( $product_id ); 23 21 24 //guid//email//emailGuid 22 25 if(!isset($_COOKIE[ 'ViaAds' ])) { … … 46 49 $data->user_agent = $userAgent; 47 50 } 48 49 51 50 52 //ProductPageUrl … … 80 82 $date = new DateTime(); 81 83 $data->Event_date = $date->format( 'Y-m-d\TH:i:s' ); 82 83 84 84 85 ViaAds_PostToUrlEvent( "https://integration.viaads.dk/woocommerce/event", $data ); -
viaads/trunk/readme.txt
r2845940 r2846806 4 4 Requires at least: 5.4 5 5 Tested up to: 6.1 6 Stable tag: 1.0. 66 Stable tag: 1.0.7 7 7 Requires PHP: 7.0 8 8 License: GPLv3 -
viaads/trunk/sync.php
r2845940 r2846806 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 10 add_action( 'template_redirect', 'ViaAds\\ViaAds_syncData' ); 11 12 function ViaAds_syncData() { 9 defined('ABSPATH') || exit; 10 11 add_action('template_redirect', 'ViaAds\\ViaAds_syncData'); 12 13 function ViaAds_syncData() 14 { 13 15 try { 14 16 //Check if key isset 15 if ( !isset( $_GET[ 'apiKeyViabillMarketing' ] )) {17 if (!isset($_GET['apiKeyViabillMarketing'])) { 16 18 return; 17 19 } … … 19 21 //Check if key match 20 22 $name = "viaads_api_key"; 21 if ( $_GET[ 'apiKeyViabillMarketing' ] != get_option( $name )) {23 if ($_GET['apiKeyViabillMarketing'] != get_option($name)) { 22 24 return; 23 25 } 24 if ( $_GET[ 'event' ] == "webshop") {26 if ($_GET['event'] == "webshop") { 25 27 $webshop = new stdClass(); 26 28 $webshop->Type = "WooCommerce"; 27 $webshop->ApiKey = get_option( $name);29 $webshop->ApiKey = get_option($name); 28 30 $webshop->Categories = ViaAds_getCategories(); 29 31 $webshop->Products = ViaAds_getProducts(); 30 ViaAds_PostToUrl( "https://integration.viaads.dk/woocommerce/WebShopData", $webshop, true);31 } else if ( $_GET[ 'event' ] == "orders") {32 ViaAds_PostToUrl( "https://integration.viaads.dk/woocommerce/WebShopOrderData", ViaAds_getOrders(), true);32 ViaAds_PostToUrl("https://integration.viaads.dk/woocommerce/WebShopData", $webshop, true); 33 } else if ($_GET['event'] == "orders") { 34 ViaAds_PostToUrl("https://integration.viaads.dk/woocommerce/WebShopOrderData", ViaAds_getOrders(), true); 33 35 } else { 34 36 return; 35 37 } 36 } catch ( Exception $e) {38 } catch (Exception $e) { 37 39 $error_object = new stdClass(); 38 40 $error_object->Error = $e->getMessage(); 39 40 $currentPageUrl = sanitize_url( home_url( $_SERVER['REQUEST_URI'] ));41 42 $currentPageUrl = sanitize_url(home_url($_SERVER['REQUEST_URI'])); 41 43 $error_object->Url = wp_http_validate_url($currentPageUrl); 42 44 43 ViaAds_PostToUrlEvent( "https://integration.viaads.dk/error", $error_object);45 ViaAds_PostToUrlEvent("https://integration.viaads.dk/error", $error_object); 44 46 } 45 47 … … 49 51 50 52 51 function ViaAds_getProducts() { 53 function ViaAds_getProducts() 54 { 52 55 $args = array( 53 56 'orderby' => 'name', 54 57 'limit' => -1, 55 58 ); 56 $productCollection = wc_get_products( $args);59 $productCollection = wc_get_products($args); 57 60 $products = []; 58 61 59 foreach ( $productCollection as $product) {62 foreach ($productCollection as $product) { 60 63 $product_object = new stdClass(); 61 64 $product_object->WebshopProductId = $product->get_id(); … … 63 66 $imageArray = array(); 64 67 $image_object = new stdClass(); 65 $image_object->Src = get_the_post_thumbnail_url( $product->get_id());66 $image_object->Id = get_post_thumbnail_id( $product->get_id());67 if ( $image_object->Src == false) {68 $image_object->Src = get_the_post_thumbnail_url($product->get_id()); 69 $image_object->Id = get_post_thumbnail_id($product->get_id()); 70 if ($image_object->Src == false) { 68 71 $image_object->Src = ""; 69 72 } 70 array_push( $imageArray, $image_object);73 array_push($imageArray, $image_object); 71 74 $attachment_ids = $product->get_gallery_image_ids(); 72 foreach ( $attachment_ids as $attachment_id) {75 foreach ($attachment_ids as $attachment_id) { 73 76 $image_object = new stdClass(); 74 $image_object->Src = wp_get_attachment_url( $attachment_id);77 $image_object->Src = wp_get_attachment_url($attachment_id); 75 78 $image_object->Id = $attachment_id; 76 if ( $image_object->Src == false) {79 if ($image_object->Src == false) { 77 80 $image_object->Src = ""; 78 81 } 79 array_push( $imageArray, $image_object);82 array_push($imageArray, $image_object); 80 83 } 81 84 $product_object->ProductImages = $imageArray; … … 83 86 //Categories 84 87 $categories = array(); 85 foreach ( get_the_terms( $product->get_id(), 'product_cat' ) as $category) {88 foreach (get_the_terms($product->get_id(), 'product_cat') as $category) { 86 89 $category_object = new stdClass(); 87 90 $category_object->WebshopCategoryId = $category->term_id; 88 91 $category_object->Name = $category->name; 89 92 $category_object->Slug = $category->slug;; 90 array_push( $categories, $category_object);93 array_push($categories, $category_object); 91 94 } 92 95 $product_object->Categories = $categories; … … 95 98 $product_object->AverageRating = $product->get_average_rating(); 96 99 $product_object->Name = $product->get_name(); 97 $product_object->Permalink = get_permalink( $product->get_id());100 $product_object->Permalink = get_permalink($product->get_id()); 98 101 // SKU 99 102 $product_object->Sku = $product->get_sku(); 100 103 // Updated At 101 $lastModifiedGmt = new DateTime( $product->get_date_modified());102 $product_object->LastModifiedGmt = $lastModifiedGmt->format( 'c');104 $lastModifiedGmt = new DateTime($product->get_date_modified()); 105 $product_object->LastModifiedGmt = $lastModifiedGmt->format('c'); 103 106 // Created At 104 $createdAt = new DateTime( $product->get_date_created());105 $product_object->CreatedGmt = $createdAt->format( 'c');107 $createdAt = new DateTime($product->get_date_created()); 108 $product_object->CreatedGmt = $createdAt->format('c'); 106 109 // Status 107 110 $product_object->Status = $product->get_status(); … … 120 123 //Price 121 124 $product_object->price = $product->get_price(); 125 if ($product_object->price == "") { 126 $product_object->price = null; 127 } 122 128 //Regular Price 123 129 $product_object->regularPrice = $product->get_regular_price(); 124 //SalePrice 125 $product_object->salePrice = $product->get_sale_price(); 126 127 if ( $product->get_sale_price() != 0 ) { 130 if ($product_object->regularPrice == "") { 131 $product_object->regularPrice = null; 132 } 133 134 if ($product->get_sale_price() != 0) { 128 135 // On Sale 129 136 $product_object->OnSale = true; … … 131 138 $product_object->SalePrice = $product->get_sale_price(); 132 139 // On Sale From Date 133 $dateOnSaleFrom = new DateTime( $product->get_date_on_sale_from());134 $product_object->DateOnSaleFrom = $dateOnSaleFrom->format( 'c');140 $dateOnSaleFrom = new DateTime($product->get_date_on_sale_from()); 141 $product_object->DateOnSaleFrom = $dateOnSaleFrom->format('c'); 135 142 // On Sale To Date 136 $dateOnSaleTo = new DateTime( $product->get_date_on_sale_to());137 $product_object->DateOnSaleTo = $dateOnSaleTo->format( 'c');143 $dateOnSaleTo = new DateTime($product->get_date_on_sale_to()); 144 $product_object->DateOnSaleTo = $dateOnSaleTo->format('c'); 138 145 } else { 139 146 // On Sale … … 141 148 } 142 149 143 if ( $product_object->Type != 'simple') {150 if ($product_object->Type != 'simple') { 144 151 $children = $product->get_children(); 145 152 $i = 1; … … 147 154 $highestPrice; 148 155 $childs = []; 149 foreach ( $children as $childRaw) {156 foreach ($children as $childRaw) { 150 157 $child_object = new stdClass(); 151 $child = wc_get_product( $childRaw);158 $child = wc_get_product($childRaw); 152 159 153 160 // Product Id … … 162 169 $child_object->ShortDescription = $child->get_short_description(); 163 170 // Permalink 164 $child_object->Permalink = get_permalink( $child->get_id());171 $child_object->Permalink = get_permalink($child->get_id()); 165 172 // Type 166 173 $child_object->Type = $child->get_type(); … … 168 175 $child_object->Status = $child->get_status(); 169 176 // Modified At 170 $dateModified = new DateTime( $child->get_date_modified());171 $child_object->DateModified = $dateModified->format( 'c');177 $dateModified = new DateTime($child->get_date_modified()); 178 $child_object->DateModified = $dateModified->format('c'); 172 179 // Created At 173 $createdAt = new DateTime( $child->get_date_created());174 $child_object->DateCreated = $createdAt->format( 'c');180 $createdAt = new DateTime($child->get_date_created()); 181 $child_object->DateCreated = $createdAt->format('c'); 175 182 // Gets the products Final Price 176 183 $childPrice = $child->get_price(); … … 178 185 // Regular Price 179 186 $child_object->RegularPrice = $child->get_price(); 187 if ($child_object->RegularPrice == ""){ 188 $child_object->RegularPrice = null; 189 } 190 180 191 // On Sale Data 181 if ( $product->get_sale_price() != 0) {192 if ($product->get_sale_price() != 0) { 182 193 // On Sale 183 194 $child_object->OnSale = true; … … 185 196 $child_object->SalePrice = $child->get_sale_price(); 186 197 // On Sale From Date 187 $dateOnSaleFrom = new DateTime( $child->get_date_on_sale_from());188 $child_object->DateOnSaleFrom = $dateOnSaleFrom->format( 'c');198 $dateOnSaleFrom = new DateTime($child->get_date_on_sale_from()); 199 $child_object->DateOnSaleFrom = $dateOnSaleFrom->format('c'); 189 200 // On Sale To Date 190 $dateOnSaleTo = new DateTime( $child->get_date_on_sale_to());191 $child_object->DateOnSaleTo = $dateOnSaleTo->format( 'c');201 $dateOnSaleTo = new DateTime($child->get_date_on_sale_to()); 202 $child_object->DateOnSaleTo = $dateOnSaleTo->format('c'); 192 203 } else { 193 204 $child_object->OnSale = false; … … 204 215 205 216 // Getting the Lowest and the Highest price from Child (Variant) Products 206 if ( $i == 1) {217 if ($i == 1) { 207 218 $lowestPrice = $childPrice; 208 219 $highestPrice = $childPrice; 209 220 } else { 210 if ( $childPrice < $lowestPrice)221 if ($childPrice < $lowestPrice) 211 222 $lowestPrice = $childPrice; 212 if ( $childPrice > $highestPrice)223 if ($childPrice > $highestPrice) 213 224 $highestPrice = $childPrice; 214 225 } 215 226 216 array_push( $childs, $child_object);227 array_push($childs, $child_object); 217 228 $i++; 218 229 } … … 226 237 } 227 238 228 array_push( $products, $product_object);239 array_push($products, $product_object); 229 240 } 230 241 … … 232 243 } 233 244 234 function ViaAds_getCategories() { 245 function ViaAds_getCategories() 246 { 235 247 $categories = []; 236 248 … … 252 264 'hide_empty' => $empty 253 265 ); 254 $all_categories = get_categories( $args);255 foreach ( $all_categories as $cat) {266 $all_categories = get_categories($args); 267 foreach ($all_categories as $cat) { 256 268 $category_id = $cat->term_id; 257 269 $category_object = new stdClass(); … … 265 277 // Parent Id 266 278 $category_object->ParentId = $cat->parent; 267 array_push( $categories, $category_object);279 array_push($categories, $category_object); 268 280 } 269 281 return $categories; 270 282 } 271 283 272 function ViaAds_getOrders() { 273 $orderCollection = wc_get_orders( array( 274 'date_modified' => date( 'Y-m-d', strtotime( date( "Y-m-d" ) . ' - 1 days' ) ) . '...' 275 . date( 'Y-m-d', strtotime( date( "Y-m-d" ) . ' + 14 days' ) ), 276 ) ); 284 function ViaAds_getOrders() 285 { 286 $orderCollection = wc_get_orders(array( 287 'date_modified' => date('Y-m-d', strtotime(date("Y-m-d") . ' - 1 days')) . '...' 288 . date('Y-m-d', strtotime(date("Y-m-d") . ' + 14 days')), 289 )); 277 290 //Test 278 291 /*$orderCollection = wc_get_orders( array( … … 282 295 283 296 $orders = []; 284 foreach ( $orderCollection as $order) {297 foreach ($orderCollection as $order) { 285 298 $order_object = new stdClass(); 286 299 // Order Number … … 299 312 $order_object->Currency = $order->get_currency(); 300 313 // Last Modified 301 $lastModifiedGmt = new DateTime( $order->get_date_modified());302 $order_object->Last_modified = $lastModifiedGmt->format( 'c');314 $lastModifiedGmt = new DateTime($order->get_date_modified()); 315 $order_object->Last_modified = $lastModifiedGmt->format('c'); 303 316 304 317 // Billing Address … … 330 343 331 344 $orderItems = []; 332 foreach ( $order->get_items() as $item_id => $item) {345 foreach ($order->get_items() as $item_id => $item) { 333 346 $order_item_object = new stdClass(); 334 347 // Product Id … … 344 357 $order_item_object->Price = $item->get_subtotal() / $item->get_quantity(); 345 358 // Quantity 346 $order_item_object->Quantity = round( $item->get_quantity());359 $order_item_object->Quantity = round($item->get_quantity()); 347 360 // Total 348 361 //$order_item_object->Total_price = number_format( $item->get_total(), 2, ".", "" ); … … 353 366 $order_item_object->Total_price_tax_included = $item->get_total() + $item->get_total_tax(); 354 367 355 array_push( $orderItems, $order_item_object);368 array_push($orderItems, $order_item_object); 356 369 } 357 370 … … 361 374 // Final infos 362 375 $orderFinal = new stdClass(); 363 $orderFinal->ApiKey = get_option( "viaads_api_key");376 $orderFinal->ApiKey = get_option("viaads_api_key"); 364 377 $orderFinal->Shop_order = $order_object; 365 378 … … 372 385 373 386 // Order Date 374 $createdAt = new DateTime( $order->get_date_created());375 $orderFinal->Order_date = $createdAt->format( 'c');387 $createdAt = new DateTime($order->get_date_created()); 388 $orderFinal->Order_date = $createdAt->format('c'); 376 389 // Customer 377 390 $customer = new stdClass(); … … 379 392 $orderFinal->customer = $customer; 380 393 381 array_push( $orders, $orderFinal);394 array_push($orders, $orderFinal); 382 395 } 383 396 return $orders; -
viaads/trunk/viaads.php
r2845940 r2846806 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. 65 * Version: 1.0.7 6 6 * Author: ViaAds 7 7 * Author URI: https://www.viaads.dk/
Note: See TracChangeset
for help on using the changeset viewer.