Skip to content

Commit

Permalink
Merge branch 'develop' into livechat
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatahalder01 committed Nov 1, 2024
2 parents 5a668fd + f31aa2c commit 79424a0
Show file tree
Hide file tree
Showing 24 changed files with 527 additions and 122 deletions.
6 changes: 0 additions & 6 deletions assets/src/js/dokan-admin-analytics.js

This file was deleted.

14 changes: 7 additions & 7 deletions dokan-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class WeDevs_Dokan {
*
* @var string
*/
public $version = '3.11.3';
public $version = '3.12.6';

/**
* Instance of self
Expand Down Expand Up @@ -133,7 +133,7 @@ public function is_supported_php() {
* @return string
*/
public function plugin_path() {
return untrailingslashit( plugin_dir_path( __FILE__ ) );
return untrailingslashit( plugin_dir_path( DOKAN_FILE ) );
}

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ public function deactivate() {
* @uses load_plugin_textdomain()
*/
public function localization_setup() {
load_plugin_textdomain( 'dokan-lite', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
load_plugin_textdomain( 'dokan-lite', false, dirname( plugin_basename( DOKAN_FILE ) ) . '/languages/' );
}

/**
Expand All @@ -215,7 +215,7 @@ public function define_constants() {
defined( 'DOKAN_DIR' ) || define( 'DOKAN_DIR', __DIR__ );
defined( 'DOKAN_INC_DIR' ) || define( 'DOKAN_INC_DIR', __DIR__ . '/includes' );
defined( 'DOKAN_LIB_DIR' ) || define( 'DOKAN_LIB_DIR', __DIR__ . '/lib' );
defined( 'DOKAN_PLUGIN_ASSEST' ) || define( 'DOKAN_PLUGIN_ASSEST', plugins_url( 'assets', __FILE__ ) );
defined( 'DOKAN_PLUGIN_ASSEST' ) || define( 'DOKAN_PLUGIN_ASSEST', plugins_url( 'assets', DOKAN_FILE ) );

// give a way to turn off loading styles and scripts from parent theme
defined( 'DOKAN_LOAD_STYLE' ) || define( 'DOKAN_LOAD_STYLE', true );
Expand All @@ -231,8 +231,8 @@ public function define_constants() {
*/
public function declare_woocommerce_feature_compatibility() {
if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', DOKAN_FILE, true );
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', DOKAN_FILE, true );
}
}

Expand Down Expand Up @@ -263,7 +263,7 @@ public function init_hooks() {

add_action( 'plugins_loaded', [ $this, 'after_plugins_loaded' ] );

add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), [ $this, 'plugin_action_links' ] );
add_filter( 'plugin_action_links_' . plugin_basename( DOKAN_FILE ), [ $this, 'plugin_action_links' ] );
add_action( 'in_plugin_update_message-dokan-lite/dokan.php', [ \WeDevs\Dokan\Install\Installer::class, 'in_plugin_update_message' ] );

add_action( 'widgets_init', [ $this, 'register_widgets' ] );
Expand Down
77 changes: 64 additions & 13 deletions includes/Analytics/Reports/Orders/Stats/QueryFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WeDevs\Dokan\Analytics\Reports\Orders\Stats;

use WeDevs\Dokan\Analytics\Reports\Orders\QueryFilter as OrdersQueryFilter;
use WeDevs\Dokan\Analytics\Reports\OrderType;

/**
* Class QueryFilter
Expand All @@ -29,8 +30,11 @@ public function register_hooks(): void {
add_filter( 'woocommerce_analytics_clauses_join_orders_stats_total', [ $this, 'add_join_subquery' ] );
add_filter( 'woocommerce_analytics_clauses_join_orders_stats_interval', [ $this, 'add_join_subquery' ] );

add_filter( 'woocommerce_analytics_clauses_where_orders_stats_total', [ $this, 'add_where_subquery' ], 30 );
add_filter( 'woocommerce_analytics_clauses_where_orders_stats_interval', [ $this, 'add_where_subquery' ], 30 );
// add_filter( 'woocommerce_analytics_clauses_where_orders_stats_total', [ $this, 'add_where_subquery' ], 30 );
// add_filter( 'woocommerce_analytics_clauses_where_orders_stats_interval', [ $this, 'add_where_subquery' ], 30 );

add_filter( 'woocommerce_analytics_clauses_where_orders_stats_total', [ $this, 'add_where_subquery_for_vendor_filter' ], 30 );
add_filter( 'woocommerce_analytics_clauses_where_orders_stats_interval', [ $this, 'add_where_subquery_for_vendor_filter' ], 30 );

add_filter( 'woocommerce_analytics_clauses_select_orders_stats_total', [ $this, 'add_select_subquery_for_total' ] );
add_filter( 'woocommerce_analytics_clauses_select_orders_stats_interval', [ $this, 'add_select_subquery_for_total' ] );
Expand All @@ -51,21 +55,61 @@ public function register_hooks(): void {
*
* @return array Modified report columns.
*/
public function modify_admin_report_columns( array $column, string $context, string $wc_table_name ): array {
public function modify_admin_report_columns( array $column, string $context, string $table_name ): array {
if ( $context !== $this->context ) {
return $column;
}

$table_name = $this->get_dokan_table();
$types = $this->get_order_types_for_sql_excluding_refunds();

$order_count = "SUM( CASE WHEN {$table_name}.order_type IN($types) THEN 1 ELSE 0 END )";

$column['orders_count'] = "{$order_count} as orders_count";
$column['avg_items_per_order'] = "SUM( {$wc_table_name}.num_items_sold ) / {$order_count} AS avg_items_per_order";
$column['avg_order_value'] = "SUM( {$wc_table_name}.net_total ) / {$order_count} AS avg_order_value";
$column['avg_admin_commission'] = "SUM( {$table_name}.admin_commission ) / {$order_count} AS avg_admin_commission";
$column['avg_vendor_earning'] = "SUM( {$table_name}.vendor_earning ) / {$order_count} AS avg_vendor_earning";
$dokan_table_name = $this->get_dokan_table();
$order_types = $this->get_order_types_for_sql_excluding_refunds();
$types = implode( ',', ( new OrderType() )->get_vendor_order_types() );
// $types = $this->get_order_types_for_sql_excluding_refunds();

$parent_order_types_str = implode( ',', ( new OrderType() )->get_admin_order_types_excluding_refunds() );
$refund_order_types_str = implode( ',', ( new OrderType() )->get_vendor_refund_types() );

$order_count = "SUM( CASE WHEN {$dokan_table_name}.order_type IN($order_types) THEN 1 ELSE 0 END )";

/**
* Override WC column.
*
* We can apply the common where clause after Dokan Coupon Distribution.
* File to restore: @see https://github.com/getdokan/dokan/blob/2cffa360a94b32033e7591fece5950068ab758f5/includes/Analytics/Reports/Orders/Stats/QueryFilter.php#L4
*/
$coupon = "SUM(CASE WHEN {$dokan_table_name}.order_type IN($parent_order_types_str) THEN discount_amount END)";

$net_total = "SUM(CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$table_name}.net_total END)";

$item_sold = "SUM( CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$table_name}.num_items_sold END)";

$refunds = "ABS( SUM( CASE WHEN {$table_name}.net_total < 0 AND {$dokan_table_name}.order_type IN($refund_order_types_str) THEN {$table_name}.net_total ELSE 0 END ) )";

$gross_sales =
"( SUM( CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$table_name}.total_sales END )" .
" + COALESCE( $coupon, 0 )" . // SUM() all nulls gives null.
" - SUM(CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$table_name}.tax_total END)" .
" - SUM(CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$table_name}.shipping_total END)" .
" + {$refunds}" .
' ) as gross_sales';

$column['num_items_sold'] = "$item_sold as num_items_sold";
$column['gross_sales'] = $gross_sales;
$column['total_sales'] = "SUM( CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$table_name}.total_sales END) AS total_sales";
$column['coupons'] = "COALESCE( $coupon, 0 ) AS coupons"; // SUM() all nulls gives null;
$column['coupons_count'] = 'COALESCE( coupons_count, 0 ) as coupons_count';
$column['refunds'] = "{$refunds} AS refunds";
$column['taxes'] = "SUM(CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$table_name}.tax_total END) AS taxes";
$column['shipping'] = "SUM(CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$table_name}.shipping_total END) AS shipping";
$column['net_revenue'] = " $net_total AS net_revenue";
$column['total_customers'] = "COUNT( DISTINCT( {$table_name}.customer_id ) ) as total_customers";
// End of override

$column['orders_count'] = "{$order_count} as orders_count";

$column['avg_items_per_order'] = "{$item_sold} / {$order_count} AS avg_items_per_order";
$column['avg_order_value'] = "{$net_total} / {$order_count} AS avg_order_value";
$column['avg_admin_commission'] = "SUM( CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$dokan_table_name}.admin_commission END) / {$order_count} AS avg_admin_commission";
$column['avg_vendor_earning'] = "SUM( CASE WHEN {$dokan_table_name}.order_type IN($types) THEN {$dokan_table_name}.vendor_earning END) / {$order_count} AS avg_vendor_earning";

return $column;
}
Expand All @@ -87,4 +131,11 @@ public function add_select_subquery_for_total( $clauses ) {

return $clauses;
}

/**
* @inheritDoc
*/
public function add_where_subquery_for_vendor_filter( array $clauses ): array {
return parent::add_where_subquery_for_vendor_filter( $clauses );
}
}
8 changes: 0 additions & 8 deletions includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,6 @@ public function enqueue_admin_scripts( $hook ) {
wp_localize_script( 'dokan-admin-product', 'dokan_admin_product', $this->admin_product_localize_scripts() );
}

// Load admin scripts for analytics.
wp_enqueue_script( 'dokan-admin-analytics' );

do_action( 'dokan_enqueue_admin_scripts', $hook );
}

Expand Down Expand Up @@ -557,11 +554,6 @@ public function get_scripts() {
'deps' => [ 'jquery' ],
'version' => filemtime( $asset_path . 'js/dokan-frontend.js' ),
],
'dokan-admin-analytics' => [
'src' => $asset_url . '/js/dokan-admin-analytics.js',
'deps' => [ 'wc-admin-app', 'wp-hooks' ],
'version' => filemtime( $asset_path . 'js/dokan-admin-analytics.js' ),
],
];

return $scripts;
Expand Down
10 changes: 8 additions & 2 deletions tests/pw/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ VENDOR=David_Johnson [Vendor username]
VENDOR2=jhonathon_Smith [Vendor username]
CUSTOMER=Michael_Williams [Customer username]
USER_PASSWORD=Passw0rd123 [Password for all other users]
GMAP=ABCD1234EFGH5678 [Google Maps API key]
LICENSE_KEY=ABCD1234EFGH5678 [Dokan License key]
DOKAN_PRO=true [Dokan pro active status]
GMAP=map_key [Google Maps API key]
LICENSE_KEY=licence_key [Dokan License key]
TALKJS_APP_ID=talkjs_app_id [TalkJS App ID]
TALKJS_APP_SECRET=talkjs_app_secret [TalkJS App Secret]
VONAGE_API_KEY=vonage_key [Vonage SMS API key]
VONAGE_API_SECRET=vonage_secret [Vonage SMS API secret]
FB_APP_ID=facebook_app_id [Facebook App ID]
FB_APP_SECRET=facebook_app_secret [Facebook App secret]

# Playwright Configuration
BASE_URL=https://example.com [Base URL of the test site]
Expand Down
20 changes: 12 additions & 8 deletions tests/pw/feature-map/feature-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,13 @@
admin can set Dokan page settings [lite]: true
admin can set Dokan appearance settings [lite]: true
admin can set Dokan privacy policy settings [lite]: true
admin can set Dokan color settings: true
admin can set Dokan colors settings: true
admin can set Dokan vendor verification settings: true
admin can set Dokan verification sms gateways settings: true
admin can set Dokan live search settings: true
admin can set Dokan store support settings: true
admin can set Dokan email verification settings: true
admin can set Dokan social api settings: true
admin can set Dokan shipping status settings: true
admin can set Dokan quote settings: true
admin can set Dokan live chat settings: true
Expand All @@ -503,7 +506,7 @@
admin can check for duplicate orders: true
admin can set Dokan setup wizard [lite]: true
admin can regenerate variable product variations author IDs: true
admin can import dummy data: false
admin can import dummy data: true
admin can clear dummy data: true
admin can test distance matrix API: true

Expand Down Expand Up @@ -596,7 +599,7 @@
vendor can approve product review: true
vendor can restore trashed product review: true
vendor can permanently-delete product review: true
vendor can perform bulk action on product reviews: false
vendor can perform bulk action on product reviews: true

- page: 'MenuManager'
features:
Expand Down Expand Up @@ -775,12 +778,13 @@

- page: 'Live Search'
features:
admin:
admin can set live search options: false
admin can add live search widget: false
# admin:
# admin can set Dokan live search settings [duplicate]: true
customer:
customer can search product using live search - suggestion box: false
customer can search product using live search - autoload content: false
customer can search product using live search (suggestion box): true
customer can search product with category using live search (suggestion box): true
customer can search product using live search (autoload content): true
customer can search product with category using live search (autoload content): true

- page: 'MangoPay'
features:
Expand Down
20 changes: 18 additions & 2 deletions tests/pw/pages/basePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,22 @@ export class BasePage {
return response;
}

// type & wait for loadState
async typeByPageAndWaitForLoadState(selector: string, text: string, clear = true): Promise<void> {
if (clear) await this.clearInputField(selector);
await Promise.all([this.waitForLoadState(), this.page.locator(selector).pressSequentially(text, { delay: 200 })]);
}

// type & wait for response
async typeByPageAndWaitForResponse(subUrl: string, selector: string, text: string, code = 200): Promise<Response> {
async typeByPageAndWaitForResponse(subUrl: string, selector: string, text: string, code = 200, clear = true): Promise<Response> {
if (clear) await this.clearInputField(selector);
const [response] = await Promise.all([this.page.waitForResponse(resp => resp.url().includes(subUrl) && resp.status() === code), this.page.locator(selector).pressSequentially(text, { delay: 200 })]);
return response;
}
// type & wait for loadState
async typeAndWaitForLoadState(selector: string, text: string): Promise<void> {
await Promise.all([this.waitForLoadState(), this.clearAndFill(selector, text)]);
}

// type & wait for response
async typeAndWaitForResponse(subUrl: string, selector: string, text: string, code = 200): Promise<Response> {
Expand Down Expand Up @@ -683,7 +694,7 @@ export class BasePage {

// clear input field
async clearInputField(selector: string): Promise<void> {
await this.page.fill(selector, '');
await this.page.locator(selector).fill('');
}

// Or
Expand Down Expand Up @@ -823,6 +834,11 @@ export class BasePage {
return await this.page.selectOption(selector, { index: Number(value) });
}

// select by value and wait for loadState
async selectByValueAndWaitForLoadState(selector: string, value: string, state: 'load' | 'domcontentloaded' | 'networkidle' = 'domcontentloaded'): Promise<void> {
await Promise.all([this.waitForLoadState(state), this.page.selectOption(selector, { value })]);
}

// select by value and wait for response
async selectByValueAndWaitForResponse(subUrl: string, selector: string, value: string, code = 200): Promise<Response> {
const [response] = await Promise.all([this.page.waitForResponse(resp => resp.url().includes(subUrl) && resp.status() === code), this.page.selectOption(selector, { value })]);
Expand Down
2 changes: 1 addition & 1 deletion tests/pw/pages/couponsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class CouponsPage extends AdminPage {
// add marketplace coupon
async addMarketplaceCoupon(coupon: coupon) {
await this.goIfNotThere(data.subUrls.backend.wc.addCoupon);
await this.setElementCssStyle('div.woocommerce-layout__header', 'display', 'none'); //todo: remove this when woocommerce header can be disabled

await this.clearAndType(couponsAdmin.addNewCoupon.couponCode, coupon.title);
await this.clearAndType(couponsAdmin.addNewCoupon.couponDescription, coupon.description);
Expand All @@ -30,7 +31,6 @@ export class CouponsPage extends AdminPage {
await this.check(couponsAdmin.addNewCoupon.enableForAllVendors);
await this.check(couponsAdmin.addNewCoupon.showOnStores);
await this.check(couponsAdmin.addNewCoupon.notifyVendors);
await this.scrollToTop();
await this.clickAndWaitForResponseAndLoadState(data.subUrls.post, couponsAdmin.addNewCoupon.publish);
await this.toContainText(couponsAdmin.addNewCoupon.publishSuccessMessage, 'Coupon updated.');
}
Expand Down
30 changes: 30 additions & 0 deletions tests/pw/pages/liveSearchPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Page } from '@playwright/test';
import { BasePage } from '@pages/basePage';
import { selector } from '@pages/selectors';
import { data } from '@utils/testData';

// selectors
const liveSearchCustomer = selector.customer.cLiveSearch;

export class LiveSearch extends BasePage {
constructor(page: Page) {
super(page);
}

async searchByLiveSearch(productName: string, autoload = false, categoryName?: string) {
await this.gotoUntilNetworkidle(data.subUrls.frontend.myAccount);

if (!autoload) {
if (categoryName) await this.selectByValueAndWaitForResponse(data.subUrls.ajax, liveSearchCustomer.liveSearchCategory, categoryName.toLowerCase());
await this.fill(liveSearchCustomer.liveSearchInput, productName); // to reduce type time
await this.typeByPageAndWaitForResponse(data.subUrls.ajax, liveSearchCustomer.liveSearchInput, ' ', 200, false);
await this.toBeVisible(liveSearchCustomer.searchedResult(productName));
if (categoryName) await this.toBeVisible(liveSearchCustomer.searchResultWithCategory(productName, categoryName));
} else {
if (categoryName) await this.selectByValueAndWaitForLoadState(liveSearchCustomer.liveSearchCategory, categoryName.toLowerCase());
await this.fill(liveSearchCustomer.liveSearchInput, productName); // to reduce type time
await this.typeByPageAndWaitForLoadState(liveSearchCustomer.liveSearchInput, ' ', false);
await this.toBeVisible(selector.customer.cShop.productTitleByName(productName));
}
}
}
Loading

0 comments on commit 79424a0

Please sign in to comment.