Problem/Motivation

FIX Code, add redirect if not isset product :
commerce_stock/modules/ui/src/Form/StockTransactions2.php

solution 1:

redirect in the form StockTransactions2.StockTransactions2.php

solution 2:

redirect to page 404

class ExampleRedirectSubscriber implements EventSubscriberInterface {

  /**
   * {@inheritdoc}
   */
  public function redirect(GetResponseEvent $event) {
    $request = $event->getRequest();
    $currentPath = $request->getPathInfo();
    if (
      '/admin/commerce/config/stock/transactions2' === $currentPath &&
      $request->query->has('commerce_product_v_id') &&
      !ProductVariation::load((int) $request->query->get('commerce_product_v_id'))
    ) {
      if (!$event->isMasterRequest()) {
        return;
      }
      throw new NotFoundHttpException();
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    return [
      KernelEvents::REQUEST => ['redirect', 100]
    ];
  }

}
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

arvodia created an issue. See original summary.

arvodia’s picture

Issue summary: View changes

arvodia’s picture

arvodia’s picture

Issue summary: View changes
guy_schneerson’s picture

Status: Active » Reviewed & tested by the community

Thanks @arvodia
I will use your code for sanding back to stock_transactions1 if not found and will add an error message to make it clear.

guy_schneerson’s picture

Assigned: arvodia » Unassigned
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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