Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single Product Page and Product Edit Page Enhancements #1986

Merged
merged 54 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
47e430b
update: Admin settings change
shohag121 Jun 9, 2023
38b3907
update: One-step product add
shohag121 Jun 9, 2023
9879bbc
fix: One-step product url fix
shohag121 Jun 12, 2023
ab179de
refactor: settings text
shohag121 Jun 12, 2023
6038f81
update: SPMV Product create search hook added
shohag121 Jun 12, 2023
ce6feae
refactor: removed `wp_delete_auto_drafts()`
shohag121 Jun 13, 2023
4137cad
Merge branch 'develop' into feat/onepage-product-create
shohag121 Jun 20, 2023
0306958
Merge branch 'develop' into feat/onepage-product-create
shohag121 Jun 23, 2023
9a33e8a
update: add product action hook setup
shohag121 Jun 26, 2023
5961040
update: product editor url replace
shohag121 Jun 26, 2023
1bbc32d
update: add pending review as new product status
shohag121 Jul 4, 2023
113b5a6
Merge branch 'develop' into feat/onepage-product-create
shohag121 Jul 4, 2023
8056dad
Add product filter reset button
Aunshon Jul 4, 2023
71e9d6f
Fix: edit product publish product directly
Aunshon Jul 5, 2023
cb6dfc2
Fix: text domain
Aunshon Jul 5, 2023
10da551
Fix: pending review in lite and pro
Aunshon Jul 6, 2023
995d43c
Fix: pending review in lite and pro
Aunshon Jul 6, 2023
412d161
Fix: pending review in lite and pro
Aunshon Jul 6, 2023
704c409
Refactor: introduce new method for post status
Aunshon Jul 6, 2023
517aef4
Refactor: if dokan_get_available_post_status function not exists in d…
Aunshon Jul 7, 2023
fce43f0
Refactor: if dokan_get_available_post_status function not exists in d…
Aunshon Jul 7, 2023
8ebd9df
Refactor: if dokan_get_available_post_status function not exists in d…
Aunshon Jul 7, 2023
8c5fe19
Refactor: if dokan_get_available_post_status function not exists in d…
Aunshon Jul 7, 2023
228489e
Merge branch 'develop' into feat/onepage-product-create
shohag121 Jul 27, 2023
503df89
refactor: Product creation popup remove and product status fix
shohag121 Jul 27, 2023
8bd3c5e
Merge branch 'develop' into feat/onepage-product-create
shohag121 Aug 14, 2023
de3fd3d
update: bring back admin settings and popup
shohag121 Aug 14, 2023
09e1381
Merge branch 'develop' into enhance/several-product-edit-enhancements
Aunshon Aug 18, 2023
0d682af
Merge pull request #1930 from Aunshon/enhance/several-product-edit-en…
nurul-umbhiya Aug 29, 2023
827f176
Merge branch 'enhance/dashboard_product_page' into feat/onepage-produ…
nurul-umbhiya Aug 29, 2023
3fe96f8
Merge pull request #1915 from shohag121/feat/onepage-product-create
nurul-umbhiya Aug 29, 2023
756035d
fixed merged conflict on others.php files
nurul-umbhiya Aug 30, 2023
e79406e
Fix: auction and booking products showing on the product menu if Doka…
Aunshon Sep 1, 2023
606ce7d
Fix: product statuses
Aunshon Sep 6, 2023
6288274
Add notice for one step product create.
Aunshon Sep 6, 2023
cc27764
Prevent wrong email send for draft product, the wrong email was as pu…
Aunshon Sep 6, 2023
7c78ae8
Prevent wrong email send for draft product, the wrong email was as pu…
Aunshon Sep 7, 2023
1aea928
Merge branch 'develop' into enhance/dashboard_product_page
Aunshon Sep 7, 2023
8342110
Merge branch 'develop' into enhance/dashboard_product_page
nurul-umbhiya Sep 7, 2023
5a9173f
Fix: product status in lite
Aunshon Sep 7, 2023
9a77b26
Product status in rest api
Aunshon Sep 7, 2023
7554ed0
Fix: draft to pending email
Aunshon Sep 7, 2023
f22e184
Fix: draft product status
Aunshon Sep 7, 2023
b53db76
Merge remote-tracking branch 'origin/develop' into enhance/dashboard_…
nurul-umbhiya Sep 8, 2023
7623b55
🛠️Fix: phpcs
Aunshon Sep 8, 2023
7b01325
🐛 fix(Products.php): change `dokan_get_new_post_status()` to `dokan_g…
nurul-umbhiya Sep 10, 2023
097a6c8
Merge remote-tracking branch 'origin/enhance/dashboard_product_page' …
nurul-umbhiya Sep 10, 2023
c3a2c60
🐛 fix(Products.php): change post_status assignment to use dokan_get_d…
nurul-umbhiya Sep 11, 2023
2d4b274
🔥 refactor(NewProduct.php): remove unnecessary check for dokan_get_op…
nurul-umbhiya Sep 11, 2023
c1ae4d0
🔧 fix(Manager.php): remove unused 'dokan_email_trigger_new_pending_pr…
nurul-umbhiya Sep 11, 2023
650768a
🐛 fix(functions.php): fix incorrect assignment of $seller_id variable…
nurul-umbhiya Sep 11, 2023
01ae819
🐛 fix(functions.php): remove unnecessary space before semicolon in do…
nurul-umbhiya Sep 11, 2023
728a30a
🐛 fix(ProductController.php): fix logic for setting post status in Pr…
nurul-umbhiya Sep 11, 2023
6c8c940
fix: api product status
nurul-umbhiya Sep 11, 2023
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
39 changes: 39 additions & 0 deletions assets/src/js/product-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,48 @@

this.attribute.disbalePredefinedAttribute();

this.setCorrectProductId();

$( 'body' ).trigger( 'dokan-product-editor-loaded', this );
},

setCorrectProductId : function () {
let productForm = $( '.dokan-product-edit-form' );
if ( ! productForm ) {
return;
}
let productId = $( '#dokan_product_id' ).val();

if ( window.history.replaceState ) {
let url = new URL( document.location );
let searchParams = url.searchParams;

let currentProductId = searchParams.get( 'product_id' );
if ( ! ( '' === currentProductId || '0' === currentProductId ) ) {
return;
}

// new value of "product_id" is set to new value
searchParams.set('product_id', productId );

let action = searchParams.get( 'action' );
if ( 'edit' !== action ) {
return;
}

// change the search property of the main url
url.search = searchParams.toString();

// the new url string
let newUrl = url.toString();
let stateData = {
product_id: productId,
}

window.history.replaceState( stateData, document.title, newUrl );
}
},

saleSchedule: function() {
var $wrap = $(this).closest( '.dokan-product-field-content', 'div, table' );
$(this).hide();
Expand Down
50 changes: 50 additions & 0 deletions includes/Admin/Notices/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ private function init_hooks() {
add_action( 'admin_notices', [ $this, 'render_missing_woocommerce_notice' ] );
add_action( 'admin_notices', [ $this, 'render_global_admin_notices_html' ] );
add_filter( 'dokan_admin_notices', [ $this, 'show_permalink_setting_notice' ] );
add_filter( 'dokan_admin_notices', [ $this, 'show_one_step_product_add_notice' ] );
add_action( 'wp_ajax_dismiss_dokan_one_step_product_notice', [ $this, 'dismiss_dokan_one_step_product_notice' ] );
}

/**
Expand Down Expand Up @@ -124,4 +126,52 @@ public function show_permalink_setting_notice( $notices ) {

return $notices;
}

/**
* Display single page product page create notice.
*
* @since DOKAN_SINCE
*
* @param array $notices
*
* @return array
*/
public function show_one_step_product_add_notice( $notices ) {
if ( 'yes' !== get_option( 'dismiss_dokan_one_step_product_nonce', 'no' ) ) {
$notices[] = [
'type' => 'alert',
'title' => __( 'New One-Step Product Form', 'dokan-lite' ),
'description' => __( 'Try it now to enhance your vendor\'s product upload experience, the older two-step version will be retired in one month.', 'dokan-lite' ),
'priority' => 1,
'show_close_button' => true,
'ajax_data' => [
'action' => 'dismiss_dokan_one_step_product_notice',
'nonce' => wp_create_nonce( 'dismiss_dokan_one_step_product_nonce' ),
],
];
}

return $notices;
}

/**
* Dismisses one-step product create notice.
*
* @since DOKAN_SINCE
*
* @return void
*/
public function dismiss_dokan_one_step_product_notice() {
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['nonce'] ) ), 'dismiss_dokan_one_step_product_nonce' ) ) {
wp_send_json_error( __( 'Invalid nonce', 'dokan-lite' ) );
}

// phpcs:ignore
if ( ! current_user_can( 'manage_woocommerce' ) ) {
wp_send_json_error( __( 'You have no permission to do that', 'dokan-lite' ) );
}

update_option( 'dismiss_dokan_one_step_product_nonce', 'yes' );
wp_send_json_success();
}
}
11 changes: 11 additions & 0 deletions includes/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,12 +539,23 @@ 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' => [
Expand Down
8 changes: 1 addition & 7 deletions includes/Blocks/ProductBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,7 @@ public function get_configurations() {
'dokan_get_product_block_configurations',
[
'disable_popup' => 'on' === dokan_get_option( 'disable_product_popup', 'dokan_selling', 'off' ),
'statuses' => apply_filters(
'dokan_post_status',
[
'publish' => __( 'Online', 'dokan-lite' ),
'draft' => __( 'Draft', 'dokan-lite' ),
]
),
'statuses' => dokan_get_available_post_status(),
'visibility_options' => dokan_get_product_visibility_options(),
'manage_stocks' => 'yes' === get_option( 'woocommerce_manage_stock' ),
'stock_statuses' => [
Expand Down
19 changes: 15 additions & 4 deletions includes/Dashboard/Templates/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,15 @@
$_visibility = $product->get_catalog_visibility();
$visibility_options = dokan_get_product_visibility_options();

// set new post status
$post_status = dokan_get_default_product_status( dokan_get_current_user_id() );
$post_status = $product->get_status() === 'auto-draft' ? $post_status : $product->get_status();

dokan_get_template_part(
'products/others', '', [
'post_id' => $post_id,
'post' => $post,
'post_status' => $post->post_status,
'post_status' => apply_filters( 'dokan_post_edit_default_status', $post_status, $product ),
'_visibility' => $_visibility,
'visibility_options' => $visibility_options,
'class' => '',
Expand Down Expand Up @@ -199,7 +203,7 @@
* @return void
*/
public function load_product_edit_template() {
if ( current_user_can( 'dokan_edit_product' ) ) {

Check warning on line 206 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokan_edit_product" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
dokan_get_template_part( 'products/edit-product-single' );
} else {
dokan_get_template_part(
Expand All @@ -220,7 +224,7 @@
*
* @return void
*/
public function render_product_listing_template( $action ) {

Check warning on line 227 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The method parameter $action is never used
$bulk_statuses = apply_filters(
'dokan_bulk_product_statuses', [
'-1' => __( 'Bulk Actions', 'dokan-lite' ),
Expand Down Expand Up @@ -270,7 +274,7 @@
if ( absint( $postdata['product_cat'] ) < 0 ) {
$errors[] = __( 'Please select a category', 'dokan-lite' );
}
} else {

Check failure on line 277 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

If control structure block found as the only statement within an "else" block. Use elseif instead.
if ( ! isset( $postdata['product_cat'] ) || empty( $postdata['product_cat'] ) ) {
$errors[] = __( 'Please select at least one category', 'dokan-lite' );
}
Expand All @@ -283,7 +287,7 @@

if ( ! self::$errors ) {
$timenow = dokan_current_datetime()->setTimezone( new \DateTimeZone( 'UTC' ) );
$product_status = dokan_get_new_post_status();
$product_status = dokan_get_default_product_status( dokan_get_current_user_id() );
$post_data = apply_filters(
'dokan_insert_product_post_data', [
'post_type' => 'product',
Expand Down Expand Up @@ -313,7 +317,7 @@
if ( ! isset( $postdata['chosen_product_cat'] ) ) {
if ( Helper::product_category_selection_is_single() ) {
wp_set_object_terms( $product_id, (int) $postdata['product_cat'], 'product_cat' );
} else {

Check failure on line 320 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

If control structure block found as the only statement within an "else" block. Use elseif instead.
if ( isset( $postdata['product_cat'] ) && ! empty( $postdata['product_cat'] ) ) {
$cat_ids = array_map( 'absint', (array) $postdata['product_cat'] );
wp_set_object_terms( $product_id, $cat_ids, 'product_cat' );
Expand Down Expand Up @@ -377,7 +381,7 @@

do_action( 'dokan_new_product_added', $product_id, $postdata );

if ( current_user_can( 'dokan_edit_product' ) ) {

Check warning on line 384 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

Found unknown capability "dokan_edit_product" in function call to current_user_can(). Please check the spelling of the capability. If this is a custom capability, please verify the capability is registered with WordPress via a call to WP_Role(s)->add_cap(). Custom capabilities can be made known to this sniff by setting the "custom_capabilities" property in the PHPCS ruleset.
$redirect = dokan_edit_product_url( $product_id );
} else {
$redirect = dokan_get_navigation_url( 'products' );
Expand Down Expand Up @@ -438,8 +442,11 @@
$errors[] = __( 'No product found!', 'dokan-lite' );
}

$current_post_status = get_post_status( $post_id );
$is_new_product = 'auto-draft' === $current_post_status;

if ( empty( $post_status ) ) {
$post_status = get_post_status( $post_id );
$post_status = $current_post_status;
}

if ( ! dokan_is_product_author( $post_id ) ) {
Expand Down Expand Up @@ -521,7 +528,11 @@
/** Process all variation products meta */
dokan_process_product_meta( $post_id, $postdata );

do_action( 'dokan_product_updated', $post_id, $postdata );
if ( $is_new_product ) {
do_action( 'dokan_new_product_added', $post_id, $postdata );
} else {
do_action( 'dokan_product_updated', $post_id, $postdata );
}

$redirect = apply_filters( 'dokan_add_new_product_redirect', dokan_edit_product_url( $post_id ), $post_id );

Expand Down Expand Up @@ -597,4 +608,4 @@
exit;
}

}

Check failure on line 611 in includes/Dashboard/Templates/Products.php

View workflow job for this annotation

GitHub Actions / Run PHPCS inspection

The closing brace for the class must go on the next line after the body
2 changes: 1 addition & 1 deletion includes/Emails/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function register_email_actions( $actions ) {
$dokan_email_actions = apply_filters(
'dokan_email_actions', array(
'dokan_new_product_added',
'dokan_email_trigger_new_pending_product',
'dokan_product_updated',
'dokan_new_seller_created',
'dokan_after_withdraw_request',
'dokan_withdraw_request_approved',
Expand Down
103 changes: 56 additions & 47 deletions includes/Emails/NewProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function __construct() {
$this->template_base = DOKAN_DIR . '/templates/';

// Triggers for this email
add_action( 'dokan_new_product_added', array( $this, 'trigger' ), 30, 2 );
add_action( 'dokan_new_product_added', array( $this, 'trigger' ), 30, 1 );
add_action( 'dokan_product_updated', array( $this, 'trigger' ), 30, 1 );

// Call parent constructor
parent::__construct();
Expand Down Expand Up @@ -61,53 +62,61 @@ public function get_default_heading() {
* Trigger the sending of this email.
*
* @param int $product_id The product ID.
* @param array $postdata.
*/
public function trigger( $product_id, $postdata ) {
if ( dokan_get_option( 'product_add_mail', 'dokan_general', 'on' ) !== 'on' ) {
return;
}

if ( dokan_get_new_post_status() === 'pending' ) {
do_action( 'dokan_email_trigger_new_pending_product', $product_id, $postdata );
return;
}

if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
return;
}

$product = wc_get_product( $product_id );
$seller_id = get_post_field( 'post_author', $product_id );
$seller = get_user_by( 'id', $seller_id );
$category = wp_get_post_terms( dokan_get_prop( $product, 'id' ), 'product_cat', array( 'fields' => 'names' ) );
$category_name = $category ? reset( $category ) : 'N/A';

if ( is_a( $product, 'WC_Product' ) ) {
$this->object = $product;

$this->find['product-title'] = '{product_title}';
$this->find['price'] = '{price}';
$this->find['seller-name'] = '{seller_name}';
$this->find['seller_url'] = '{seller_url}';
$this->find['category'] = '{category}';
$this->find['product_link'] = '{product_link}';
$this->find['site_name'] = '{site_name}';
$this->find['site_url'] = '{site_url}';

$this->replace['product-title'] = $product->get_title();
$this->replace['price'] = $product->get_price();
$this->replace['seller-name'] = $seller->display_name;
$this->replace['seller_url'] = dokan_get_store_url( $seller->ID );
$this->replace['category'] = $category_name;
$this->replace['product_link'] = admin_url( 'post.php?action=edit&post=' . $product_id );
$this->replace['site_name'] = $this->get_from_name();
$this->replace['site_url'] = site_url();
}

$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
public function trigger( $product_id ) {
$product = wc_get_product( $product_id );
if ( ! $product ) {
return;
}

// we've added _dokan_new_product_email_sent from version DOKAN_SINCE
// so, we are assuming if the meta doesn't exist, email was already sent to the client
$email_sent = $product->get_meta( '_dokan_new_product_email_sent' );
if ( empty( $email_sent ) || true === wc_string_to_bool( $email_sent ) ) {
return;
}

if ( 'publish' !== $product->get_status() ) {
return;
}

$product->update_meta_data( '_dokan_new_product_email_sent', 'yes' );
$product->save();

if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
return;
}

$seller_id = get_post_field( 'post_author', $product_id );
$seller = get_user_by( 'id', $seller_id );
$category = wp_get_post_terms( dokan_get_prop( $product, 'id' ), 'product_cat', array( 'fields' => 'names' ) );
$category_name = $category ? reset( $category ) : 'N/A';

if ( is_a( $product, 'WC_Product' ) ) {
$this->object = $product;

$this->find['product-title'] = '{product_title}';
$this->find['price'] = '{price}';
$this->find['seller-name'] = '{seller_name}';
$this->find['seller_url'] = '{seller_url}';
$this->find['category'] = '{category}';
$this->find['product_link'] = '{product_link}';
$this->find['site_name'] = '{site_name}';
$this->find['site_url'] = '{site_url}';

$this->replace['product-title'] = $product->get_title();
$this->replace['price'] = $product->get_price();
$this->replace['seller-name'] = $seller->display_name;
$this->replace['seller_url'] = dokan_get_store_url( $seller->ID );
$this->replace['category'] = $category_name;
$this->replace['product_link'] = admin_url( 'post.php?action=edit&post=' . $product_id );
$this->replace['site_name'] = $this->get_from_name();
$this->replace['site_url'] = site_url();
}

$this->setup_locale();
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
$this->restore_locale();
}

/**
Expand Down
Loading
Loading