dcco-8.x-3.x-dev/modules/dcco_store/modules/dcco_individual_sponsor/dcco_individual_sponsor.install

modules/dcco_store/modules/dcco_individual_sponsor/dcco_individual_sponsor.install
<?php

/**
 * Install, update, or uninstall scripts.
 */

/**
 * Implements hook_install().
 */
function dcco_individual_sponsor_install() {
  module_load_include('inc', 'dcco_store', 'inc/dcco_store');

  $size_attributes = dcco_store_create_attribute_values('camp_tshirt_size', [
    'Small',
    'Medium',
    'Large',
    'XL',
    '2XL',
    '3XL',
  ]);

  $products = [];
  $products[] = [
    'title' => '$25 Individual Sponsorship',
    'price' => '25.00',
    'sku' => '25',
  ];
  $products[] = [
    'title' => '$50 Individual Sponsorship',
    'price' => '50.00',
    'sku' => '50',
  ];
  $products[] = [
    'title' => '$100 Individual Sponsorship',
    'price' => '100.00',
    'sku' => '100',
  ];

  foreach ($products as $product) {
    $variations = array_map(function ($size_attribute) use ($product) {
      $size = strtolower($size_attribute->getName());
      return [
        'title' => $size_attribute->getName(),
        'type' => 'camp_individual_sponsorship',
        'price' => $product['price'],
        'sku' => "indiv_sponsor_{$product['sku']}_{$size}",
        'attribute_t_shirt_size' => $size_attribute,
      ];
    }, $size_attributes);

    $product['type'] = 'camp_individual_sponsorship';
    dcco_store_create_product($product, $variations);
  }
}

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

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