Verified Commit 098dc803 authored by quietone's avatar quietone
Browse files

Issue #3270534 by quietone, benjifisher, DamienMcKenna: Test failures with PHP 8.1

parent eb79e51d
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\commerce_migrate_commerce\Attributes;
use Drupal\commerce_migrate_commerce\Plugin\migrate\source\commerce1\Profile;
use Drupal\field\Plugin\migrate\source\d7\Field;
use Drupal\field\Plugin\migrate\source\d7\FieldInstance;
@@ -13,7 +14,6 @@ use Drupal\field\Plugin\migrate\source\d7\FieldInstancePerFormDisplay;
use Drupal\field\Plugin\migrate\source\d7\FieldInstancePerViewMode;
use Drupal\field\Plugin\migrate\source\d7\ViewMode;
use Drupal\migrate\Exception\RequirementsException;
use Drupal\migrate\Plugin\MigrationDeriverTrait;
use Drupal\migrate_drupal\Plugin\migrate\FieldMigration;
use Drupal\node\Plugin\migrate\source\d7\Node;
use Drupal\taxonomy\Plugin\migrate\source\d7\Term;
@@ -307,19 +307,14 @@ function _commerce_migrate_commerce_get_field_name() {
 *   An array of taxonomy vocabularies that are product attributes..
 */
function _commerce_migrate_commerce_get_attributes() {
  $source_plugin = MigrationDeriverTrait::getSourcePlugin('d7_field_instance');
  $rows = Attributes::getAttributeRows();
  $attributes = [];
  foreach ($source_plugin as $row) {
    if (($row->getSourceProperty('entity_type') == 'commerce_product') &&
      ($row->getSourceProperty('type') == 'taxonomy_term_reference') &&
      ($row->getSourceProperty('widget')['type'] == 'options_select')) {
      // Get all bundles for this field.
  foreach ($rows as $row) {
    $field_definition = $row->getSourceProperty('field_definition');
    $data = unserialize($field_definition['data']);
    foreach ($data['settings']['allowed_values'] as $allowed_value) {
      $attributes[] = $allowed_value['vocabulary'];
    }
  }
  }
  return array_unique($attributes);
}
+30 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\commerce_migrate_commerce;

use Drupal\migrate\Plugin\MigrationDeriverTrait;

/**
 * Get the attribute rows from the d7_field_instance source plugin.
 */
class Attributes {

  use MigrationDeriverTrait;

  /**
   * Get d7_field_instance rows that are for product attributes.
   *
   * @return \Drupal\migrate\Row[]
   *   The source plugin rows that are for taxonomy term reference fields, that
   *   are using options select and for commerce products.
   */
  public static function getAttributeRows() {
    $source_plugin = self::getSourcePlugin('d7_field_instance');
    return array_filter(iterator_to_array($source_plugin), function ($row) {
      return (($row->getSourceProperty('entity_type') == 'commerce_product') &&
        ($row->getSourceProperty('type') == 'taxonomy_term_reference') &&
        ($row->getSourceProperty('widget')['type'] == 'options_select'));
    });
  }

}
+3 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 */
class MigratePrepareRow implements EventSubscriberInterface {

  use MigrationDeriverTrait;

  /**
   * Product node types.
   *
@@ -94,7 +96,7 @@ class MigratePrepareRow implements EventSubscriberInterface {
   *   An array of taxonomy vocabularies that are product attributes..
   */
  protected function getAttributes() {
    $source_plugin = MigrationDeriverTrait::getSourcePlugin('d7_field_instance');
    $source_plugin = $this->getSourcePlugin('d7_field_instance');
    $attributes = [];
    foreach ($source_plugin as $row) {
      if (($row->getSourceProperty('entity_type') == 'commerce_product') &&
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ class OrderItemDeriver extends DeriverBase implements ContainerDeriverInterface

          $values['label'] = $this->t('@label (@type)', [
            '@label' => $values['label'],
            '@type' => $row->getSourceProperty('name'),
            '@type' => $row->getSourceProperty('type'),
          ]);
          $values['source']['line_item_type'] = $line_item_type;
          $values['destination']['default_bundle'] = $line_item_type;
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ class ProductDeriver extends DeriverBase implements ContainerDeriverInterface {

        $values['label'] = $this->t('@label (@type)', [
          '@label' => $values['label'],
          '@type' => $row->getSourceProperty('name'),
          '@type' => $row->getSourceProperty('type'),
        ]);
        $values['source']['product_type'] = $product_type;
        $values['destination']['default_bundle'] = $product_type;
Loading