Skip to content

Commit

Permalink
fix: Vendor class shop_data persistence is broken on save()
Browse files Browse the repository at this point in the history
  • Loading branch information
shohag121 committed Nov 22, 2023
1 parent 321ea9a commit 5effd39
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
5 changes: 3 additions & 2 deletions includes/Vendor/Vendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -1386,7 +1386,7 @@ public function get_meta( $key, $single = false ) {
* @since 2.9.11
*
* @param string $key
* @param mix $value
* @param mixed $value
*
* @return void
*/
Expand Down Expand Up @@ -1550,7 +1550,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 = [];
Expand Down
41 changes: 41 additions & 0 deletions tests/Vendor/UserToVendorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Vendor;

use WeDevs\Dokan\Vendor\Vendor;

class UserToVendorTest extends \WP_UnitTestCase {

/**
* Check vendor class persists `shop_data` on save.
*
* @test
*/
public function test_vendor_data_is_persisted_on_save() {
$user = $this->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' ) );
}
}

0 comments on commit 5effd39

Please sign in to comment.