You are here

function uc_product_node_type_insert in Ubercart 8.4

Implements hook_node_type_insert().

1 call to uc_product_node_type_insert()
uc_product_node_type_update in uc_product/uc_product.module
Implements hook_node_type_update().

File

uc_product/uc_product.module, line 968
The product module for Ubercart.

Code

function uc_product_node_type_insert(NodeTypeInterface $type) {
  if ($type
    ->getThirdPartySetting('uc_product', 'product', FALSE)) {
    uc_product_add_default_image_field($type
      ->id());
    $defaults = [
      'model' => '',
      'cost' => 0,
      'price' => 0,
      'weight' => 0,
      'weight_units' => \Drupal::config('uc_store.settings')
        ->get('weight.units'),
      'length' => 0,
      'width' => 0,
      'height' => 0,
      'length_units' => \Drupal::config('uc_store.settings')
        ->get('length.units'),
      'pkg_qty' => 1,
      'default_qty' => 1,
      'shippable' => $type
        ->getThirdPartySetting('uc_product', 'shippable', TRUE),
    ];
    $connection = \Drupal::database();
    $result = $connection
      ->query('SELECT n.vid, n.nid FROM {node} n LEFT JOIN {uc_products} p ON n.vid = p.vid WHERE n.type = :type AND p.vid IS NULL', [
      ':type' => $type
        ->id(),
    ]);
    foreach ($result as $node) {
      $connection
        ->insert('uc_products')
        ->fields($defaults + [
        'nid' => $node->nid,
        'vid' => $node->vid,
      ])
        ->execute();
    }
  }
}