Skip to content

Conversation

@rakib1904107
Copy link
Contributor

@rakib1904107 rakib1904107 commented Jan 28, 2026

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Related Pull Request(s)

Closes

  • Closes #

How to test the changes in this Pull Request:

  • Steps or issue link

Changelog entry

Title

Detailed Description of the pull request. What was previous behaviour
and what will be changed in this PR.

Before Changes

Describe the issue before changes with screenshots(s).

After Changes

Describe the issue after changes with screenshot(s).

Feature Video (optional)

Link of detailed video if this PR is for a feature.

PR Self Review Checklist:

  • Code is not following code style guidelines
  • Bad naming: make sure you would understand your code if you read it a few months from now.
  • KISS: Keep it simple, Sweetie (not stupid!).
  • DRY: Don't Repeat Yourself.
  • Code that is not readable: too many nested 'if's are a bad sign.
  • Performance issues
  • Complicated constructions that need refactoring or comments: code should almost always be self-explanatory.
  • Grammar errors.

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • Tests
    • Updated test factory for product creation with enhanced post-processing logic for variation products. Improvements now capture product relationships more effectively and ensure proper metadata assignment during test fixture generation, delivering more comprehensive and accurate testing scenarios for validating product variation workflows across different configurations and use cases.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 28, 2026

📝 Walkthrough

Walkthrough

The create_variation_product method in the ProductFactory now updates post author fields for created variation products and their children when a seller ID is configured, rather than returning the variation immediately.

Changes

Cohort / File(s) Summary
Factory post-creation processing
tests/php/src/Factories/ProductFactory.php
Modified create_variation_product to capture variation object, collect variation ID and children IDs, iterate through collected IDs to update post_author field to seller_id when set, then return the variation. Note: potential bug where children array is pushed into IDs collection, causing nested arrays during iteration.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

Dev Review Done

Suggested reviewers

  • mrabbani
  • kzamanbd
  • MdAsifHossainNadim

Poem

🐰 A variation springs to life so fine,
With children gathered, all in line,
Post authors set by seller's hand,
Though nested arrays make demands,
Test factories hop to higher ground!

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete with most required sections left empty or containing only placeholders and template text. Complete the description by filling in: Changes proposed, Related PR link (beyond template), Closes issue number, How to test steps, Changelog entry with title and detailed description, Before/After changes with context, and mark completed checklist items.
Title check ❓ Inconclusive The title 'Updated variation-product function' is vague and uses generic phrasing that doesn't specifically describe the main change. While it references the modified function, it lacks clarity about what was actually updated or why. Provide a more specific title that describes the key change, such as 'Add post_author update to variation product creation' or 'Update variation product to set seller_author on creation'.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@tests/php/src/Factories/ProductFactory.php`:
- Around line 135-149: In create_variation_product, initialize $product_ids as
an array and merge the variation children into it so each child ID is an integer
(e.g. $product_ids = []; $product_ids[] = $variable_product->get_id();
$product_ids = array_merge( $product_ids, $variable_product->get_children() );),
replacing the current array_push( $product_ids,
$variable_product->get_children() ) which nests the children array; this ensures
the foreach over $product_ids in create_variation_product passes scalar post IDs
to wp_update_post and avoids an uninitialized variable notice.

Comment on lines 135 to +149
public function create_variation_product( $product = null ) {
return WC_Helper_Product::create_variation_product( $product );
$variable_product = WC_Helper_Product::create_variation_product( $product );
$product_ids[] = $variable_product->get_id();

array_push( $product_ids, $variable_product->get_children() );

foreach ( $product_ids as $product_id ) {
if ( $this->seller_id ) {
$post_data = [
'ID' => $product_id,
'post_author' => $this->seller_id,
];

wp_update_post( $post_data );
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix nested IDs array and initialize $product_ids.

array_push( $product_ids, $variable_product->get_children() ) adds the children array as a single element, so the loop passes an array to wp_update_post, and child authors won’t be updated. Also, $product_ids is uninitialized and emits a notice.

🧩 Proposed fix
-        $variable_product = WC_Helper_Product::create_variation_product( $product );
-        $product_ids[] = $variable_product->get_id();
-
-        array_push( $product_ids, $variable_product->get_children() );
-
-        foreach ( $product_ids as $product_id ) {
-			if ( $this->seller_id ) {
-				$post_data = [
-					'ID'          => $product_id,
-					'post_author' => $this->seller_id,
-				];
-
-				wp_update_post( $post_data );
-			}
-        }
+        $variable_product = WC_Helper_Product::create_variation_product( $product );
+        $product_ids      = array_merge(
+            array( $variable_product->get_id() ),
+            $variable_product->get_children()
+        );
+
+        if ( $this->seller_id ) {
+            foreach ( $product_ids as $product_id ) {
+                $post_data = [
+                    'ID'          => $product_id,
+                    'post_author' => $this->seller_id,
+                ];
+
+                wp_update_post( $post_data );
+            }
+        }
🤖 Prompt for AI Agents
In `@tests/php/src/Factories/ProductFactory.php` around lines 135 - 149, In
create_variation_product, initialize $product_ids as an array and merge the
variation children into it so each child ID is an integer (e.g. $product_ids =
[]; $product_ids[] = $variable_product->get_id(); $product_ids = array_merge(
$product_ids, $variable_product->get_children() );), replacing the current
array_push( $product_ids, $variable_product->get_children() ) which nests the
children array; this ensures the foreach over $product_ids in
create_variation_product passes scalar post IDs to wp_update_post and avoids an
uninitialized variable notice.

@rakib1904107 rakib1904107 changed the title updated variation-product function Updated variation-product function Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants