Skip to content

Conversation

masteradhoc
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

With the new get and set methods of brands getting added to Woo i wanted to test with a good amount of testdata.
But saw that the feature wasnt implemented into Smooth Generator (#163).
I went ahead and added that feature like this:

  • Implemented a new faker collection from the same provider so we get proper brand names (see here)
  • generate brands in case not enough are set
  • generate products and assign 1(one) brand to the product

Closes #163 .

How to test the changes in this Pull Request:

  1. implement PR
  2. generate x products
  3. check if brands get generated (/wp-admin/edit-tags.php?taxonomy=product_brand&post_type=product)
  4. check if brands are assigned to the newly created products

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Changelog entry

Create brands and assign to generated products

Enter a summary of all changes on this Pull Request. This will appear in the changelog if accepted.

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@layoutd layoutd self-assigned this Oct 2, 2025
@layoutd layoutd requested review from Copilot and layoutd October 2, 2025 21:28
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds brand support to the WooCommerce Smooth Generator, enabling automatic creation and assignment of brands to generated products. The implementation leverages new brand get/set methods being added to WooCommerce core.

  • Implements brand term generation using the Faker Device provider for realistic brand names
  • Adds brand assignment logic to both simple and variable product generators
  • Ensures adequate brand terms are available before product generation

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
includes/Generator/Generator.php Adds Device provider to Faker for brand name generation
includes/Generator/Term.php Implements brand-specific term name generation using department method
includes/Generator/Product.php Adds brand assignment to products and ensures sufficient brand terms exist

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@layoutd layoutd left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on! I added a few comments inline.


if ( $taxonomy_obj->hierarchical ) {
if ( $taxonomy_obj->hierarchical && 'product_brand' === $taxonomy ) {
$term_name = ucwords( self::$faker->department( 1 ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$term_name = ucwords( self::$faker->department( 1 ) );
$term_name = ucwords( self::$faker->deviceManufacturer() );

department was adding Commerce departments.

'image_id' => self::get_image(),
'category_ids' => self::get_term_ids( 'product_cat', self::$faker->numberBetween( 0, 3 ) ),
'tag_ids' => self::get_term_ids( 'product_tag', self::$faker->numberBetween( 0, 5 ) ),
'brand_ids' => self::get_term_ids( 'product_brand', 1),
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't get this to add generated brands. I had to use wp_set_object_terms in generate.
It would also be best to assign a variable number for brands (as in category and tags).

// Assign brand terms using wp_set_object_terms
$brand_ids = self::get_term_ids( 'product_brand', self::$faker->numberBetween( 1, 3 ) );
if ( ! empty( $brand_ids ) ) {
	wp_set_object_terms( $product->get_id(), $brand_ids, 'product_brand' );
}

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.

[Enhancement]: Assign brands to generated products

2 participants