{
	"$schema": "https://playground.wordpress.net/blueprint-schema.json",
	"meta": {
		"title": "23h Brand Ambassador demo",
		"description": "WooCommerce with demo brand ambassadors, visits and commissions.",
		"author": "23hevents",
		"categories": [
			"WooCommerce",
			"Affiliate"
		]
	},
	"landingPage": "/wp-admin/admin.php?page=bamb-dashboard",
	"preferredVersions": {
		"php": "8.3",
		"wp": "latest"
	},
	"features": {
		"networking": true
	},
	"steps": [
		{
			"step": "login",
			"username": "admin"
		},
		{
			"step": "installPlugin",
			"pluginData": {
				"resource": "wordpress.org/plugins",
				"slug": "woocommerce"
			},
			"options": {
				"activate": true
			}
		},
		{
			"step": "installPlugin",
			"pluginData": {
				"resource": "wordpress.org/plugins",
				"slug": "23h-brand-ambassador"
			},
			"options": {
				"activate": true
			}
		},
		{
			"step": "runPHP",
			"code": "<?php\nrequire_once '/wordpress/wp-load.php';\nwp_set_current_user( 1 );\n\nif ( class_exists( 'WC_Install' ) ) {\n\tWC_Install::install();\n}\n\n// WooCommerce: a ready store, no onboarding.\nupdate_option( 'woocommerce_currency', 'USD' );\nupdate_option( 'woocommerce_default_country', 'US:CA' );\nupdate_option( 'woocommerce_coming_soon', 'no' );\nupdate_option( 'woocommerce_onboarding_profile', array( 'skipped' => true ) );\nupdate_option( 'woocommerce_task_list_hidden', 'yes' );\nupdate_option( 'woocommerce_enable_signup_and_login_from_checkout', 'yes' );\nupdate_option( 'woocommerce_enable_guest_checkout', 'yes' );\nupdate_option( 'blogname', 'Demo Candle Shop' );\n\n$products = array();\nforeach ( array( 'Lavender Candle' => 28, 'Cedar Candle' => 32, 'Fig Diffuser' => 45, 'Gift Box' => 68 ) as $name => $price ) {\n\t$product = new WC_Product_Simple();\n\t$product->set_name( $name );\n\t$product->set_regular_price( $price );\n\t$product->set_status( 'publish' );\n\t$products[] = $product->save();\n}\n\n// The ambassador pages.\n$settings = get_option( 'bamb_settings', array() );\n$settings = is_array( $settings ) ? $settings : array();\nforeach ( array(\n\t'page_affiliate_account'        => array( 'Brand Ambassador Account', '[bamb_affiliate_account]' ),\n\t'page_affiliate_register'       => array( 'Become a Brand Ambassador', '[bamb_affiliate_registration]' ),\n\t'page_affiliate_reset_password' => array( 'Reset Password', '[bamb_affiliate_reset_password]' ),\n) as $key => $page ) {\n\t$settings[ $key ] = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => $page[0], 'post_content' => '<!-- wp:shortcode -->' . $page[1] . '<!-- /wp:shortcode -->' ) );\n}\n$settings['active_currency']       = 'USD';\n$settings['commission_rate_sale']  = 10;\n$settings['buyer_commission_rate'] = 5;\nupdate_option( 'bamb_settings', $settings );\n\n// Ambassadors.\n$affiliates = array();\nforeach ( array( 'Emma Carter', 'Liam Brooks', 'Olivia Hayes', 'Noah Bennett', 'Ava Morales', 'Mia Foster' ) as $i => $full_name ) {\n\tlist( $first, $last ) = explode( ' ', $full_name );\n\t$login   = strtolower( $first . '.' . $last );\n\t$user_id = wp_insert_user( array( 'user_login' => $login, 'user_email' => $login . '@example.com', 'user_pass' => wp_generate_password(), 'first_name' => $first, 'last_name' => $last, 'display_name' => $full_name, 'role' => 'customer' ) );\n\tif ( is_wp_error( $user_id ) ) {\n\t\tcontinue;\n\t}\n\t$affiliate = bamb_get_affiliate_by_user_id( $user_id );\n\tif ( empty( $affiliate ) ) {\n\t\t$date = gmdate( 'Y-m-d H:i:s', time() - ( 35 - $i * 4 ) * DAY_IN_SECONDS );\n\t\tbamb_insert_affiliate( array( 'user_id' => $user_id, 'date_created' => $date, 'date_modified' => $date, 'payment_email' => $login . '@example.com', 'status' => 'active', 'parent_id' => 0 ) );\n\t\t$affiliate = bamb_get_affiliate_by_user_id( $user_id );\n\t}\n\tif ( ! empty( $affiliate ) ) {\n\t\t$affiliates[] = $affiliate->get( 'id' );\n\t}\n}\n\n// Visits, orders and commissions over the last 30 days.\nmt_srand( 7 );\n$visits = array();\nfor ( $v = 0; $v < 90 && ! empty( $affiliates ); $v++ ) {\n\t$affiliate_id = $affiliates[ mt_rand( 0, count( $affiliates ) - 1 ) ];\n\t$date         = gmdate( 'Y-m-d H:i:s', time() - mt_rand( 0, 29 * DAY_IN_SECONDS ) );\n\t$visit_id     = bamb_insert_visit( array( 'affiliate_id' => $affiliate_id, 'date_created' => $date, 'date_modified' => $date, 'ip_address' => '', 'landing_url' => home_url( '/?ref=' . $affiliate_id ), 'referrer_url' => ( mt_rand( 0, 1 ) ? 'https://www.facebook.com/' : 'https://www.instagram.com/' ), 'commission_id' => 0 ) );\n\t$visits[]     = array( $visit_id, $affiliate_id, $date );\n}\n\n$statuses = array( 'paid', 'unpaid', 'unpaid', 'pending', 'unpaid', 'rejected' );\nfor ( $o = 0; $o < 14 && ! empty( $visits ); $o++ ) {\n\t$visit = $visits[ mt_rand( 0, count( $visits ) - 1 ) ];\n\t$order = wc_create_order();\n\t$order->add_product( wc_get_product( $products[ mt_rand( 0, count( $products ) - 1 ) ] ), mt_rand( 1, 2 ) );\n\t$order->set_billing_first_name( 'Demo' );\n\t$order->set_billing_last_name( 'Buyer ' . ( $o + 1 ) );\n\t$order->set_billing_email( 'buyer' . $o . '@example.com' );\n\t$order->calculate_totals();\n\t$status = $statuses[ $o % count( $statuses ) ];\n\t$order->set_status( 'pending' === $status ? 'processing' : ( 'rejected' === $status ? 'refunded' : 'completed' ) );\n\t$order->save();\n\t$date          = gmdate( 'Y-m-d H:i:s', strtotime( $visit[2] ) + HOUR_IN_SECONDS );\n\t$commission_id = bamb_insert_commission( array( 'affiliate_id' => $visit[1], 'visit_id' => $visit[0], 'date_created' => $date, 'date_modified' => $date, 'type' => 'sale', 'status' => $status, 'reference' => $order->get_id(), 'reference_amount' => $order->get_total(), 'customer_id' => 0, 'origin' => 'woo', 'amount' => round( $order->get_total() * 0.10, 2 ), 'parent_id' => 0, 'payment_id' => 0, 'currency' => 'USD' ) );\n\tbamb_update_visit( $visit[0], array( 'commission_id' => $commission_id ) );\n}\n\nbamb_insert_creative( array( 'name' => 'Share text', 'description' => 'Short text for social posts', 'date_created' => gmdate( 'Y-m-d H:i:s' ), 'date_modified' => gmdate( 'Y-m-d H:i:s' ), 'type' => 'text', 'image_url' => '', 'alt_text' => '', 'text' => 'I love these candles. Use my link and get 10% off your first order!', 'landing_url' => home_url( '/' ), 'status' => 'active', 'layout' => '' ) );\n\n// Keep the review notice out of the demo.\nupdate_option( 'bamb_dismissed_admin_notices', array( 'review_request' ) );\n"
		}
	]
}