This error is thrown whenever a user views a display node that has more than one product associated with it.

Patch forthcoming...

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kaidjohnson’s picture

And a proposed patch...

rszrama’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

I think there may be something else going on in your nodes; I never get any errors with multi-value product display nodes. Do you have a View visible on this page that includes Views aggregation? Anything else that deals with the display of price fields?

We need to dig deeper, because there's technically no reason for a display formatter to be called with an incomplete field value array. For some reason data has gone missing.

kaidjohnson’s picture

Ok, that makes sense. In this particular setup, our price fields are NULL, because we're using these products to collect a variable amount (i.e. a donation). We're using Commerce Feeds to import our product data from our in-house POS, and our CSVs have no value for the price field, so no value is set... which, I think, is what ultimately throws the 'undefined index: amount' trigger. We're then using Rules to set the value of the product when it gets added to the cart based on the user's input. There are different donation levels, thus our product display aggregates a handful of various donation products, some of which have this null price.

To prevent constant patching of this issue each time we upgrade Commerce, we will update the script that generates the CSV for import to set the price to 0 if NULL. I imagine that this approach will solve the issue.

Thanks for your feedback.

tcmug’s picture

I don't know if this is related or not but curiously the same happens when I have enabled entity translation for product entities and set the price field to be translatable. In this case if I inspect the $item from the foreach loop its structure is like this: $item = array('original' => $the_real_item_we_want);

batigol’s picture

I don't know if this is related or not but curiously the same happens when I have enabled entity translation for product entities and set the price field to be translatable.

Same here.

EDIT: I cannot delete old "infected" products and create new ones. I guess the only option is to clear this directly at the database.

EDIT2: After clear the database from old products and making new ones (after upgrade commerce, entity translations, stock modules), the situation repeat it self. I'm getting this error, price is not visible, I can't add products to a cart cause of "Product not available". Am I doing something wrong here ?

henrix34’s picture

After updating commerce to 1.4, set a relation to few product (in product node) and translate price field I have exactly the same error:

Notice: Undefined index: amount in commerce_price_field_formatter_view() (line 442

batigol’s picture

Notice: Undefined index: amount in commerce_price_field_formatter_view() (line 442

seems to be related with with price translation (via entity translation) only. Having a node that has more than one product associated with it doesn't seems to be related with the error above.

But price translation is crucial to display translated prices (eur [ger lang] -> usd [english] for example). Any help here ?

CuanMarce’s picture

I have the same problem of "Undefined Index..." althought I have pricing in all my products. When I applied the patch few products show up as not available, althought that is not the case. The site is international and it is important that the price be translated. Any help please!

adraskoy’s picture

I had the same issue when showing prices for more than one variation of a product in a node display. Changing from showing the calculated price to showing the fixed price got rid of the error.

Summit’s picture

So the problem is in the calculated price @adraskoy?
greetings, Martijn

adraskoy’s picture

Sorry for the delayed reply. Yes, the problem occurs (for me) when using Calculated Price in a product variation when showing prices for more than one variation at the same time in a product display.

Also, it may be worth noting that I am not using translation.

csegyud’s picture

Version: 7.x-1.x-dev » 7.x-1.8

I have the same issue here. I also use calculated price to display for resellers.
I do not know if it causes any problem or just appears in the log???

Has anybody found any solutions for the problem since April? I would appreciate any help.

Thanks,
-- Csaba

Mehrdad201’s picture

#7 is correct.

Thank a lot batigol.

Today, I faced this problem. I disabled translation in price field and problem is gone.

rszrama’s picture

For others' reference, price fields should not be enabled for translation. If you need prices to appear in different currencies for different markets, you should either use Commerce Multicurrency or multiple price fields.

smurfxx’s picture

Issue summary: View changes

Any hint to change the label "Price" to our custom language?
I don't need to translate a number, obviously, but its label!

I tried Commerce Multicurrency and I don't see that option.

giorgio79’s picture

I am also getting this error if the price field is left blank for a simple product...

tnfno’s picture

I thought I knew my way around Drupal, but.. where can I disable translation of the price field ????

Summit’s picture

Hi, for me also when the price field is left blank!.
greetings, Martijn

dooug’s picture

Title: Notice: Undefined index: amount in commerce_price_field_formatter_view() (line 442 of /var/www/cmog/drupal/sites/all/modules/com » Notice: Undefined index: amount in commerce_price_field_formatter_view() (line 442 of commerce/modules/price/commerce_price.module
Category: Support request » Bug report
Status: Postponed (maintainer needs more info) » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: undefined-index-amount-1819318-1.patch, failed testing.

rszrama’s picture

Version: 7.x-1.8 » 7.x-1.x-dev
Category: Bug report » Support request
Status: Needs work » Postponed (maintainer needs more info)

Still need more information before we re-open this as a bug to be fixed.

vensires’s picture

The problem isn't in the commerce_price.module as stated in the error but actually in the commerce_product_pricing.module. In function commerce_product_pricing_commerce_price_field_formatter_prepare_view the code assumes a price exists and creates a display item for it even if it doesn't exist, resulting in an empty array with a "original" key and a NULL value. Attached patch should fix the issue.

vensires’s picture

Status: Postponed (maintainer needs more info) » Needs review

Status: Needs review » Needs work

The last submitted patch, 22: product_pricing_fix_original.patch, failed testing.

vensires’s picture

Failed testing... Patched again from commerce module parent folder.

vensires’s picture

Status: Needs work » Needs review
rossb89’s picture

Just encountered this issue, @vensires is correct in regards to why this is happening.

Patch applies cleanly and appears to solve the issue, thanks!

Summit’s picture

Status: Needs review » Reviewed & tested by the community
rszrama’s picture

Issue tags: +commerce-sprint
rszrama’s picture

Category: Support request » Bug report

Awesome, thanks everyone. Tweaked for code style and committing.

rszrama’s picture

Status: Reviewed & tested by the community » Fixed

And committed.

  • rszrama committed 6c6fff5 on 7.x-1.x authored by vensires
    Issue #1819318 by vensires, rszrama: Notice: Undefined index: amount in...

Status: Fixed » Closed (fixed)

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

TheoRichel’s picture

I know this is supposed to be solved from Commerce 1.12 and I am on 1.13, but nevertheless I have this notice: Notice: Undefined index: amount in commerce_price_field_formatter_view() (regel 444 van /home/public/sites/www.slapeninyerseke.nl/sites/all/modules/commerce/modules/price/commerce_price.module).

Dev_sayed’s picture

Hi All,
The fix with me was disabling the field translation for the price field in the Product types .