-
Notifications
You must be signed in to change notification settings - Fork 55
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?
Changes from 3 commits
c832934
e226441
52f1fb2
5c30890
dc9fa4c
8672d9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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), | ||
masteradhoc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| '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' ); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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 ) ); | ||||||
masteradhoc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| $term_name = ucwords( self::$faker->department( 1 ) ); | |
| $term_name = ucwords( self::$faker->deviceManufacturer() ); |
department was adding Commerce departments.
Uh oh!
There was an error while loading. Please reload this page.