I made a small module that adds a checkbox to accept the terms and conditions in the purchase tunnel.

Why when I uninstall a module that creates a "Checkout Pane" it removes all "Checkout Flows" ?

Every module that adds "Checkout Pane" has the same problem. This problem is very annoying.

https://www.drupal.org/sandbox/zenimagine/3082137

Comments

zenimagine created an issue. See original summary.

jsacksick’s picture

Project: Commerce Shipping » Commerce Core
Component: Code » Documentation

Probably because of this code:

  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();
    // Merge-in the pane dependencies.
    foreach ($this->getPanes() as $pane) {
      foreach ($pane->calculateDependencies() as $dependency_type => $list) {
        foreach ($list as $name) {
          $dependencies[$dependency_type][] = $name;
        }
      }
    }

    return $dependencies;
  }

present in CheckoutFlowWithPanesBase::calculateDependencies().

That adds dependencies on all the checkout panes.

bojanz’s picture

Category: Support request » Bug report

This feels like a bug.

zenimagine’s picture

Do you have a temporary solution, so that I can uninstall my module without breaking my Drupal Commerce configuration ?

jsacksick’s picture

Try commenting the code in calculateDependencies()? (that is CheckoutFlowWithPanesBase::calculateDependencies() and see if this makes a difference.

zenimagine’s picture

@jsacksick I use Composer to manage modules and dependencies. Do you have a patch to do this? Thank you

zenimagine’s picture

@bojanz @jsacksick Hi, who can patch please? I have been stuck for months with this issue. I can test a fix.

jsacksick’s picture

Status: Active » Needs review
StatusFileSize
new1.8 KB

I managed to write a failing test, but I've failed to fix the issue itself for now.

I started adding the following to CheckoutFlow:

  /**
   * {@inheritdoc}
   */
  public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);

    // For checkout flows with panes, ensure panes provided by the module being
    // uninstalled are removed from the configuration.
    if ($this->getPlugin() instanceof CheckoutFlowWithPanesInterface) {
      $uninstalled_modules = $dependencies['module'];
      $panes_to_remove = [];
      /** @var \Drupal\commerce_checkout\CheckoutPaneManager $pane_manager */
      $pane_manager = \Drupal::service('plugin.manager.commerce_checkout_pane');

      foreach ($pane_manager->getDefinitions() as $definition) {
        if (in_array($definition['provider'], $uninstalled_modules)) {
          $panes_to_remove[$definition['id']] = $definition['id'];
        }
      }

      if ($panes_to_remove) {
        $this->configuration['panes'] = array_diff_key($this->configuration['panes'], $panes_to_remove);
        $changed = TRUE;
      }
    }

    return $changed;
  }

But that doesn't seem to do the trick as when calculateDepencies() is then called, the dependency is re-added.

zenimagine’s picture

@jsacksick Thanks for your answer, I started to despair. I have been totally stuck with this problem for months, cannot uninstall the "Commerce Agree Terms" module, it erases all Checkout flows.

Should I test your patch or wait for the next one ?

jsacksick’s picture

@zenimagine: No, not yet, the test i wrote demonstrates the problem, but haven't managed to fix it yet.

Status: Needs review » Needs work

The last submitted patch, 8: 3200217-8-tests-only.patch, failed testing. View results

jsacksick’s picture

Status: Needs work » Needs review
StatusFileSize
new6.05 KB

The attached patch should do the trick, hopefully!

jsacksick’s picture

StatusFileSize
new6.05 KB
zenimagine’s picture

@jsacksick Ok thank you, I will test the last path tonight.

zenimagine’s picture

@jsacksick I just tested the patch, when I uninstall my module, all checkout flows are deleted except "default". Custom checkout flows should not be deleted.

jsacksick’s picture

StatusFileSize
new6.12 KB

I didn't upload the right patch in #13, but the changes done since aren't altering the logic. I wrote a functional test proving the logic works, and just to be sure, I just retested this myself manually.

The test configures a pane from a module that is then uninstalled, the test confirms the checkout flow still exists after uninstalling the module, and the configuration is correctly updated (i.e the pane that was provided by the module is removed from the checkout flow configuration).

zenimagine’s picture

@jsacksick I am not familiar with programming. I tested the last patch and it is identical to my previous comment. If I uninstall my custom module, all checkout Flows is deleted except the Default checkout Flows.

jsacksick’s picture

hm... I'm really not sure what to do then, the test I wrote is testing exactly that, and I manually tested this as well, and the checkout flow remained.

Are the checkout flows provided by the module you're uninstalling as well?

zenimagine’s picture

@jsacksick Have you created other Cash Flow? My module simply add a checkbox in the purchase funnel to accept the terms and conditions.

I have 4 cash flows and only the default flow is not erased.

https://git.drupalcode.org/sandbox/zenimagine-3082137

jsacksick’s picture

Yes, I tested with other checkout flows, tried it again just now.

I created a custom checkout flow, saved it with the custom checkout pane, then uninstalled the module providing the checkout pane, and the checkout flow remained.

zenimagine’s picture

@jsacksick I do not understand why on my site it is erasing Custom Checkout Feeds. Can you test with my module ?

  • jsacksick committed 536f968 on 8.x-2.x
    Issue #3200217 by zenimagine, jsacksick: Ensure uninstalling a module...
jsacksick’s picture

Title: Why when I uninstall a module that creates a "Checkout Pane" it removes all "Checkout Flows" ? » Ensure uninstalling a module providing a checkout pane doesn't remove all checkout flows.
Status: Needs review » Fixed

I went ahead and committed a fix since I was able to reproduce the bug manually and wrote a failing test that no longer fails with the fix.

Status: Fixed » Closed (fixed)

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