Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ npm-debug.log
.DS_Store
includes/.DS_Store
.idea
.vscode
/includes/.DS_Store
plugin-deploy.sh
secret.json
Expand Down
2 changes: 0 additions & 2 deletions assets/js/vue-admin.js

This file was deleted.

2 changes: 0 additions & 2 deletions assets/js/vue-bootstrap.js

This file was deleted.

25 changes: 14 additions & 11 deletions includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use WeDevs\Dokan\ProductCategory\Helper as CategoryHelper;
use WeDevs\Dokan\ReverseWithdrawal\SettingsHelper;
use WeDevs\Dokan\Utilities\OrderUtil;
use WeDevs\Dokan\ProductForm\Factory as ProductFormFactory;
use WeDevs\Dokan\Utilities\ReportUtil;

class Assets {
Expand Down Expand Up @@ -379,6 +378,11 @@ public function get_styles() {
'deps' => [ 'wp-components' ],
'version' => filemtime( DOKAN_DIR . '/assets/css/components.css' ),
],
'dokan-product-form-manager' => [
'src' => DOKAN_PLUGIN_ASSEST . '/js/form-manager.css',
'deps' => [ 'wp-components' ],
'version' => filemtime( DOKAN_DIR . '/assets/js/form-manager.css' ),
],
];

return $styles;
Expand Down Expand Up @@ -693,18 +697,18 @@ public function get_scripts() {
];
}

return $scripts;
}

public function get_product_fields() {
$temp_fields = [];
foreach ( ProductFormFactory::get_fields() as $field_id => $field ) {
$temp_fields[ $field_id ] = $field->toArray();
$product_form_manager = DOKAN_DIR . '/assets/js/form-manager.asset.php';
if ( file_exists( $product_form_manager ) ) {
$form_asset = require $product_form_manager;
$scripts['dokan-product-form-manager'] = [
'version' => $form_asset['version'],
'src' => $asset_url . '/js/form-manager.js',
'deps' => array_merge( $form_asset['dependencies'], [ 'dokan-react-components' ] ),
];
}

return json_encode( $temp_fields );
return $scripts;
}

/**
* Registers WooCommerce Admin scripts for the React-based Dokan Vendor dashboard.
*
Expand Down Expand Up @@ -784,7 +788,6 @@ public function enqueue_front_scripts() {
'currency_format' => esc_attr( str_replace( [ '%1$s', '%2$s' ], [ '%s', '%v' ], get_woocommerce_price_format() ) ), // For accounting JS
'round_at_subtotal' => get_option( 'woocommerce_tax_round_at_subtotal', 'no' ),
'product_types' => apply_filters( 'dokan_product_types', [ 'simple' ] ),
'product_form_fields' => $this->get_product_fields(),
'loading_img' => DOKAN_PLUGIN_ASSEST . '/images/loading.gif',
'store_product_search_nonce' => wp_create_nonce( 'dokan_store_product_search_nonce' ),
'i18n_download_permission' => __( 'Are you sure you want to revoke access to this download?', 'dokan-lite' ),
Expand Down
79 changes: 79 additions & 0 deletions includes/Product/FormData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace WeDevs\Dokan\Product;

class FormData {

/**
* Get product brands recursively in a flat array for dropdowns.
*
* @param int $parent_id The ID of the parent term (0 for top-level).
* @param int $level The current recursion depth for indentation.
* @param array $results Pass-by-reference array to collect data.
*
* @return array
*
* @since DOKAN_SINCE
*/
public static function get_products_brands( int $parent_id = 0, int $level = 0, array &$results = [] ): array {
$args = apply_filters(
'dokan_product_brands_args', [
'taxonomy' => 'product_brand',
'hide_empty' => 0,
'parent' => $parent_id,
'orderby' => 'name',
'order' => 'ASC',
]
);

$terms = get_terms( $args );

if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
foreach ( $terms as $term ) {
// Add to our flat results array
$results[] = [
'value' => $term->term_id,
'slug' => $term->slug,
'label' => $term->name,
'parent' => $parent_id,
];
// Recursive call to find children of this term
self::get_products_brands( $term->term_id, $level + 1, $results );
}
}

return apply_filters( 'dokan_get_products_brands_data', $results );
}

/**
* Search product tags
*
* @since DOKAN_SINCE
*
* @return array
*/
public static function get_product_tags(): array {
$drop_down_tags = apply_filters(
'dokan_product_tags_args', [
'taxonomy' => 'product_tag',
'hide_empty' => 0,
'orderby' => 'name',
'order' => 'ASC',
]
);

$data = [];
$product_tags = get_terms( $drop_down_tags );
if ( $product_tags ) {
foreach ( $product_tags as $term ) {
$data[] = [
'value' => $term->term_id,
'slug' => $term->slug,
'label' => $term->name,
];
}
}

return $data;
}
}
5 changes: 5 additions & 0 deletions includes/Product/Hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function __construct() {
add_action( 'woocommerce_product_options_advanced', array( $this, 'add_per_product_commission_options' ), 15 );
add_action( 'woocommerce_process_product_meta_simple', array( $this, 'save_per_product_commission_options' ), 15 );
add_action( 'woocommerce_process_product_meta_variable', array( $this, 'save_per_product_commission_options' ), 15 );
add_action( 'dokan_product_content_inside_area_before', [ $this, 'load_react_template' ] );
}

public function load_react_template() {
echo '<div id="product-form-manager-template"></div>';
}

/**
Expand Down
58 changes: 58 additions & 0 deletions includes/ProductForm/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ abstract class Component {
'title' => '', // label for the field
'description' => '', // description of the field
'help_content' => '', // help content for the field
'left_icon' => '', // left icon for the field
'tooltip' => '', // tooltip content for the field
'visibility' => true, // field visibility, if the field is visible under frontend
'required' => false, // by default, all fields are not required
'dependency_condition' => [], // dependency condition for the field
Expand Down Expand Up @@ -178,6 +180,62 @@ public function set_help_content( string $help_content ): self {
return $this;
}

/**
* Get field left icon
*
* @since DOKAN_SINCE
*
* @return string
*/
public function get_left_icon(): string {
return $this->data['left_icon'];
}

/**
* Set field left icon, validated with
*
* @since DOKAN_SINCE
*
* @param string $left_icon
*
* @see wp_kses_post()
*
* @return $this
*/
public function set_left_icon( string $left_icon ): self {
$this->data['left_icon'] = wp_kses_post( $left_icon );

return $this;
}

/**
* Get field tooltip content
*
* @since DOKAN_SINCE
*
* @return string
*/
public function get_tooltip(): string {
return $this->data['tooltip'];
}

/**
* Set field tooltip content, validated with
*
* @since DOKAN_SINCE
*
* @param string $tooltip
*
* @see wp_kses_post()
*
* @return $this
*/
public function set_tooltip( string $tooltip ): self {
$this->data['tooltip'] = wp_kses_post( $tooltip );

return $this;
}

/**
* Get field visibility
*
Expand Down
2 changes: 2 additions & 0 deletions includes/ProductForm/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Elements {
const CROSS_SELL_IDS = 'cross_sell_ids';
const CATEGORIES = 'category_ids';
const TAGS = 'tag_ids';
const BRANDS = 'brand_ids';
const DOWNLOADABLE = 'downloadable';
const DOWNLOADS = 'downloads';
const DOWNLOAD_LIMIT = 'download_limit';
Expand All @@ -75,4 +76,5 @@ class Elements {
const ADDITIONAL_SHIPPING_COST_META = '_additional_price';
const ADDITIONAL_SHIPPING_QUANTITY_META = '_additional_qty';
const ADDITIONAL_SHIPPING_PROCESSING_TIME_META = '_dps_processing_time';
const CREATE_SCHEDULE_FOR_DISCOUNT = '_create_schedule_for_discount';
}
1 change: 1 addition & 0 deletions includes/ProductForm/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Factory {
* 'additional_args' => [], // (array) additional arguments for the field
* 'description' => '', // (string) description of the field
* 'help_content' => '', // (string) help content for the field
* 'tooltip' => '', // (string) tooltip content for the field
* 'visibility' => true, // (bool) field visibility, if the field is visible under frontend
* 'required' => false, // (bool) by default, all fields are not required
* 'order' => 30, // (int) field order
Expand Down
Loading
Loading