uc_product.install in Ubercart 8.4
Same filename and directory in other branches
Install, update and uninstall functions for the uc_product module.
File
uc_product/uc_product.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the uc_product module.
*/
use Drupal\image\Entity\ImageStyle;
use Drupal\Core\Url;
/**
* Implements hook_schema().
*/
function uc_product_schema() {
$schema = [];
$schema['uc_product_features'] = [
'description' => 'Stores information of features added to products.',
'fields' => [
'pfid' => [
'description' => 'Primary key: the product feature id.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'nid' => [
'description' => 'The {node}.nid of the product that has this feature.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'fid' => [
'description' => 'The type of feature.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
],
'description' => [
'description' => 'The description of the feature.',
'type' => 'text',
],
],
'indexes' => [
'nid' => [
'nid',
],
],
'primary key' => [
'pfid',
],
'foreign keys' => [
'uc_product' => [
'table' => 'uc_product',
'columns' => [
'nid' => 'nid',
],
],
],
];
$schema['uc_products'] = [
'description' => 'Product information for nodes.',
'fields' => [
'vid' => [
'description' => 'The {node}.vid of the product.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'nid' => [
'description' => 'The {node}.nid of the product.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
],
'model' => [
'description' => 'SKU or model number.',
'type' => 'varchar',
'length' => 40,
'not null' => TRUE,
'default' => '',
],
'cost' => [
'description' => 'The amount the store pays to sell the product.',
'type' => 'numeric',
'precision' => 16,
'scale' => 5,
'not null' => TRUE,
'default' => 0.0,
],
'price' => [
'description' => 'The amount the customer pays for the product.',
'type' => 'numeric',
'precision' => 16,
'scale' => 5,
'not null' => TRUE,
'default' => 0.0,
],
'weight' => [
'description' => 'Physical weight.',
'type' => 'float',
'not null' => TRUE,
'default' => 0.0,
],
'weight_units' => [
'description' => 'Unit of measure for the weight field.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'lb',
],
'length' => [
'description' => 'Physical length of the product or its packaging.',
'type' => 'float',
'not null' => TRUE,
'default' => 0.0,
],
'width' => [
'description' => 'Physical width of the product or its packaging.',
'type' => 'float',
'not null' => TRUE,
'default' => 0.0,
],
'height' => [
'description' => 'Physical height of the product or its packaging.',
'type' => 'float',
'not null' => TRUE,
'default' => 0.0,
],
'length_units' => [
'description' => 'Unit of measure for the length, width, and height.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => 'in',
],
'pkg_qty' => [
'description' => 'The number of this product that fit in one package.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
],
'default_qty' => [
'description' => 'The default value for the quantity field in the "Add to Cart" form.',
'type' => 'int',
'size' => 'small',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
],
'shippable' => [
'description' => 'Boolean flag signifying that the product can be shipped.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
],
],
'indexes' => [
'nid' => [
'nid',
],
],
'primary key' => [
'vid',
],
'foreign keys' => [
'node' => [
'table' => 'node',
'columns' => [
'nid' => 'nid',
'vid' => 'vid',
],
],
],
];
return $schema;
}
/**
* Implements hook_uninstall().
*/
function uc_product_uninstall() {
$styles = ImageStyle::loadMultiple([
'uc_product',
'uc_thumbnail',
]);
if (!empty($styles)) {
$style_names = [];
foreach ($styles as $style) {
$style_names[] = $style
->label();
}
\Drupal::messenger()
->addWarning(\Drupal::translation()
->formatPlural(count($style_names), 'The image style %style has not been deleted. If you need to delete it, <a href=":url">please do so manually</a>.', 'The image styles %styles have not been deleted. If you need to delete them, <a href=":url">please do so manually</a>.', [
'%style' => $style_names[0],
'%styles' => implode(', ', $style_names),
':url' => Url::fromRoute('entity.image_style.collection')
->toString(),
]));
}
}
Functions
Name | Description |
---|---|
uc_product_schema | Implements hook_schema(). |
uc_product_uninstall | Implements hook_uninstall(). |