-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: product variation author id update for product quick save (#914)
* fix: product variation author id update for product quick save fixed #874 #878 #883 * query limit increased in product query * fix: codes updated with phpcs standard * add translation in select option
- Loading branch information
Showing
4 changed files
with
214 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
includes/Upgrade/Upgrades/BackgroundProcesses/V_3_0_10_ProductAttributesAuthorId.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
namespace WeDevs\Dokan\Upgrade\Upgrades\BackgroundProcesses; | ||
|
||
use WeDevs\Dokan\Abstracts\DokanBackgroundProcesses; | ||
|
||
/** | ||
* Dokan Product attribute author id updater class | ||
* | ||
* @since DOKAN_LITE_SINCE | ||
*/ | ||
class V_3_0_10_ProductAttributesAuthorId extends DokanBackgroundProcesses { | ||
|
||
/** | ||
* Perform updates | ||
* | ||
* @param mixed $item | ||
* | ||
* @since DOKAN_LITE_SINCE | ||
* | ||
* @return mixed | ||
*/ | ||
public function task( $item ) { | ||
if ( empty( $item ) ) { | ||
return false; | ||
} | ||
|
||
if ( 'product_attribute_author_id_as_parent_author_id' === $item['updating'] ) { | ||
return $this->update_product_attribute_author( $item['paged'] ); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Update product attribute author | ||
* if its not same as product author id | ||
* | ||
* @param $paged | ||
* | ||
* @since DOKAN_LITE_SINCE | ||
* | ||
* @return array|boolean | ||
*/ | ||
private function update_product_attribute_author( $paged ) { | ||
$limit = 100; | ||
$count = $limit * $paged; | ||
|
||
$query_args = [ | ||
'post_type' => 'product_variation', | ||
'status' => 'any', | ||
'number' => $limit, | ||
'offset' => $count, | ||
'fields' => 'id=>parent', | ||
]; | ||
|
||
$product_variation_parent_ids = get_posts( $query_args ); | ||
|
||
if ( ! $product_variation_parent_ids ) { | ||
return false; | ||
} | ||
|
||
foreach ( $product_variation_parent_ids as $key => $parent_id ) { | ||
$product = wc_get_product( $parent_id ); | ||
$product_author = get_post_field( 'post_author', $product->get_id() ); | ||
|
||
//get product all variations | ||
foreach ( $product->get_children() as $child_id ) { | ||
$variation_author_id = get_post_field( 'post_author', $child_id ); | ||
|
||
/** | ||
* We will change the variation post author id if its not | ||
* Same as product author id | ||
*/ | ||
if ( $product_author !== $variation_author_id ) { | ||
dokan_override_author_for_variations( $product, $product_author ); | ||
} | ||
} | ||
} | ||
|
||
return [ | ||
'updating' => 'product_attribute_author_id_as_parent_author_id', | ||
'paged' => ++$paged, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace WeDevs\Dokan\Upgrade\Upgrades; | ||
|
||
use WeDevs\Dokan\Abstracts\DokanUpgrader; | ||
use WeDevs\Dokan\Upgrade\Upgrades\BackgroundProcesses\V_3_0_10_ProductAttributesAuthorId; | ||
|
||
class V_3_0_10 extends DokanUpgrader { | ||
|
||
/** | ||
* Update product attribute id to same as product author id | ||
* | ||
* @return void | ||
*/ | ||
public static function update_product_attributes_author_id() { | ||
$processor = new V_3_0_10_ProductAttributesAuthorId(); | ||
|
||
$args = [ | ||
'updating' => 'product_attribute_author_id_as_parent_author_id', | ||
'paged' => 0, | ||
]; | ||
|
||
$processor->push_to_queue( $args )->dispatch_process(); | ||
} | ||
} |
Oops, something went wrong.