Fatal error when working with commerce price field

Created on 28 February 2019, over 6 years ago
Updated 5 September 2024, about 1 year ago

Hello,

I'm using this module to make a substraction between 2 commerce price field (which are number as I removed all currency).

When I go to my view, I got the following error :

InvalidArgumentException : Field price__number is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (ligne 586 of /core/lib/Drupal/Core/Entity/ContentEntityBase.php).

πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡«πŸ‡·France Alexandre360

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Eventually checking for commerce_price might be more solid?
    See https://git.drupalcode.org/project/commerce_reports/-/blob/8.x-1.x/comme... implementations.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica
  • πŸ‡¬πŸ‡§United Kingdom dahousecat

    I just encountered this issue and found that the SimpleMathField class is a bit flakey.

    getFieldValue says it returns mixed, but then the return value is used by functions like preg_match and strpos without first checking the type.

    I suspect really getFieldValue should define it's return type as string and probably log an error if it tries to return something that is not.

    However I've just gone for a very light refactor in this patch introducing these changes:

    - In removeSeparator if $data is not string just return $data.
    - Re-write the whole part where if it's a commerce price field.
    - Add an additional is_string check before calling preg_match.

    It looks like the patch from ivanpg94 would also fix this bug but I only came across this ticket once I'd already written my own patch, which does include some additional safety checks.

  • πŸ‡ΊπŸ‡ΈUnited States andileco

    Hi all, I don't use Commerce myself, and so testing this always proves to be a big hassle. This ticket is also marked for 8.x-1.x, which is two versions back. @dahousecat is your patch for 3.0.x? If so, please update the ticket. If someone can provide some steps to repeat and test the patch, I would appreciate it.

Production build 0.71.5 2024