Skip to content

Commit febe0d0

Browse files
authored
implement cogs feature (#176)
* implement cogs feature
1 parent 18c2e99 commit febe0d0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

includes/Generator/Product.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,12 @@ protected static function generate_variable_product() {
352352
'downloadable' => false,
353353
'image_id' => self::get_image(),
354354
) );
355+
356+
// Set COGS if the feature is enabled.
357+
if ( wc_get_container()->get( 'Automattic\WooCommerce\Internal\CostOfGoodsSold\CostOfGoodsSoldController' )->feature_is_enabled() ) {
358+
$variation->set_props( array( 'cogs_value' => round( $price * ( 1 - self::$faker->numberBetween( 15, 60 ) / 100 ), 2 ) ) );
359+
}
360+
355361
$variation->save();
356362
}
357363
$data_store = $product->get_data_store();
@@ -416,6 +422,11 @@ protected static function generate_simple_product() {
416422
'gallery_image_ids' => $gallery,
417423
) );
418424

425+
// Set COGS if the feature is enabled.
426+
if ( wc_get_container()->get( 'Automattic\WooCommerce\Internal\CostOfGoodsSold\CostOfGoodsSoldController' )->feature_is_enabled() ) {
427+
$product->set_props( array( 'cogs_value' => round( $price * ( 1 - self::$faker->numberBetween( 15, 60 ) / 100 ), 2 ) ) );
428+
}
429+
419430
return $product;
420431
}
421432

0 commit comments

Comments
 (0)