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

fix: Vendor class shop_data persistence is broken on save() #2089

Merged
merged 1 commit into from
Dec 11, 2023
Merged
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
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' ) );
}
}

Loading