Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/refactor/dashboard_products' int…
Browse files Browse the repository at this point in the history
…o module/form_manager
  • Loading branch information
nurul-umbhiya committed Dec 11, 2023
2 parents 62aa976 + fc5ff41 commit 70553c5
Show file tree
Hide file tree
Showing 43 changed files with 3,794 additions and 2,143 deletions.
64 changes: 0 additions & 64 deletions assets/src/js/product-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
$( '.dokan-product-attribute-wrapper ul.dokan-attribute-option-list' ).on( 'click', 'button.dokan-add-new-attribute', this.attribute.addNewExtraAttr );
$( '.product-edit-container .dokan-product-attribute-wrapper' ).on( 'click', 'a.dokan-product-remove-attribute', this.attribute.removeAttribute );
$( '.product-edit-container .dokan-product-attribute-wrapper' ).on( 'click', 'a.dokan-save-attribute', this.attribute.saveAttribute );
$( 'body' ).on( 'click', '.product-container-footer input[type="submit"]', this.createNewProduct );

this.attribute.disbalePredefinedAttribute();

Expand Down Expand Up @@ -340,69 +339,6 @@
$( 'body' ).trigger( 'dokan-product-editor-popup-opened', Dokan_Editor );
},

createNewProduct: function (e) {
e.preventDefault();

var self = $(this),
form = self.closest('form#dokan-add-new-product-form'),
btn_id = self.attr('data-btn_id');

form.find( 'span.dokan-show-add-product-success' ).html('');
form.find( 'span.dokan-show-add-product-error' ).html('');
form.find( 'span.dokan-add-new-product-spinner' ).css( 'display', 'inline-block' );

self.attr( 'disabled', 'disabled' );

if ( form.find( 'input[name="post_title"]' ).val() == '' ) {
$( 'span.dokan-show-add-product-error' ).html( dokan.product_title_required );
self.removeAttr( 'disabled' );
form.find( 'span.dokan-add-new-product-spinner' ).css( 'display', 'none' );
return;
}

if ( form.find( 'select[name="product_cat"]' ).val() == '-1' ) {
$( 'span.dokan-show-add-product-error' ).html( dokan.product_category_required );
self.removeAttr( 'disabled' );
form.find( 'span.dokan-add-new-product-spinner' ).css( 'display', 'none' );
return;
}

var data = {
action: 'dokan_create_new_product',
postdata: form.serialize(),
_wpnonce : dokan.nonce
};

Dokan_Editor.modal.iziModal('startLoading');
$.post( dokan.ajaxurl, data, function( resp ) {
if ( resp.success ) {
self.removeAttr( 'disabled' );
if ( btn_id === 'create_new' ) {
$( '#dokan-add-product-popup' ).iziModal('close');
window.location.href = resp.data;
} else {
product_featured_frame = undefined;
$('.dokan-dashboard-product-listing-wrapper').load( window.location.href + ' table.product-listing-table' );
Dokan_Editor.modal.iziModal('resetContent');
Dokan_Editor.openProductPopup();
Dokan_Editor.reRenderPopupElements();
$( 'span.dokan-show-add-product-success' ).html( dokan.product_created_response );

setTimeout(function() {
$( 'span.dokan-show-add-product-success' ).html( '' );
}, 3000);
}
} else {
self.removeAttr( 'disabled' );
$( 'span.dokan-show-add-product-error' ).html( resp.data );
}
form.find( 'span.dokan-add-new-product-spinner' ).css( 'display', 'none' );
})
.always( function () {
Dokan_Editor.modal.iziModal('stopLoading');
});
},

attribute: {

toggleAttribute: function(e) {
Expand Down
3 changes: 3 additions & 0 deletions dokan.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
* @property WeDevs\Dokan\Vendor\Manager $vendor Instance of Vendor Manager Class
* @property WeDevs\Dokan\BackgroundProcess\Manager $bg_process Instance of WeDevs\Dokan\BackgroundProcess\Manager class
* @property WeDevs\Dokan\Frontend\Frontend $frontend_manager Instance of \WeDevs\Dokan\Frontend\Frontend class
* @property WeDevs\Dokan\Dashboard\Manager $dashboard Instance of \WeDevs\Dokan\Dashboard\Manager class
*/
final class WeDevs_Dokan {

Expand Down Expand Up @@ -256,6 +257,7 @@ public function define_constants() {
$this->define( 'DOKAN_FILE', __FILE__ );
$this->define( 'DOKAN_DIR', __DIR__ );
$this->define( 'DOKAN_INC_DIR', __DIR__ . '/includes' );
$this->define( 'DOKAN_TEMPLATE_DIR', __DIR__ . '/templates' );
$this->define( 'DOKAN_LIB_DIR', __DIR__ . '/lib' );
$this->define( 'DOKAN_PLUGIN_ASSEST', plugins_url( 'assets', __FILE__ ) );

Expand Down Expand Up @@ -373,6 +375,7 @@ public function init_classes() {
new \WeDevs\Dokan\Vendor\UserSwitch();
new \WeDevs\Dokan\CacheInvalidate();
new \WeDevs\Dokan\Shipping\Hooks();
new \WeDevs\Dokan\ProductForm\Init();

if ( is_admin() ) {
new \WeDevs\Dokan\Admin\Hooks();
Expand Down
19 changes: 0 additions & 19 deletions includes/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,25 +557,6 @@ public function get_settings_fields() {
'default' => 'on',
'tooltip' => __( 'If checked, vendors will have permission to sell immediately after registration. If unchecked, newly registered vendors cannot add products until selling capability is activated manually from admin dashboard.', 'dokan-lite' ),
],
'one_step_product_create' => [
'name' => 'one_step_product_create',
'label' => __( 'One Page Product Creation', 'dokan-lite' ),
'desc' => __( 'Add new product in single page view', 'dokan-lite' ),
'type' => 'switcher',
'default' => 'on',
'tooltip' => __( 'If disabled, instead of a single add product page it will open a pop up window or vendor will redirect to product page when adding new product.', 'dokan-lite' ),
],
'disable_product_popup' => [
'name' => 'disable_product_popup',
'label' => __( 'Disable Product Popup', 'dokan-lite' ),
'desc' => __( 'Disable add new product in popup view', 'dokan-lite' ),
'type' => 'switcher',
'default' => 'off',
'show_if' => [
'dokan_selling.one_step_product_create' => [ 'equal' => 'off' ],
],
'tooltip' => __( 'If disabled, instead of a pop up window vendor will redirect to product page when adding new product.', 'dokan-lite' ),
],
'order_status_change' => [
'name' => 'order_status_change',
'label' => __( 'Order Status Change', 'dokan-lite' ),
Expand Down
39 changes: 0 additions & 39 deletions includes/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public function __construct() {
add_action( 'wp_ajax_dokan_seller_listing_search', [ $this, 'seller_listing_search' ] );
add_action( 'wp_ajax_nopriv_dokan_seller_listing_search', [ $this, 'seller_listing_search' ] );

add_action( 'wp_ajax_dokan_create_new_product', [ $this, 'create_product' ] );

add_action( 'wp_ajax_custom-header-crop', [ $this, 'crop_store_banner' ] );

add_action( 'wp_ajax_dokan_json_search_products_tags', [ $this, 'dokan_json_search_products_tags' ] );
Expand All @@ -57,43 +55,6 @@ public function __construct() {
add_action( 'wp_ajax_dokan-upgrade-dissmiss', [ $this, 'dismiss_pro_notice' ] );
}

/**
* Create product from popup submission
*
* @since 2.5.0
*
* @return void
*/
public function create_product() {
check_ajax_referer( 'dokan_reviews' );

if ( ! current_user_can( 'dokan_add_product' ) ) {
wp_send_json_error( __( 'You have no permission to do this action', 'dokan-lite' ) );
}

$submited_data = isset( $_POST['postdata'] ) ? wp_unslash( $_POST['postdata'] ) : ''; //phpcs:ignore

parse_str( $submited_data, $postdata );

$response = dokan_save_product( $postdata );

if ( is_wp_error( $response ) ) {
wp_send_json_error( $response->get_error_message() );
}

if ( is_int( $response ) ) {
if ( current_user_can( 'dokan_edit_product' ) ) {
$redirect = dokan_edit_product_url( $response );
} else {
$redirect = dokan_get_navigation_url( 'products' );
}

wp_send_json_success( $redirect );
} else {
wp_send_json_error( __( 'Something wrong, please try again later', 'dokan-lite' ) );
}
}

/**
* Check the availability of shop name.
*
Expand Down
2 changes: 1 addition & 1 deletion includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public function get_scripts() {
],
'dokan-util-helper' => [
'src' => $asset_url . '/js/helper.js',
'deps' => [ 'jquery', 'dokan-sweetalert2', 'moment' ],
'deps' => [ 'jquery', 'dokan-sweetalert2', 'moment', 'jquery-tiptip' ],
'version' => filemtime( $asset_path . 'js/helper.js' ),
'in_footer' => false,
],
Expand Down
2 changes: 1 addition & 1 deletion includes/Blocks/ProductBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ProductBlock {
* @return array
*/
public function get_configurations() {
$can_create_tags = dokan_get_option( 'product_vendors_can_create_tags', 'dokan_selling' );
$can_create_tags = dokan()->is_pro_exists() ? dokan_get_option( 'product_vendors_can_create_tags', 'dokan_selling', 'off' ) : 'off';

return apply_filters(
'dokan_get_product_block_configurations',
Expand Down
12 changes: 10 additions & 2 deletions includes/CatalogMode/Dashboard/ProductBulkEdit.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public function save_bulk_edit_catalog_mode_data( $status, $product_ids ) {
// loop through the products and update the status
if ( ! empty( $product_ids ) ) {
foreach ( $product_ids as $product_id ) {
// get product object
$product = wc_get_product( $product_id );
if ( ! $product ) {
continue;
}

// get existing product data
$catalog_mode_data = Helper::get_catalog_mode_data_by_product( $product_id );
$count++;
Expand All @@ -81,7 +87,7 @@ public function save_bulk_edit_catalog_mode_data( $status, $product_ids ) {
if ( Helper::hide_add_to_cart_button_option_is_enabled_by_admin() ) {
$catalog_mode_data['hide_add_to_cart_button'] = 'on';
}
// if admin didn't enabled hide product price, set this value to off
// if admin didn't enable hide product price, set this value to off
if ( ! Helper::hide_product_price_option_is_enabled_by_admin() ) {
$catalog_mode_data['hide_product_price'] = 'off';
}
Expand All @@ -92,8 +98,10 @@ public function save_bulk_edit_catalog_mode_data( $status, $product_ids ) {
$catalog_mode_data['hide_product_price'] = 'off';
break;
}

// finally save catalog mode data
update_post_meta( $product_id, '_dokan_catalog_mode', $catalog_mode_data );
$product->add_meta_data( '_dokan_catalog_mode', $catalog_mode_data, true );
$product->save();
}
}
wp_safe_redirect(
Expand Down
31 changes: 16 additions & 15 deletions includes/CatalogMode/Dashboard/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public function __construct() {
return;
}
// render catalog mode section under single product edit page
add_action( 'dokan_product_edit_after_options', [ $this, 'render_product_section' ], 99, 1 );
add_action( 'dokan_product_edit_after_options', [ $this, 'render_product_section' ], 99, 2 );
// save catalog mode section data
add_action( 'dokan_product_updated', [ $this, 'save_catalog_mode_data' ], 13 );
add_filter( 'dokan_product_edit_meta_data', [ $this, 'save_catalog_mode_data' ], 13, 1 );
}

/**
Expand All @@ -38,29 +38,28 @@ public function __construct() {
* @since 3.6.4
*
* @param $product_id int
* @param $product \WC_Product
*
* @return void
*/
public function render_product_section( $product_id ) {
public function render_product_section( $product_id, $product ) {
// check permission, don't let vendor staff view this section
if ( ! current_user_can( 'dokandar' ) ) {
return;
}

// get product data
$product = wc_get_product( $product_id );
// return if product type is optional
if ( ! $product || 'auction' === $product->get_type() ) {
// return if product type is auction
if ( 'auction' === $product->get_type() ) {
return;
}

$defaults = Helper::get_defaults();
// check for saved values
$catalog_mode_data = get_post_meta( $product_id, '_dokan_catalog_mode', true );
$catalog_mode_data = $product->get_meta( '_dokan_catalog_mode', true );

//load template
dokan_get_template_part(
'products/catalog-mode-content', '', [
'products/edit/sections/catalog-mode-content', '', [
'product_id' => $product_id,
'saved_data' => $catalog_mode_data ? $catalog_mode_data : $defaults,
]
Expand All @@ -72,17 +71,17 @@ public function render_product_section( $product_id ) {
*
* @since 3.6.4
*
* @param $product_id int
* @param array $meta_data
*
* @return void
* @return array
*/
public function save_catalog_mode_data( $product_id ) {
public function save_catalog_mode_data( array $meta_data ) {
if ( ! isset( $_POST['_dokan_catalog_mode_frontend_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['_dokan_catalog_mode_frontend_nonce'] ), 'dokan_catalog_mode_frontend' ) ) {
return;
return $meta_data;
}

if ( ! dokan_is_user_seller( dokan_get_current_user_id() ) ) {
return;
return $meta_data;
}

$catalog_mode_data = [
Expand All @@ -95,6 +94,8 @@ public function save_catalog_mode_data( $product_id ) {
$catalog_mode_data['hide_product_price'] = 'off';
}

update_post_meta( $product_id, '_dokan_catalog_mode', $catalog_mode_data );
$meta_data['_dokan_catalog_mode'] = $catalog_mode_data;

return $meta_data;
}
}
9 changes: 3 additions & 6 deletions includes/CatalogMode/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,12 @@ public static function get_catalog_mode_data_by_product( $product ) {

// get product id
if ( 'variation' === $product->get_type() ) {
$product_id = $product->get_parent_id();
} else {
$product_id = $product->get_id();
$product = wc_get_product( $product->get_parent_id() );
}

// check for saved values
$catalog_mode_data = get_post_meta( $product_id, '_dokan_catalog_mode', true );
$catalog_mode_data = is_array( $catalog_mode_data ) && ! empty( $catalog_mode_data ) ? $catalog_mode_data : $defaults;
$catalog_mode_data = $product->get_meta( '_dokan_catalog_mode', true );

return $catalog_mode_data;
return is_array( $catalog_mode_data ) && ! empty( $catalog_mode_data ) ? $catalog_mode_data : $defaults;
}
}
7 changes: 7 additions & 0 deletions includes/Dashboard/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
use WeDevs\Dokan\Dashboard\Templates\Manager as TemplateManager;
use WeDevs\Dokan\Traits\ChainableContainer;

/**
* Dashboard Manager
*
* @since 3.0.0
*
* @property TemplateManager $templates Instance of TemplateManager class
*/
class Manager {

use ChainableContainer;
Expand Down
20 changes: 13 additions & 7 deletions includes/Dashboard/Templates/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

namespace WeDevs\Dokan\Dashboard\Templates;

use WeDevs\Dokan\Dashboard\Templates\Dashboard;
use WeDevs\Dokan\Dashboard\Templates\Main;
use WeDevs\Dokan\Dashboard\Templates\Orders;
use WeDevs\Dokan\Dashboard\Templates\Products;
use WeDevs\Dokan\Dashboard\Templates\Settings;
use WeDevs\Dokan\Dashboard\Templates\Withdraw;
use WeDevs\Dokan\Dashboard\Templates\MultiStepCategories;
use WeDevs\Dokan\Traits\ChainableContainer;

/**
* Dashboard Template Manager
*
* @since 3.0.0
*
* @property Dashboard $dashboard Instance of Dashboard class
* @property Orders $orders Instance of Orders class
* @property Products $products Instance of Dashboard class
* @property Settings $settings Instance of Settings class
* @property Withdraw $withdraw Instance of Withdraw class
* @property MultiStepCategories $product_category Instance of MultiStepCategories class
* @property ReverseWithdrawal $reverse_withdrawal Instance of ReverseWithdrawal class
*/
class Manager {

use ChainableContainer;
Expand Down
Loading

0 comments on commit 70553c5

Please sign in to comment.