orange_ecom_profile-2.0.x-dev/orange_ecom_profile.install

orange_ecom_profile.install
<?php

/**
 * @file
 * Install, update & uninstall functions for orange_ecom_profile.
 */

use Drupal\taxonomy\Entity\Term;
use Drupal\commerce_store\Entity\Store;

/**
 * Implements hook_install().
 */
function orange_ecom_profile_install() {

  // First, do everything in Orange profile.
  include_once DRUPAL_ROOT . '/profiles/contrib/orange_profile/orange_profile.install';
  orange_profile_install();

  // Create sample product categories.
  $product_category_term = Term::create([
    'name' => 'Clothing',
    'vid' => 'product_categories',
  ]);
  $product_category_term->save();

  $product_category_term_2 = Term::create([
    'name' => 'Equipment',
    'vid' => 'product_categories',
  ]);
  $product_category_term_2->save();

  // Create sample brands.
  $brand_term = Term::create([
    'name' => 'Google',
    'vid' => 'brands',
  ]);
  $brand_term->save();

  $brand_term_2 = Term::create([
    'name' => 'Amazon',
    'vid' => 'brands',
  ]);
  $brand_term_2->save();

  // Create a store for Commerce.
  $address = [
    'country_code' => 'CA',
    'address_line1' => '123 Test Street',
    'locality' => 'Kelowna',
    'administrative_area' => 'BC',
    'postal_code' => 'V1X5V1',
  ];

  // The currency code.
  $currency = 'CAD';

  // If needed, this will import the currency.
  $currency_importer = \Drupal::service('commerce_price.currency_importer');
  $currency_importer->import($currency);

  $store = Store::create([
    'type' => 'online',
    'uid' => 1,
    'name' => 'Store',
    'mail' => 'webadmin@acromedia.com',
    'address' => $address,
    'default_currency' => $currency,
    'billing_countries' => [
      'CA',
    ],
  ]);
  $store->save();

  // If needed, this sets the store as the default store.
  /** @var \Drupal\commerce_store\Entity\Store $store_storage */
  $store_storage = \Drupal::entityTypeManager()->getStorage('commerce_store');
  $store_storage->markAsDefault($store);

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc