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 ) ); } } diff --git a/includes/Generator/Product.php b/includes/Generator/Product.php index 7e822f5..7ed0ceb 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' ); + } } /** diff --git a/includes/Generator/Term.php b/includes/Generator/Term.php index 2ee55df..b6dfa55 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(