Skip to content

Commit 951ddb8

Browse files
authored
Merge pull request #82 from bfiessinger/feature/woocommerce-analytics-integration
add integration for woocommerce admin
2 parents dbb2c58 + ddb0b7b commit 951ddb8

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"Variation": "Codexshaper\\WooCommerce\\Models\\Variation",
6161
"Webhook": "Codexshaper\\WooCommerce\\Facades\\Webhook",
6262
"WooCommerce": "Codexshaper\\WooCommerce\\Facades\\WooCommerce",
63+
"WooAnalytics": "Codexshaper\\WooCommerce\\Facades\\WooAnalytics",
6364
"Query": "Codexshaper\\WooCommerce\\Facades\\Query"
6465
}
6566
}

src/Facades/WooAnalytics.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Codexshaper\WooCommerce\Facades;
4+
5+
use Codexshaper\WooCommerce\WooCommerceAnalyticsApi;
6+
use Illuminate\Support\Facades\Facade;
7+
8+
class WooAnalytics extends Facade
9+
{
10+
/**
11+
* Get the registered name of the component.
12+
*
13+
* @return string
14+
*/
15+
protected static function getFacadeAccessor()
16+
{
17+
return WooCommerceAnalyticsApi::class;
18+
}
19+
}

src/WooCommerceAnalyticsApi.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Codexshaper\WooCommerce;
4+
5+
use Automattic\WooCommerce\Client;
6+
use Codexshaper\WooCommerce\Traits\WooCommerceTrait;
7+
8+
class WooCommerceAnalyticsApi
9+
{
10+
use WooCommerceTrait;
11+
12+
/**
13+
*@var \Automattic\WooCommerce\Client
14+
*/
15+
protected $client;
16+
17+
/**
18+
*@var array
19+
*/
20+
protected $headers = [];
21+
22+
/**
23+
* Build Woocommerce connection.
24+
*
25+
* @return void
26+
*/
27+
public function __construct()
28+
{
29+
try {
30+
$this->headers = [
31+
'header_total' => config('woocommerce.header_total') ?? 'X-WP-Total',
32+
'header_total_pages' => config('woocommerce.header_total_pages') ?? 'X-WP-TotalPages',
33+
];
34+
35+
$this->client = new Client(
36+
config('woocommerce.store_url'),
37+
config('woocommerce.consumer_key'),
38+
config('woocommerce.consumer_secret'),
39+
[
40+
'version' => 'wc-analytics',
41+
'wp_api' => config('woocommerce.wp_api_integration'),
42+
'verify_ssl' => config('woocommerce.verify_ssl'),
43+
'query_string_auth' => config('woocommerce.query_string_auth'),
44+
'timeout' => config('woocommerce.timeout'),
45+
]
46+
);
47+
} catch (\Exception $e) {
48+
throw new \Exception($e->getMessage(), 1);
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)