示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     // Create a store.
     $values = ['name' => t('Default store'), 'uid' => 1, 'mail' => \Drupal::config('system.site')->get('mail'), 'type' => 'default', 'default_currency' => 'USD', 'address' => ['country_code' => 'GB', 'locality' => 'London', 'postal_code' => 'NW1 6XE', 'address_line1' => '221B Baker Street']];
     $this->store = Store::create($values);
     $this->store->save();
     // Set as default store.
     \Drupal::configFactory()->getEditable('commerce_store.settings')->set('default_store', $this->store->uuid())->save();
     // Create a product variation.
     $values = ['type' => 'default', 'sku' => $this->randomMachineName(), 'price' => ['amount' => 999, 'currency_code' => 'USD']];
     $this->variation = ProductVariation::create($values);
     $this->variation->save();
     // We need a product too otherwise tests complain about the missing
     // backreference.
     $this->createEntity('commerce_product', ['type' => 'default', 'title' => $this->randomMachineName(), 'stores' => [$this->store], 'variations' => [$this->variation]]);
 }
示例#2
0
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('local_tasks_block');
     $this->drupalPlaceBlock('local_actions_block');
     $this->drupalPlaceBlock('page_title_block');
     $this->adminUser = $this->drupalCreateUser(['administer orders', 'administer order types', 'administer line item types', 'access administration pages']);
     // Create a store
     $values = ['name' => t('Default store'), 'uid' => 1, 'mail' => \Drupal::config('system.site')->get('mail'), 'type' => 'default', 'default_currency' => 'USD', 'address' => ['country_code' => 'GB', 'locality' => 'London', 'postal_code' => 'NW1 6XE', 'address_line1' => '221B Baker Street']];
     $this->store = Store::create($values);
     $this->store->save();
     // Set as default store.
     \Drupal::configFactory()->getEditable('commerce_store.settings')->set('default_store', $this->store->uuid())->save();
     // Create a product variation.
     $values = ['type' => 'default', 'sku' => $this->randomMachineName()];
     $this->variation = ProductVariation::create($values);
     $this->variation->save();
     // We need a product too otherwise tests complain about the missing
     // backreference.
     $this->createEntity('commerce_product', ['type' => 'default', 'title' => $this->randomMachineName(), 'variations' => [$this->variation]]);
     $this->drupalLogin($this->adminUser);
 }
示例#3
0
 public function migrateNcdProductVariation($import)
 {
     $query = \Drupal::entityQuery('commerce_product_variation')->condition('field_old_id', $import->product_id);
     $newId = $query->execute();
     if (!empty($newId)) {
         $newId = array_pop($newId);
         $targetEntity = ProductVariation::load($newId);
         // dpm($targetEntity);
     } else {
         $targetEntity = ProductVariation::create(array('type' => $import->type == 'bundle' ? 'device' : 'accessory', 'sku' => $import->sku));
     }
     $targetEntity->field_picture = $this->processFile($import->field_picture[$import->language]);
     $targetEntity->field_wiring_diagram = $this->processFile($import->field_wiring_diagram[$import->language]);
     $targetEntity->field_mechanical_drawing = $this->processFile($import->field_mechanical_drawing[$import->language]);
     $targetEntity->field_unique_datasheets = $this->processFile($import->field_unique_datasheets[$import->language]);
     $targetEntity->field_documents = $this->processFile($import->field_documents[$import->language]);
     $targetEntity->sku = $import->sku;
     $targetEntity->field_title = $import->title ?? 'No Title';
     $targetEntity->price = array('amount' => $import->commerce_price[$import->language]['0']['amount'] / 100.0 ?? '0', 'currency_code' => 'USD');
     $targetEntity->cost = array('amount' => $import->field_cost[$import->language]['0']['amount'] / 100.0 ?? '0', 'currency_code' => 'USD');
     $targetEntity->field_assigned_categories = $this->convertCategoryAssignment($import->field_assigned_categories[$import->language]);
     $targetEntity->field_at_a_glance_items = $this->constructArray($import->field_at_a_glance_items[$import->language]);
     $targetEntity->status = $import->status;
     $targetEntity->field_prod_bod = $import->field_prod_bod[$import->language]['0']['value'] ?? '';
     $targetEntity->field_ac_or_dc_dimming = $import->field_ac_or_dc_dimming[$import->language]['0']['value'] ?? '';
     $targetEntity->field_board_location = $import->field_board_location[$import->language]['0']['value'] ?? '';
     $targetEntity->field_github_repository = $import->field_github_repository[$import->language]['0']['value'] ?? '';
     $targetEntity->field_maximum_board_current_cons = $import->field_maximum_board_current_cons[$import->language]['0']['value'] ?? '';
     $targetEntity->field_maximum_potentiometer_ampe = $import->field_maximum_potentiometer_ampe[$import->language]['0']['value'] ?? '';
     $targetEntity->field_maximum_potentiometer_volt = $import->field_maximum_potentiometer_volt[$import->language]['0']['value'] ?? '';
     $targetEntity->field_maximum_voltage = $import->field_maximum_voltage[$import->language]['0']['value'] ?? '';
     $targetEntity->field_minimum_board_current_cons = $import->field_minimum_board_current_cons[$import->language]['0']['value'] ?? '';
     $targetEntity->field_minimum_voltage = $import->field_minimum_voltage[$import->language]['0']['value'] ?? '';
     $targetEntity->field_nominal_voltage = $import->field_nominal_voltage[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_adc_inputs = $import->field_number_of_adc_inputs[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_contact_closures = $import->field_number_of_contact_closures[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_current_sensors = $import->field_number_of_current_sensors[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_dacs = $import->field_number_of_dacs[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_digital_io_ports = $import->field_number_of_digital_io_ports[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_dimmers = $import->field_number_of_dimmers[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_fets = $import->field_number_of_fets[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_motor_controller = $import->field_number_of_motor_controller[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_open_collectors = $import->field_number_of_open_collectors[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_potentiometers = $import->field_number_of_potentiometers[$import->language]['0']['value'] ?? '';
     $targetEntity->field_number_of_relays = $import->field_number_of_relays[$import->language]['0']['value'] ?? '';
     $targetEntity->field_part_bins = $import->field_part_bins[$import->language]['0']['value'] ?? '';
     $targetEntity->field_filepath = $import->field_filepath[$import->language]['0']['value'] ?? '';
     $targetEntity->field_potentiometer_resistance = $import->field_potentiometer_resistance[$import->language]['0']['value'] ?? '';
     $targetEntity->field_relay_ac_amperage = $import->field_relay_ac_amperage[$import->language]['0']['value'] ?? '';
     $targetEntity->field_relay_type = $import->field_relay_type[$import->language]['0']['value'] ?? '';
     $targetEntity->field_resolution_of_adc_inputs = $import->field_resolution_of_adc_inputs[$import->language]['0']['value'] ?? '';
     $targetEntity->field_resolution_of_dac_inputs = $import->field_resolution_of_dac_inputs[$import->language]['0']['value'] ?? '';
     //    $targetEntity->field_uses_power_supply = $import->field_uses_power_supply[$import->language]['0']['value'] ?? 0;
     $targetEntity->field_wattage_per_channel = $import->field_wattage_per_channel[$import->language]['0']['value'] ?? '';
     $targetEntity->field_old_id = $import->product_id;
     $targetEntity->save();
 }