From 2d82b61d237863e038568dc6d001bb3ff301078a Mon Sep 17 00:00:00 2001 From: Shazahanul Islam Shohag Date: Mon, 11 Dec 2023 11:59:58 +0600 Subject: [PATCH] fix: Vendor class `shop_data` persistence is broken on `save()` (#2089) --- includes/Vendor/Vendor.php | 5 ++-- tests/Vendor/UserToVendorTest.php | 41 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/Vendor/UserToVendorTest.php diff --git a/includes/Vendor/Vendor.php b/includes/Vendor/Vendor.php index d291067658..54750470f6 100644 --- a/includes/Vendor/Vendor.php +++ b/includes/Vendor/Vendor.php @@ -1387,7 +1387,7 @@ public function get_meta( $key, $single = false ) { * @since 2.9.11 * * @param string $key - * @param mix $value + * @param mixed $value * * @return void */ @@ -1551,7 +1551,8 @@ public function set_store_times_close_notice( $value ) { * @since 2.9.11 */ public function apply_changes() { - $this->update_meta( 'dokan_profile_settings', array_replace_recursive( $this->shop_data, $this->changes ) ); + $this->shop_data = array_replace_recursive( $this->shop_data, $this->changes ); + $this->update_meta( 'dokan_profile_settings', $this->shop_data ); $this->update_meta_data(); $this->changes = []; diff --git a/tests/Vendor/UserToVendorTest.php b/tests/Vendor/UserToVendorTest.php new file mode 100644 index 0000000000..b2ffcaee07 --- /dev/null +++ b/tests/Vendor/UserToVendorTest.php @@ -0,0 +1,41 @@ +factory()->user->create_and_get(); + + $data = [ + 'shopurl' => '', + 'fname' => 'John', + 'lname' => 'Doe', + 'shopname' => 'My Shop', + 'phone' => '+00000000000000', + 'address' => 'My Address', + ]; + + add_action( 'dokan_new_seller_created', function ( $user_id, $vendor_info ) use ( $data ) { + $this->assertEquals( $data['shopname'], $vendor_info['store_name'] ); + $this->assertEquals( $data['phone'], $vendor_info['phone'] ); + }, 10, 2); + + dokan_user_update_to_seller( $user, $data ); + + $vendor = new Vendor( $user->ID ); + $shop_info = $vendor->get_shop_info(); + $this->assertEquals( $data['shopname'], $shop_info['store_name'] ); + $this->assertEquals( $data['phone'], $shop_info['phone'] ); + + $this->assertTrue( !!did_action( 'dokan_new_seller_created' ) ); + } +} +