-
Notifications
You must be signed in to change notification settings - Fork 54
Assign brands to generated products #174
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
base: trunk
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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.
includes/Generator/Term.php
Outdated
|
||
if ( $taxonomy_obj->hierarchical ) { | ||
if ( $taxonomy_obj->hierarchical && 'product_brand' === $taxonomy ) { | ||
$term_name = ucwords( self::$faker->department( 1 ) ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$term_name = ucwords( self::$faker->department( 1 ) ); | |
$term_name = ucwords( self::$faker->deviceManufacturer() ); |
department
was adding Commerce departments.
includes/Generator/Product.php
Outdated
'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), |
There was a problem hiding this comment.
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' );
}
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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:
Closes #163 .
How to test the changes in this Pull Request:
Other information:
Changelog entry
Create brands and assign to generated products
FOR PR REVIEWER ONLY: