Commit 97fa55e9 authored by Pedro Cambra's avatar Pedro Cambra
Browse files

Issue #3326571 by pcambra: Unable to delete tickets

parent f3e0aad1
Loading
Loading
Loading
Loading
+12 −20
Original line number Diff line number Diff line
@@ -73,9 +73,9 @@ class OrderEventSubscriber implements EventSubscriberInterface {
      'commerce_order.validate.post_transition' => ['onValidateTransition'],
      'commerce_order.fulfill.post_transition' => ['onFulfillTransition'],
      'commerce_order.cancel.post_transition' => ['onCancelTransition'],
      OrderEvents::ORDER_PRESAVE => ['onOrderPresave', -100],
      OrderEvents::ORDER_DELETE => ['onOrderDelete', -100],
      OrderEvents::ORDER_ASSIGN => ['onOrderAssign'],
      OrderEvents::ORDER_PAID => ['onOrderPaid'],
    ];
  }

@@ -93,6 +93,8 @@ class OrderEventSubscriber implements EventSubscriberInterface {
    $this->autoActivateTickets($order);
  }



  /**
   * Create the order's tickets when the order is fulfilled.
   *
@@ -124,7 +126,7 @@ class OrderEventSubscriber implements EventSubscriberInterface {
  }

  /**
   * Event listener for order presave event.
   * Event listener for order paid event.
   *
   * @param \Drupal\commerce_order\Event\OrderEvent $orderEvent
   *   The order event.
@@ -133,18 +135,10 @@ class OrderEventSubscriber implements EventSubscriberInterface {
   * @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  public function onOrderPresave(OrderEvent $orderEvent) {
  public function onOrderPaid(OrderEvent $orderEvent) {
    $order = $orderEvent->getOrder();

    // Allow other modules to abort the ticket creation.
    if (!empty($order->ignore_update)) {
      return;
    }

    // Automatically create tickets for all placed orders.
    if ($order->getState()->getId() != 'draft') {
      // Only proceed, if order is paid.
      if ($order->isPaid()) {
    $this->createTickets($order);
    $this->autoActivateTickets($order);

@@ -155,8 +149,6 @@ class OrderEventSubscriber implements EventSubscriberInterface {
      $this->sendTicketMails($order);
    }
  }
    }
  }

  /**
   * Event listener for order delete event.
+12 −5
Original line number Diff line number Diff line
@@ -2,8 +2,7 @@

namespace Drupal\Tests\commerce_ticketing\Functional;

use Drupal\commerce_order\Entity\Order;
use Drupal\user\RoleInterface;
use Drupal\commerce_ticketing\Entity\CommerceTicket;

/**
 * Tests commerce order relationship with tickets.
@@ -61,16 +60,24 @@ class TicketOrderTest extends TicketBrowserTestBase {
  }

  /**
   * Tests removing tickets when order is deleted.
   * Tests removing tickets from an order.
   */
  public function testRemoveFromOrder() {
  public function testRemoveTickets() {
    $this->drupalLogin($this->adminUser);
    $this->drupalGet($this->order->toUrl());
    $edit_link = $this->getSession()->getPage()->findLink('Edit');
    $edit_link = $this->getSession()->getPage()->findLink('Tickets');
    $edit_link->click();
    $delete_link = $this->getSession()->getPage()->findLink('Delete');
    $delete_link->click();
    $this->submitForm([], 'Delete');

    $this->assertSession()->pageTextContains('The commerce ticket Ticket has been deleted.');
    $tickets = CommerceTicket::loadMultiple();
    $this->assertEquals(0, count($tickets));
    $this->drupalGet($this->order->toUrl());
    $edit_link = $this->getSession()->getPage()->findLink('Tickets');
    $edit_link->click();
    $this->assertSession()->pageTextContains('There are no commerce ticket entities yet.');
  }

}
+1 −3
Original line number Diff line number Diff line
@@ -3,8 +3,6 @@
namespace Drupal\Tests\commerce_ticketing\Kernel;

use Drupal\commerce_order\Entity\OrderInterface;
use Drupal\commerce_product\Entity\Product;
use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\commerce_ticketing\Entity\CommerceTicket;
use Drupal\Core\Session\AccountInterface;
use Drupal\user\Entity\Role;
@@ -86,7 +84,7 @@ class TicketCreationTest extends TicketKernelTestBase {
    Role::load(AccountInterface::ANONYMOUS_ROLE)
      ->grantPermission('view commerce_product')
      ->save();
    $order = $this->createOrder([], null, $mail);
    $order = $this->createOrder([], NULL, $mail);

    $variation = $this->createProductVariation();
    $variation->save();
+30 −0
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests\commerce_ticketing\Kernel;

use Drupal\commerce_ticketing\Entity\CommerceTicket;

/**
 * Tests the ticket delete.
 *
 * @group commerce_ticketing
 */
class TicketDeletionTest extends TicketKernelTestBase {

  /**
   * Tests ticket delete when order is completed.
   */
  public function testTicketDeleteOrderCompleted() {
    $this->assertCount(0, $this->tickets);
    $this->addPayment();
    $this->assertEquals('completed', $this->order->getState()->getId());
    $tickets = CommerceTicket::loadMultiple();
    $this->assertCount(1, $tickets);
    $ticket = reset($tickets);
    $ticket->delete();
    \Drupal::entityTypeManager()->getStorage('commerce_ticket')->resetCache();
    $tickets = CommerceTicket::loadMultiple();
    $this->assertCount(0, $tickets);
  }

}
+2 −3
Original line number Diff line number Diff line
@@ -154,7 +154,6 @@ abstract class TicketKernelTestBase extends CartKernelTestBase {
   * @param \Drupal\commerce_order\Entity\OrderInterface|null $order
   *   The order to add payment for, empty to use the default.
   *
   * @return void
   * @throws \Drupal\Core\Entity\EntityStorageException
   */
  protected function addPayment(OrderInterface $order = NULL) {
@@ -187,14 +186,14 @@ abstract class TicketKernelTestBase extends CartKernelTestBase {
   *
   * @param array $values
   *   Array of default values.
   * @param \Drupal\Core\Session\AccountInterface|NULL $customer
   * @param \Drupal\Core\Session\AccountInterface|null $customer
   *   Customer to assign the order.
   * @param string $email
   *   E-mail to use instead of customer's.
   *
   * @return \Drupal\commerce_order\Entity\OrderInterface
   */
  protected function createOrder(array $values = [], AccountInterface $customer = null, string $email = '') {
  protected function createOrder(array $values = [], AccountInterface $customer = NULL, string $email = '') {
    return Order::create($values + [
      'type' => 'default',
      'state' => 'draft',
+1 −1

File changed.

Contains only whitespace changes.

Loading