{
  "$schema": "https://playground.wordpress.net/blueprint-schema.json",
  "landingPage": "/",
  "preferredVersions": {
    "php": "8.3",
    "wp": "7.1"
  },
  "login": false,
  "meta": {
    "title": "Lake & Line print shop",
    "author": "Kit Rx",
    "description": "A self-contained WooCommerce demonstration. All orders use a practice payment method."
  },
  "steps": [
    {
      "step": "setSiteOptions",
      "options": {
        "blogname": "Lake & Line",
        "blog_public": "0",
        "woocommerce_allow_tracking": "no",
        "woocommerce_custom_orders_table_enabled": "no"
      }
    },
    {
      "step": "installPlugin",
      "pluginData": {
        "resource": "url",
        "url": "https://downloads.wordpress.org/plugin/woocommerce.11.3.0.zip"
      },
      "options": {
        "activate": true
      }
    },
    {
      "step": "installTheme",
      "themeData": {
        "resource": "url",
        "url": "https://kit-rx.com/samples/woocommerce/lake-line-theme.zip"
      },
      "options": {
        "activate": true,
        "importStarterContent": false
      }
    },
    {
      "step": "writeFile",
      "path": "/tmp/lake-line-catalog.json",
      "data": "[{\"sku\": \"LL-WAVE\", \"name\": \"Under the Wave\", \"slug\": \"wave\", \"artist\": \"Katsushika Hokusai\", \"date\": \"1830–33\", \"price\": 24, \"description\": \"A deep blue wave curls above three narrow fishing boats. Mount Fuji sits low on the distant horizon.\", \"format\": \"Landscape print, 14 × 10 inches.\", \"alt\": \"A curling blue wave with white foam above boats and a distant Mount Fuji.\", \"record\": \"https://www.artic.edu/artworks/24645\"}, {\"sku\": \"LL-PLUM\", \"name\": \"Plum Garden at Kameido\", \"slug\": \"plum\", \"artist\": \"Utagawa Hiroshige\", \"date\": \"1857\", \"price\": 28, \"description\": \"A dark plum trunk divides the foreground. White blossoms hang over small figures in the garden beneath a red sky.\", \"format\": \"Portrait print, 10 × 14 inches.\", \"alt\": \"A dark plum tree with white blossoms above visitors in a green garden and red sky.\", \"record\": \"https://www.artic.edu/artworks/26577\"}, {\"sku\": \"LL-CRANES\", \"name\": \"Cranes on Snow-Covered Pine\", \"slug\": \"cranes\", \"artist\": \"Katsushika Hokusai\", \"date\": \"c. 1834\", \"price\": 32, \"description\": \"Two cranes balance on pine branches under the snow. One bird spreads its dark-tipped wings across the narrow frame.\", \"format\": \"Tall portrait print, 7 × 15 inches.\", \"alt\": \"Two cranes perch on snow-covered pine, one spreading its wings.\", \"record\": \"https://www.artic.edu/artworks/21720\"}]"
    },
    {
      "step": "writeFile",
      "path": "/tmp/lake-line-wave.jpg",
      "data": {
        "resource": "url",
        "url": "https://kit-rx.com/samples/woocommerce/wave.jpg"
      }
    },
    {
      "step": "writeFile",
      "path": "/tmp/lake-line-plum.jpg",
      "data": {
        "resource": "url",
        "url": "https://kit-rx.com/samples/woocommerce/plum.jpg"
      }
    },
    {
      "step": "writeFile",
      "path": "/tmp/lake-line-cranes.jpg",
      "data": {
        "resource": "url",
        "url": "https://kit-rx.com/samples/woocommerce/cranes.jpg"
      }
    },
    {
      "step": "runPHP",
      "code": "<?php\nrequire '/wordpress/wp-load.php';\nrequire_once WP_PLUGIN_DIR . '/woocommerce/includes/admin/wc-admin-functions.php';\nif (!class_exists('WooCommerce')) {\n    throw new RuntimeException('WooCommerce is required to install this store.');\n}\n$catalog = json_decode(file_get_contents('/tmp/lake-line-catalog.json'), true, 512, JSON_THROW_ON_ERROR);\nwc_create_page('shop', 'woocommerce_shop_page_id', 'Prints', '');\nwc_create_page('cart', 'woocommerce_cart_page_id', 'Shopping bag', '[woocommerce_cart]');\nwc_create_page('checkout', 'woocommerce_checkout_page_id', 'Checkout', '[woocommerce_checkout]');\nwc_create_page('my-account', 'woocommerce_myaccount_page_id', 'My account', '[woocommerce_my_account]');\nforeach (array('cart' => '[woocommerce_cart]', 'checkout' => '[woocommerce_checkout]', 'myaccount' => '[woocommerce_my_account]') as $page => $shortcode) {\n    $id = wc_get_page_id($page);\n    if ($id > 0) {\n        wp_update_post(array('ID' => $id, 'post_content' => $shortcode));\n    }\n}\n$settings = array(\n    'blogname' => 'Lake & Line', 'blogdescription' => 'Japanese woodblock prints',\n    'blog_public' => '0', 'woocommerce_store_country' => 'US:NY',\n    'woocommerce_default_country' => 'US:NY', 'woocommerce_currency' => 'USD',\n    'woocommerce_default_customer_address' => 'base', 'woocommerce_price_num_decimals' => 0,\n    'woocommerce_enable_guest_checkout' => 'yes', 'woocommerce_enable_checkout_login_reminder' => 'no',\n    'woocommerce_enable_signup_and_login_from_checkout' => 'no', 'woocommerce_enable_myaccount_registration' => 'no',\n    'woocommerce_cheque_settings' => array('enabled' => 'yes', 'title' => 'Demo order', 'description' => 'Place a practice order using the sample address. No payment is collected.', 'instructions' => 'Your practice order is complete. Nothing will be charged or shipped.'),\n    'woocommerce_calc_taxes' => 'no', 'woocommerce_hide_out_of_stock_items' => 'yes',\n    'woocommerce_allow_tracking' => 'no', 'woocommerce_custom_orders_table_enabled' => 'no',\n    'woocommerce_coming_soon' => 'no',\n    'woocommerce_task_list_hidden' => 'yes', 'woocommerce_admin_install_timestamp' => time(),\n    'woocommerce_onboarding_profile' => array('completed'=>true,'skipped'=>true),\n    'woocommerce_checkout_privacy_policy_text' => '', 'woocommerce_terms_page_id' => 0,\n);\nforeach ($settings as $key => $value) {\n    update_option($key, $value);\n}\n$home = get_page_by_path('collection-home');\nif (!$home) {\n    $home_id = wp_insert_post(array('post_title' => 'Lake & Line', 'post_name' => 'collection-home', 'post_type' => 'page', 'post_status' => 'publish'));\n} else {\n    $home_id = $home->ID;\n}\nupdate_option('show_on_front', 'page');\nupdate_option('page_on_front', $home_id);\n$category = term_exists('Woodblock prints', 'product_cat') ?: wp_insert_term('Woodblock prints','product_cat',array('slug'=>'woodblock-prints'));\nif (is_wp_error($category)) {\n    throw new RuntimeException($category->get_error_message());\n}\n$category_id = is_array($category) ? (int) $category['term_id'] : (int) $category;\n$uploads = wp_upload_dir();\nwp_mkdir_p($uploads['path']);\nforeach ($catalog as $item) {\n    $product_id = wc_get_product_id_by_sku($item['sku']);\n    $product = $product_id ? wc_get_product($product_id) : new WC_Product_Simple();\n    if (!$product_id) {\n        $product->set_sku($item['sku']);\n    }\n    $product->set_name($item['name']);\n    $product->set_slug($item['slug']);\n    $product->set_featured($item['sku'] === 'LL-WAVE');\n    $product->set_regular_price((string) $item['price']);\n    $product->set_status('publish');\n    $product->set_catalog_visibility('visible');\n    $product->set_category_ids(array($category_id));\n    $product->set_virtual(false);\n    $product->set_sold_individually(false);\n    $product->set_stock_status('instock');\n    $product->set_short_description('<p>'.esc_html($item['artist'].' · '.$item['date']).'</p><p>'.esc_html($item['description']).'</p>');\n    $product->set_description('<p>'.esc_html($item['format']).' This sample represents an unframed reproduction on paper.</p><p>Public-domain artwork, Clarence Buckingham Collection, Art Institute of Chicago. <a href=\"'.esc_url($item['record']).'\">View the collection record</a>.</p>');\n    $product->update_meta_data('_ll_artist', $item['artist']);\n    $attachment_id = $product->get_image_id();\n    if (!$attachment_id) {\n        $filename = $item['slug'].'.jpg';\n        $destination = $uploads['path'].'/'.$filename;\n        if (!copy('/tmp/lake-line-'.$filename, $destination)) {\n            throw new RuntimeException('Missing artwork image: '.$filename);\n        }\n        $attachment_id = wp_insert_attachment(array('post_title' => $item['name'], 'post_mime_type'=>'image/jpeg', 'post_status'=>'inherit'),$destination,0,true);\n        if (is_wp_error($attachment_id)) {\n            throw new RuntimeException($attachment_id->get_error_message());\n        }\n        $size = getimagesize($destination);\n        wp_update_attachment_metadata($attachment_id, array('width'=>$size[0], 'height'=>$size[1], 'file'=>_wp_relative_upload_path($destination), 'sizes'=>array()));\n        update_post_meta($attachment_id,'_wp_attachment_image_alt',$item['alt']);\n        $product->set_image_id($attachment_id);\n    }\n    $product->save();\n}\n$zone = new WC_Shipping_Zone(0);\n$flat_id = 0;\nforeach ($zone->get_shipping_methods() as $method) {\n    if ($method->id === 'flat_rate') {\n        $flat_id = $method->get_instance_id();\n        break;\n    }\n}\nif (!$flat_id) {\n    $flat_id = $zone->add_shipping_method('flat_rate');\n}\nupdate_option('woocommerce_flat_rate_'.$flat_id.'_settings', array('title'=>'Print shipping','tax_status'=>'none','cost'=>'5'));\nupdate_user_meta(1, 'show_admin_bar_front', 'false');\nflush_rewrite_rules(false);\n"
    }
  ]
}
