Skip to content

Commit

Permalink
Merge pull request #82 from bfiessinger/feature/woocommerce-analytics…
Browse files Browse the repository at this point in the history
…-integration

add integration for woocommerce admin
  • Loading branch information
Codexshaper authored Sep 25, 2022
2 parents dbb2c58 + ddb0b7b commit 951ddb8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"Variation": "Codexshaper\\WooCommerce\\Models\\Variation",
"Webhook": "Codexshaper\\WooCommerce\\Facades\\Webhook",
"WooCommerce": "Codexshaper\\WooCommerce\\Facades\\WooCommerce",
"WooAnalytics": "Codexshaper\\WooCommerce\\Facades\\WooAnalytics",
"Query": "Codexshaper\\WooCommerce\\Facades\\Query"
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/Facades/WooAnalytics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Codexshaper\WooCommerce\Facades;

use Codexshaper\WooCommerce\WooCommerceAnalyticsApi;
use Illuminate\Support\Facades\Facade;

class WooAnalytics extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return WooCommerceAnalyticsApi::class;
}
}
51 changes: 51 additions & 0 deletions src/WooCommerceAnalyticsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace Codexshaper\WooCommerce;

use Automattic\WooCommerce\Client;
use Codexshaper\WooCommerce\Traits\WooCommerceTrait;

class WooCommerceAnalyticsApi
{
use WooCommerceTrait;

/**
*@var \Automattic\WooCommerce\Client
*/
protected $client;

/**
*@var array
*/
protected $headers = [];

/**
* Build Woocommerce connection.
*
* @return void
*/
public function __construct()
{
try {
$this->headers = [
'header_total' => config('woocommerce.header_total') ?? 'X-WP-Total',
'header_total_pages' => config('woocommerce.header_total_pages') ?? 'X-WP-TotalPages',
];

$this->client = new Client(
config('woocommerce.store_url'),
config('woocommerce.consumer_key'),
config('woocommerce.consumer_secret'),
[
'version' => 'wc-analytics',
'wp_api' => config('woocommerce.wp_api_integration'),
'verify_ssl' => config('woocommerce.verify_ssl'),
'query_string_auth' => config('woocommerce.query_string_auth'),
'timeout' => config('woocommerce.timeout'),
]
);
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 1);
}
}
}

0 comments on commit 951ddb8

Please sign in to comment.