Skip to content

Commit

Permalink
Merge branch 'release/3.13.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Aunshon committed Oct 30, 2024
2 parents a9655bf + 3354c1d commit 2a03d90
Show file tree
Hide file tree
Showing 108 changed files with 6,232 additions and 767 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
**WC requires at least:** 8.0.0
**WC tested up to:** 9.3.3
**Requires PHP:** 7.4
**Stable tag:** 3.12.6
**Stable tag:** 3.13.0
**License:** GPLv2 or later
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -347,6 +347,11 @@ A. Just install and activate the PRO version without deleting the free plugin. A

## Changelog ##

### v3.13.0 ( Oct 28, 2024 ) ###

- **feat:** Replaced the Dokan array container with the League Container, ensuring backward compatibility for seamless performance and enhanced flexibility.
- **feat:** Updated Dokan to be fully compatible with WooCommerce Analytics Reports

### v3.12.6 ( Oct 24, 2024 ) ###

- **fix:** Fixed js error on frontend pages.
Expand Down
7 changes: 6 additions & 1 deletion appsero.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"package.json",
".php_cs",
".babelrc",
".editorconfig"
".editorconfig",
".eslintrc",
"postcss.config.js",
"webpack.config.js",
"tailwind.config.js",
".prettierrc.js"
]
}
1 change: 1 addition & 0 deletions assets/js/dokan-admin-analytics.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php return array('dependencies' => array(), 'version' => '33fd710a64e86a40d022');
1 change: 1 addition & 0 deletions assets/js/dokan-admin-analytics.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/version-replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const pluginFiles = [
'templates/**/*',
'src/**/*',
'dokan.php',
'dokan-class.php',
'uninstall.php',
];

Expand Down
1 change: 1 addition & 0 deletions bin/zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const pluginFiles = [
'CHANGELOG.md',
'readme.txt',
'dokan.php',
'dokan-class.php',
'uninstall.php',
'composer.json',
];
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
},
"autoload": {
"psr-4": {
"WeDevs\\Dokan\\": "includes/"
"WeDevs\\Dokan\\": "includes/",
"WeDevs\\Dokan\\ThirdParty\\Packages\\": "lib/packages/"
},
"files": [
"includes/functions-rest-api.php",
Expand Down
19 changes: 19 additions & 0 deletions docs/analytics/reports.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- [Introduction](#introduction)
- [Custom Products Stats Datastore](#custom-products-stats-datastore)

## Introduction
To handle **Dokan Orders**, we followed the [WooCommerce Admin Reports Extension Guidelines](https://github.com/woocommerce/woocommerce/blob/trunk/docs/reporting/extending-woocommerce-admin-reports.md#handle-currency-parameters-on-the-server).

## Custom Stats Datastore

We need to customize the default *WooCommerce Analytics Datastore* for some reports. For example, we replaced the [WC Products Stats DataStore](https://github.com/woocommerce/woocommerce/blob/9297409c5a705d1cd0ae65ec9b058271bd90851e/plugins/woocommerce/src/Admin/API/Reports/Products/Stats/DataStore.php#L170) with the [Dokan Product Stats Store](./../../includes/Analytics/Reports/Products/Stats/WcDataStore.php). This modification involves overriding the `$total_query` and `$interval_query` properties by substituting the `Automattic\WooCommerce\Admin\API\Reports\SqlQuery` class with `WeDevs\Dokan\Analytics\Reports\WcSqlQuery`.

The primary change was to update the `get_sql_clause( $type, $handling = 'unfiltered' )` method to `get_sql_clause( $type, $handling = '' )`, allowing us to apply necessary filters for adding JOIN and WHERE clauses to the `dokan_order_stats` table.

### Implementation Steps

- **Step 1:** Create the [WcSqlQuery](./../../includes/Analytics/Reports/DataStoreModifier.php) class to override the `get_sql_clause( $type, $handling = 'unfiltered' )` method from the [WC SqlQuery](https://github.com/woocommerce/woocommerce/blob/9297409c5a705d1cd0ae65ec9b058271bd90851e/plugins/woocommerce/src/Admin/API/Reports/SqlQuery.php#L87) class. The new method should use `get_sql_clause( $type, $handling = '' )`.

- **Step 2:** Implement the [WcDataStore](https://github.com/woocommerce/woocommerce/blob/9297409c5a705d1cd0ae65ec9b058271bd90851e/plugins/woocommerce/src/Admin/API/Reports/Products/Stats/DataStore.php#L170) class to set the `$total_query` and `$interval_query` properties with instance of **WcSqlQuery**.

- **Step 3:** Use the `woocommerce_data_stores` filter within the [DataStoreModifier](./../../includes/Analytics/Reports/DataStoreModifier.php) class to replace the default WooCommerce Products Stats datastore with the custom Dokan Product Stats Store.
129 changes: 129 additions & 0 deletions docs/container.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
## Container Documentation

- [Register Service Provider](#register-service-provider)
- [Register Services in the Service Provider](#register-services-in-the-service-provider)
- [Add Services to the Container](#add-services-to-the-container)
- [Get Service from the Container](#get-service-from-the-container)
- [Override the Existing Service](#override-the-existing-service)
- [Check if a Service is Registered](#check-service-is-registered-or-not)

### Register Service Provider

1. **Step 1:** Create a service provider inside `includes/DependencyManagement/Providers` that extends `WeDevs\Dokan\DependencyManagement\BaseServiceProvider`.
2. **Step 2:** Register the service provider in the `boot` method of `includes/DependencyManagement/Providers/ServiceProvider.php`.

You can see the already registered service providers inside the `boot` method of the [ServiceProvider](./../includes/DependencyManagement/Providers/ServiceProvider.php#L46) class.

### Register Services in the Service Provider

1. **Step 1:** Register the services inside the `register` method of your service provider.
2. **Step 2:** Implement a `provides` method that returns `true` or `false` when the container invokes it with a service name.

```php
namespace WeDevs\Dokan\DependencyManagement\Providers;

use WeDevs\Dokan\DependencyManagement\BaseServiceProvider;

class SomeServiceProvider extends BaseServiceProvider
{
/**
* The provides method lets the container know
* which services are provided by this provider.
* The alias must be added to this array or it will
* be ignored.
*/
public function provides(string $id): bool
{
$services = [
'key',
Some\Controller::class,
Some\Model::class,
Some\Request::class,
];

return in_array($id, $services);
}

/**
* The register method defines services in the container.
* Services must have an alias in the `provides` method
* or they will be ignored.
*/
public function register(): void
{
$this->getContainer()->add('key', 'value');

$this->getContainer()
->add(Some\Controller::class)
->addArgument(Some\Request::class)
->addArgument(Some\Model::class);

$this->getContainer()->add(Some\Request::class);
$this->getContainer()->add(Some\Model::class);
}
}
```

### Add Services to the Container

- Add a service:

```php
$this->getContainer()->add(ServiceClass::class);
```

- Add a shared service (one instance per request lifecycle):

```php
$this->getContainer()->addShared(ServiceClass::class);
```

- Add a service with constructor parameters:

```php
$this->getContainer()->addShared(ServiceClass::class, function () {
return new ServiceClass($params);
});
```

- Add a shared service with constructor parameters and tag it:

```php
$this->getContainer()->addShared(ServiceClass::class, function () {
return new ServiceClass($params);
})->addTag('tag_name');
```

- Add a service and tag all implemented interfaces:

```php
$this->getContainer()->share_with_implements_tags(ServiceClass::class);
```

### Get Service from the Container

- Get a single instance:

```php
$service = dokan()->get_container()->get(ServiceClass::class);
```

- Get an array of instances by tag:

```php
$service_list = dokan()->get_container()->get('tag-name');
```

### Override the Existing Service

```php
dokan()->get_container()->extend(ServiceClass::class)->setConcrete(new OtherServiceClass());
```

### Check if a Service is Registered

```php
$is_registered = dokan()->get_container()->has(ServiceClass::class);
```

For more details, visit the [League Container documentation](https://container.thephpleague.com/4.x/service-providers).
Loading

0 comments on commit 2a03d90

Please sign in to comment.