1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/WeeShop-WeeShop

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
weeshop.install 3.5 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Kent Отправлено 23.11.2021 17:10 e118e28
<?php
/**
* @file
* Install, update and uninstall functions for the commerce_base installation profile.
*/
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
use Drupal\user\UserInterface;
/**
* Implements hook_install().
*
* Perform actions to set up the site for this profile.
*
* @see system_install()
*/
function weeshop_install() {
// Set front page to "node".
\Drupal::configFactory()->getEditable('system.site')->set('page.front', '/node')->save(TRUE);
// Allow visitor account creation with administrative approval.
$user_settings = \Drupal::configFactory()->getEditable('user.settings');
$user_settings->set('register', UserInterface::REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)->save(TRUE);
// Enable default permissions for system roles.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access comments']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access comments', 'post comments', 'skip comment approval']);
// Assign user 1 the "administrator" role.
$user = User::load(1);
$user->roles[] = 'administrator';
$user->save();
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['access site-wide contact form']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['access site-wide contact form']);
// Allow all users to use search.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, ['search content']);
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, ['search content']);
// Enable the admin theme.
\Drupal::configFactory()->getEditable('node.settings')->set('use_admin_theme', TRUE)->save(TRUE);
// Set Default user picture.
_weeshop_set_default_user_picture();
$permissions = [
'use search_api_autocomplete for product_search'
];
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, $permissions);
_weeshop_set_shipping();
}
function _weeshop_set_default_user_picture() {
$avatar_path = \Drupal::config('system.file')->get('default_scheme') . '://default_user_picture.png';
$file = file_save_data(file_get_contents(__DIR__.'/assets/image/default_user_picture.png'), $avatar_path, \Drupal\Core\File\FileSystemInterface::EXISTS_REPLACE);
\Drupal::configFactory()->getEditable('field.field.user.user.user_picture')
->set('settings.default_image.uuid', $file->uuid())
->set('alt', 'Default user picture')
->set('title', 'Default user picture')
->save(TRUE);
}
function _weeshop_set_shipping(){
\Drupal::configFactory()->getEditable('commerce_order.commerce_order_type.default')
->set('workflow', 'order_fulfillment')
->set('third_party_settings.commerce_checkout.checkout_flow', 'shipping')
->set('third_party_settings.commerce_shipping.shipment_type', 'default')
->save(TRUE);
// Create the order field.
$field_definition = commerce_shipping_build_shipment_field_definition('default');
\Drupal::service('commerce.configurable_field_manager')->createField($field_definition);
\Drupal\commerce_shipping\Entity\ShippingMethod::create([
'stores' => [1,2,3],
'plugin' => [
'target_plugin_id' => 'flat_rate',
'target_plugin_configuration' => [
'rate_label' => '固定邮费',
'rate_description' => '',
'rate_amount' => [
'number' => '10',
'currency_code' => 'CNY'
],
'services' => ['default'],
'default_package_type' => 'custom_box',
'workflow' => 'shipment_default',
]
],
'name' => '普通快递'
])->save();
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/WeeShop-WeeShop.git
git@api.gitlife.ru:oschina-mirror/WeeShop-WeeShop.git
oschina-mirror
WeeShop-WeeShop
WeeShop-WeeShop
8.x-1.x