When I click the conditions link of the COD payment method I get:

admin/store/settings/payment/manage/uc_payment_method_cod" could not be found.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

TR’s picture

Status: Active » Postponed (maintainer needs more info)

Works for me. The page that link points to is provided by the Rules UI module, so make sure you have Rules UI enabled. If you do, please check your other 'conditions' links on /admin/store/settings/payment and /admin/store/settings/quotes to see if any of the other links work. What version of Rules do you have installed?

ñull’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)

I tried to reproduce what I saw yesterday, but I can't. May be it was a cache issue and after clearing it now works.

tinker’s picture

Status: Closed (cannot reproduce) » Active

Noticed the same issue and can reproduce. This only occurs if uc_payment_pack is enabled after uc_payment using admin modules page. To reproduce:
- disable and uninstall uc_payment_pack
- disable and uninstall uc_payment (must happen to remove existing rules)
- enable uc_payment
- enable uc_payment_pack (do not use drush for this command)

Problem is that Rules component 'COD conditions' is not created until rules cache is rebuilt. This stems from uc_payment.rules_defaults.inc

  $methods = _uc_payment_method_list();
  foreach ($methods as $id => $method) {
    $set = rules_and(array(
      'order' => array('type' => 'uc_order', 'label' => t('Order')),
    ));
    $set->label = t('@method conditions', array('@method' => $method['name']));

    $configs['uc_payment_method_' . $method['id']] = $set;
  }

This can be fixed by clearing Rules cache in hook_install.

/**
 * Implements hook_install().
 */
function uc_payment_pack_install() {
  // Flush Rules cache to create uc_payment_pack Rules components.
  // See uc_payment.rules_defaults.inc
  rules_clear_cache();
}

Don't know how good this solution is as it seems heavy handed. If it's acceptable I can roll a patch.
Also happens for uc_cybersource and potentially all payment methods that do not use uc_credit.

tinker’s picture

Title: Missing COD conditions » COD payment conditions - page not found

Dupe issue #1571084: Cannot add conditions to "check" as it says "page not found" for 'Check' method closed for same reason.

TR’s picture

Nice catch! That's a reasonable solution, as it only has to be done at install time. I'm almost positive the same fix will be needed with all the shipping methods as well.

I'll try to reproduce this. A patch would be greatly appreciated.

longwave’s picture

Could this be done in hook_modules_enabled in uc_payment/uc_quote if this affect all methods? Enabling a module is a rare operation so I think it should be okay to do every time.

tinker’s picture

@longwave thx for the idea. Think that is a better solution.

Looking at rules cache there does not seem to be a way to rebuild one component at a time so rules_clear_cache() appears to be a clean as it will get.

Don't have time to test right now but does the following seem acceptable?

function uc_payment_modules_enabled($modules) {
  // Ensure rules components exist for new payment methods. 
  // See uc_payment.rules_defaults.inc
  $clear_cache = FALSE;
  // Check if new modules implement ubercart payment methods.
  foreach ($modules as $module) {
    $function = $module . '_uc_payment_method';
    if (function_exists($function)) {
      $clear_cache = TRUE;
      break;
    }
  }
  if ($clear_cache) {
    rules_clear_cache();
  }
}

Patch will follow after testing.

tinker’s picture

Title: COD payment conditions - page not found » Payment conditions - page not found
Version: 7.x-3.8 » 7.x-3.x-dev
Status: Active » Needs review
FileSize
1.25 KB

Testing revealed that rules_clear_cache() was not an effective solution. Switched to entity_defaults_rebuild(array('rules_config')). Patch uses uc_payment_modules_enabled() to fix issue for all payment methods and is for 7.x-3.x-dev.

tinker’s picture

Forgot to mention that reinstalling uc_payment module revealed another bug #2533192: Duplicate key payment_received when reinstalling uc_payment. Please make sure to apply that patch or delete 'payment_received' row from 'uc_order_statuses' table before reinstalling uc_payment module as the database error will stop the uc_payment_default_rules_configuration() from being executed.

TR’s picture

Component: Payment » Rules