It's not possible to create a product or an order if there are no stores. The UX is weird, cause the store field repeatedly fails validation.

We should create a trait and use it in ProductForm / OrderForm, outputting a red box with a message (containing a link to the store add form, with a destination back to the current form) instead of the actual form.

Comments

bojanz created an issue. See original summary.

bojanz’s picture

We can place the trait in \Drupal\commerce_store\Form\StoreWarningTrait.

The order and product form would use the trait, call $this->buildStoreWarning(), and if the output is not empty, replace the form with the warning.
The buildStoreWarning() method would do an entity query to get the number of stores, if the count is 0, return the warning element.

harings_rob’s picture

Assigned: Unassigned » harings_rob

I will work on this.

bojanz’s picture

Status: Active » Fixed

I've committed an improved version of this in https://github.com/drupalcommerce/commerce/commit/e837ba054b07d5a1857924...

I ended up removing the trait and repeating the code in both forms, since it's a small amount of code reliant on external dependencies, and because I wanted different messages on the two forms.

Worth mentioning:

 +      $options = [
 +        'query' => [
 +          'destination' => Url::fromRoute('<current>')->toString(),
 +        ],
 +      ];
 +      $link = Link::createFromRoute('Add a new store.', 'entity.commerce_store.add_page', [], $options);

Turns out the current url can be received using the trick above. Didn't know that.
Also decided to hardcode the route to the add page, since it follows standards and can't change.

  • bojanz committed e837ba0 on 8.x-2.x authored by harings_rob
    Issue #2656768 by harings_rob: Hide the product / order forms if there...
harings_rob’s picture

Hi,

Looks better now.

It's good that I can see how you changed it. Gives me a better view on how things are done.

Regards,

Status: Fixed » Closed (fixed)

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