Comments

czigor created an issue. See original summary.

czigor’s picture

Title: Create an OrderProductType condition » Create an OrderItemProductType condition
czigor’s picture

Status: Active » Needs review
StatusFileSize
new6.83 KB

Unit test is included in the patch.

czigor’s picture

- Using 'commerce_entity_select' instead of a plain 'select'
- Fixing some docblocks.

bojanz’s picture

Status: Needs review » Needs work
+  /**
+   * The product storage.
+   *
+   * @var \Drupal\Core\Entity\EntityStorageInterface
+   */
+  protected $productStorage;
+
+  /**
+   * Constructs a new OrderItemProductType object.
+   *
+   * @param array $configuration
+   *   The plugin configuration, i.e. an array with configuration values keyed
+   *   by configuration option name.
+   * @param string $plugin_id
+   *   The plugin_id for the plugin instance.
+   * @param mixed $plugin_definition
+   *   The plugin implementation definition.
+   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
+   *   The entity type manager.
+   */
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
+    parent::__construct($configuration, $plugin_id, $plugin_definition);
+
+    $this->productStorage = $entity_type_manager->getStorage('commerce_product');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+    return new static(
+      $configuration,
+      $plugin_id,
+      $plugin_definition,
+      $container->get('entity_type.manager')
+    );
+  }

You're injecting the product storage, but never using it.

+  /**
+   * {@inheritdoc}
+   */
+  public function defaultConfiguration() {
+    return [
+      'products' => [],
+    ] + parent::defaultConfiguration();
+  }

This key is wrong.

Also, no config schema has been added.

bojanz’s picture

+    // Order item with a variation belong to glass product.
+    $product_entity = $this->prophesize(ProductInterface::class);
+    $product_entity->bundle()->willReturn('glass');
+    $product_entity = $product_entity->reveal();

Why call it the $product_entity? We don't suffix variables that way.

+    $purchased_entity = $this->prophesize(ProductVariationInterface::class);
+    $purchased_entity->getEntityTypeId()->willReturn('commerce_product_variation');
+    $purchased_entity->getProduct()->willReturn($product_entity);
+    $purchased_entity = $purchased_entity->reveal();

This is a $product_variation, no?

  • bojanz committed 1305282 on 8.x-2.x authored by czigor
    Issue #2905071 by czigor: Create an OrderItemProductType condition
    
bojanz’s picture

Status: Needs work » Fixed

Addressed the feedback and committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.