From c83293463465749d5f969bd80b16185ef62580e8 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 25 Aug 2025 20:16:51 +0200 Subject: [PATCH 1/6] add new collection --- includes/Generator/Generator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/Generator/Generator.php b/includes/Generator/Generator.php index f9b7c71..db5d246 100644 --- a/includes/Generator/Generator.php +++ b/includes/Generator/Generator.php @@ -98,6 +98,7 @@ protected static function init_faker() { if ( ! self::$faker ) { self::$faker = \Faker\Factory::create( 'en_US' ); self::$faker->addProvider( new \Bezhanov\Faker\Provider\Commerce( self::$faker ) ); + self::$faker->addProvider( new \Bezhanov\Faker\Provider\Device( self::$faker ) ); } } From e22644131451d8d75e30a839e3dab0e6f847c21a Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 25 Aug 2025 20:20:20 +0200 Subject: [PATCH 2/6] add brand feature to product generation --- includes/Generator/Product.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/includes/Generator/Product.php b/includes/Generator/Product.php index 7e822f5..1c3e0de 100644 --- a/includes/Generator/Product.php +++ b/includes/Generator/Product.php @@ -140,6 +140,7 @@ public static function batch( $amount, array $args = array() ) { // In case multiple batches are being run in one request, refresh the cache data. RandomRuntimeCache::clear( 'product_cat' ); RandomRuntimeCache::clear( 'product_tag' ); + RandomRuntimeCache::clear( 'product_brand' ); return $product_ids; } @@ -314,6 +315,7 @@ protected static function generate_variable_product() { '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), 'gallery_image_ids' => $gallery, 'reviews_allowed' => self::$faker->boolean(), 'purchase_note' => self::$faker->boolean() ? self::$faker->text() : '', @@ -409,6 +411,7 @@ protected static function generate_simple_product() { 'downloadable' => false, '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), 'shipping_class_id' => 0, 'image_id' => $image_id, 'gallery_image_ids' => $gallery, @@ -431,14 +434,17 @@ protected static function maybe_generate_terms( int $product_amount ): void { $cats = 5; $cat_depth = 1; $tags = 10; + $brands = 5; } elseif ( $product_amount < 50 ) { $cats = 10; $cat_depth = 2; $tags = 20; + $brands = 10; } else { $cats = 20; $cat_depth = 3; $tags = 40; + $brands = 10; } $existing_cats = count( self::get_term_ids( 'product_cat', $cats ) ); @@ -450,6 +456,11 @@ protected static function maybe_generate_terms( int $product_amount ): void { if ( $existing_tags < $tags ) { Term::batch( $tags - $existing_tags, 'product_tag' ); } + + $existing_brands = count( self::get_term_ids( 'product_brand', $brands ) ); + if ( $existing_brands < $brands ) { + Term::batch( $brands - $existing_brands, 'product_brand' ); + } } /** From 52f1fb233ab5b9097abdc2056ce245271f0dbce6 Mon Sep 17 00:00:00 2001 From: Brian Date: Mon, 25 Aug 2025 20:21:41 +0200 Subject: [PATCH 3/6] adjust term generation so product_brands only get 1 brand assigned --- includes/Generator/Term.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/Generator/Term.php b/includes/Generator/Term.php index 2ee55df..7936445 100644 --- a/includes/Generator/Term.php +++ b/includes/Generator/Term.php @@ -38,7 +38,9 @@ public static function generate( $save = true, string $taxonomy = 'product_cat', parent::maybe_initialize_generators(); - if ( $taxonomy_obj->hierarchical ) { + if ( $taxonomy_obj->hierarchical && 'product_brand' === $taxonomy ) { + $term_name = ucwords( self::$faker->department( 1 ) ); + } elseif ( $taxonomy_obj->hierarchical ) { $term_name = ucwords( self::$faker->department( 3 ) ); } else { $term_name = self::random_weighted_element( array( From 5c30890534937b39bad0558521d0e3d9987e8bed Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 3 Oct 2025 13:54:34 +0200 Subject: [PATCH 4/6] Update includes/Generator/Term.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- includes/Generator/Term.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Generator/Term.php b/includes/Generator/Term.php index 7936445..b6dfa55 100644 --- a/includes/Generator/Term.php +++ b/includes/Generator/Term.php @@ -39,7 +39,7 @@ public static function generate( $save = true, string $taxonomy = 'product_cat', parent::maybe_initialize_generators(); if ( $taxonomy_obj->hierarchical && 'product_brand' === $taxonomy ) { - $term_name = ucwords( self::$faker->department( 1 ) ); + $term_name = ucwords( self::$faker->department( 1 ) ); } elseif ( $taxonomy_obj->hierarchical ) { $term_name = ucwords( self::$faker->department( 3 ) ); } else { From dc9fa4ce94b888bd452a3199353a43f378a81ee7 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 3 Oct 2025 13:54:46 +0200 Subject: [PATCH 5/6] Update includes/Generator/Product.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- includes/Generator/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Generator/Product.php b/includes/Generator/Product.php index 1c3e0de..8f6ccd9 100644 --- a/includes/Generator/Product.php +++ b/includes/Generator/Product.php @@ -315,7 +315,7 @@ protected static function generate_variable_product() { '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), + 'brand_ids' => self::get_term_ids( 'product_brand', 1 ), 'gallery_image_ids' => $gallery, 'reviews_allowed' => self::$faker->boolean(), 'purchase_note' => self::$faker->boolean() ? self::$faker->text() : '', From 8672d9d311ca39b4bd7b3de6f5eaef1b5632eb89 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 3 Oct 2025 13:54:54 +0200 Subject: [PATCH 6/6] Update includes/Generator/Product.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- includes/Generator/Product.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Generator/Product.php b/includes/Generator/Product.php index 8f6ccd9..7ed0ceb 100644 --- a/includes/Generator/Product.php +++ b/includes/Generator/Product.php @@ -411,7 +411,7 @@ protected static function generate_simple_product() { 'downloadable' => false, '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), + 'brand_ids' => self::get_term_ids( 'product_brand', 1 ), 'shipping_class_id' => 0, 'image_id' => $image_id, 'gallery_image_ids' => $gallery,