In the module uc_discounts, I am unable to add a discount.

When I try to add a discount at admin/store/uc_discounts/add my dev site just hangs. I have Backdrop v1.22.2 and the latest release of this module (1.x-2.0.1).

Update: I was using Chrome, but when using Firefox I get a little more information and this is logged in the site reports:

LOCATION    xxx/admin/store/uc_discounts/add
REFERRER    xxx/admin/store/uc_discounts
MESSAGE    Notice: Array to string conversion in date_limit_format() (line 1171 of xxxxx/web/core/includes/date.inc).
SEVERITY    notice

and

LOCATION    xxx/admin/store/uc_discounts/add
REFERRER    xxx/admin/store/uc_discounts/list
MESSAGE    Warning: strtr() expects parameter 1 to be string, array given in strtr() (line 1186 of xxxxx/web/core/includes/date.inc).

Hopefully that gives a clue as to where I might look?

Most helpful answers

Glad to hear you found a solution. Just for completeness, the issue you found in uc_discounts module is now fixed in the latest release. Thanks for flagging it!

Comments

bugfolder's picture

There's a new bugfix release (which, among other things, fixed the bug of the wrong release number on the previous bugfix release). Does version 1.x-2.0.2 still exhibit this problem?

I'm afraid so, yes.

I uninstalled the module, cleared cache, replaced the module files, reinstalled and the exact same problem exists.

The error suggests something related to date but I'm afraid I'm not clever enough to find out anything further.

I assume this is repeatable and I'm not the only person seeing this?

My need for a discount is very simple - to apply a percentage discount on an item if the customer's country (defined in their user account addressfield) is one of a selected list (OECD developing countries).

Looking at the functionality of the Ubercart Discount module, I was not at all clear that I could use it for this purpose. So I reviewed the D7 modules and found Ubercart Simple Discount which enables discounts to be applied by Rules.

I followed instructions to convert a D7 module to BackdropCMS and - with changes required only in the .info file - this module miraculously works exactly as I wanted.

No problems so far, so perhaps this is one of those examples where a module can easily be ported to BackdropCMS.

If anyone knows of any problems I might encounter following this, do please let me know.

In the meantime, I uninstalled the module uc_discounts as I couldn't get it to work at all in my dev site. I hope that module is investigated and fixed by someone smarter than me (I'm not an experienced developer, just a site builder).

Hello There,

Doesn't look like anyone dug into the nature of this error, so let me help out.

I have been working with PHP since 2000, and with Drupal since 2010, though I would not describe myself as any kind of expert.

The error you received is a PARAMETER TYPE MISMATCH error:
 

Warning: strtr() expects parameter 1 to be string, array given in strtr() (line 1186 of xxxxx/web/core/includes/date.inc).

 

1)  The strtr() function expects that the first parameter supplied be a STRING, which is a simple data type often likened to a 1-dimensional array of CHARacters.  You can liken this to a ROW in a spreadsheet.

2)  The parameter supplied was actually an ARRAY, which is a complex data type that you can liken to the entire spreadsheet

To solve your issue, you need to reduce the complexity of the passed parameter by exploring the OBJECT being passed (which is an ARRAY)  using either injected code or debugging tools to figure out what ROW in the ARRAY is the string of CHAR that will meet the expectations of the parameter declaration for that function.

Parameter declarations exist to prevent programs from acting crazy.  They are actually an effort to help make programs safer.  Unfortunately, when you change the underlying architecture of a technology (Drupal 6 -> Drupal 7 -> Drupal 8 -> Drupal 9 anyone?) the code, correct though it was 10 years ago even, may not work today.  Such is the hubris of those who steer our tools.

As for the exact nature of the error, here's an analogy:

Let's propose a data structure like a mini spreadsheet that looks like this:

aaa
bbb
ccc

The strtr() function is expecting to receive one of the above 3-letter rows, not the entire 9-letter block, which is what it's getting.

Now, I notice that the error being thrown in question is actually NOT in uc_discount.  It is in DRUPAL CORE and it is a consequence of code somewhere (maybe in uc_discount?) submitting an improperly formatted function call to date.inc.

This makes me feel like your particular error may have something to do with your using a different PHP version than was originally used to develop Drupal Core or Ubercart Discounts. 

There were a MAJOR changes between PHP 5, PHP 6 and PHP 7, for example, over which the Ubercart product was originally developed and upgraded.  This kind of "rug pulling" is not exclusive to Drupal leadership, though they are an egregious example of it.

So...let's have a look see at the code in question, shall we?

line 1186 of xxxxx/web/core/includes/date.inc

First of all, it looks to me like the error message is totally nuts. 

A) date.inc 196 lines long
B) uc_simple_discount.module is only 533 lines long

This leads me to believe that the error actually emanates from a "function call stack" where function -> function -> function and the error message that "bubbled up" got garbled.

OK, let's look for instances of strtr() in the code of those two modules:

A) There are NO instances of strtr() in date.inc
B) There are NO instances of strtr() in uc_simple_discout

Your error message contains a reference to /core/includes/xxxxxx

This signals to me that you are trying to do "something D7" in a D8 or D9 environment as the architecture of D7 does not have a /core subdirectory as far as I can remember.

g.
----

 

bugfolder's picture

This signals to me that you are trying to do "something D7" in a D8 or D9 environment as the architecture of D7 does not have a /core subdirectory as far as I can remember.

Actually, the problem was that a property in the date_popup element that changed in Backdrop hadn't been updated in the module. It's been fixed in the latest release.

Thanks for digging into this @Graham Leach! Yes, there are a number of differences between Backdrop and Drupal 7 (including the '/core' subdirectory for most core files) since Backdrop was forked in between Drupal 7 and Drupal 8. But for the most part it's extremely compatible in terms of the API, etc. The Change Records page is useful to skim in this regard.

As far as this issue, it sounds like @bugfolder has tracked it down:

Hello @laryn,

Thanks!

g.
----

 

bugfolder's picture

Glad to hear you found a solution. Just for completeness, the issue you found in uc_discounts module is now fixed in the latest release. Thanks for flagging it!