Assign brands to generated products#174
Assign brands to generated products#174masteradhoc wants to merge 6 commits intowoocommerce:trunkfrom
Conversation
There was a problem hiding this comment.
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.
layoutd
left a comment
There was a problem hiding this comment.
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.
| $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.
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 <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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: