Skip to content

Commit

Permalink
fix: product variation author id update for product quick save (#914)
Browse files Browse the repository at this point in the history
* 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
kapilpaul authored and tareq1988 committed Oct 20, 2020
1 parent 7e6782e commit 7a29fb3
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 65 deletions.
3 changes: 2 additions & 1 deletion includes/Upgrade/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Upgrades {
'2.9.19' => Upgrades\V_2_9_19::class,
'2.9.23' => Upgrades\V_2_9_23::class,
'3.0.4' => Upgrades\V_3_0_4::class,
'3.0.10' => Upgrades\V_3_0_10::class,
];

/**
Expand Down Expand Up @@ -95,7 +96,7 @@ public static function get_upgrades( $upgrades = [] ) {
$installed_version = self::get_db_installed_version();

foreach ( self::$upgrades as $version => $class_name ) {
if ( version_compare( $installed_version , $version, '<' ) ) {
if ( version_compare( $installed_version, $version, '<' ) ) {
$upgrades[ $version ][] = $class_name;
}
}
Expand Down
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,
];
}
}
25 changes: 25 additions & 0 deletions includes/Upgrade/Upgrades/V_3_0_10.php
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();
}
}
Loading

0 comments on commit 7a29fb3

Please sign in to comment.