I am currently working on an order form which allows editing order items like a SaaS landing page. There are created order items which can be customized using the purchased entity widgets. The problem, however, is that our widgets do not respect if the order item already has an existing field value.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mglaman created an issue. See original summary.

mglaman’s picture

Status: Active » Needs review
FileSize
1.36 KB

This allows me to embed the order item content entity form, re-use our widgets and allow customization on our custom cart form page.

agoradesign’s picture

I'm lacking the context, only read the patch file, but: why is there an order item inside commerce_product module? Is this safe to use without commerce_order?

mglaman’s picture

Because this widget only works for the commerce_order_item purchased_entity field. It's the product specific add to cart form widget. Since the add to cart form is supposed to be usable with any purchased entity type.

See

  /**
   * {@inheritdoc}
   */
  public static function isApplicable(FieldDefinitionInterface $field_definition) {
    $entity_type = $field_definition->getTargetEntityTypeId();
    $field_name = $field_definition->getName();
    return $entity_type == 'commerce_order_item' && $field_name == 'purchased_entity';
  }

The intent is we know this widget will only be on the create/edit form of an order item. Right now we just assume it's always "create" and never "edit".

agoradesign’s picture

ok, that makes sense :)

mglaman’s picture

bojanz’s picture

Status: Needs review » Needs work

Approach makes sense. Build didn't pass. Asked Matt for a rebase, to check against latest tests.

mglaman’s picture

Status: Needs work » Needs review
FileSize
2.42 KB

Fixed patch. It was due to the fact the order item always has a value for the purchased entity. Now the widget checks if the entity is new or not. If it is a new entity, load from context. Otherwise from value.

  • mglaman committed c93123f on 8.x-2.x
    Issue #2888231 by mglaman: Attribute widget should respect if order item...
mglaman’s picture

Status: Needs review » Fixed

Committed!

Status: Fixed » Closed (fixed)

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