Problem/Motivation

Undefined index: commerce_file_target_id error when viewing the Licensed files view on both the order completion page, or on the files tab in the users account page.

Steps to reproduce

Drupal 8.9.13
Commerce 2.24
Commerce License 2.0-alpha20
Commerce File 2.0-beta1
Commerce Braintree 1.3

Tested on a new install of Drupal and Commerce

  1. Create a Product type and a Product variation type
  2. On the product variation check the boxes to "Provide a file for download" and "Provide a license"
  3. Under License settings, check "File" under Available licenses
  4. Under Order Item type select "Default"
  5. Create a new Product and upload a file to the File field
  6. Set License expiration to "Unlimited"

In Admin > Commerce > Configuration > File under Download limits the "Limit the number of times a user can download a licensed file" checkbox is NOT checked

Go through the normal add to cart, checkout, and payment process and the order completes but on the checkout completion page, with the Licensed files view at the bottom of the page, the Undefined index: commerce_file_target_id error appears. The error is thrown once for each file in the table, so if there are 2 files, the error appears twice.

The same error appears on the Files tab of the user account page where the Licensed files view is displayed.

However, in the Licensed files view admin page in Views, you can enter the user id as a parameter to display the view and the table is displayed with no errors. The downloads field is blank. I went back and set the download limit to 10 but the field is still empty.

The error only appears on the first page load, or after a cache clear. If you reload the page the error disappears.

Proposed resolution

For troubleshooting purposes I removed the Download limit field from the view and that resolved the error.

That's all I got. I'm not a developer so there's not much more I can do with this. The full error message is below.

Notice: Undefined index: commerce_file_target_id in Drupal\commerce_file\Plugin\views\field\DownloadLimit->render() (line 93 of modules\contrib\commerce_file\src\Plugin\views\field\DownloadLimit.php).
Drupal\commerce_file\Plugin\views\field\DownloadLimit->render(Object) (Line: 1155)
Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender(Object) (Line: 238)
template_preprocess_views_view_field(Array, 'views_view_field', Array) (Line: 287)
Drupal\Core\Theme\ThemeManager->render('views_view_field', Array) (Line: 431)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 1746)
Drupal\views\Plugin\views\field\FieldPluginBase->theme(Object) (Line: 771)
Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array) (Line: 710)
Drupal\views\Plugin\views\style\StylePluginBase->renderFields(Array) (Line: 577)
Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping(Array, Array, 1) (Line: 468)
Drupal\views\Plugin\views\style\StylePluginBase->render(Array) (Line: 2170)
Drupal\views\Plugin\views\display\DisplayPluginBase->render() (Line: 1533)
Drupal\views\ViewExecutable->render() (Line: 183)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay('page', Array) (Line: 77)
Drupal\views\Element\View::preRenderViewElement(Array)
call_user_func_array(Array, Array) (Line: 100)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. Support for this callback implementation is deprecated in 8.8.0 and will be removed in Drupal 9.0.0. See https://www.drupal.org/node/2966725', 'silenced_deprecation', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 781)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 372)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 200)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 226)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 227)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 156)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Comments

jmoruzi created an issue. See original summary.

jsacksick’s picture

@jmoruzi: Did you make any changes to the view? Or just use the default one that ships with the module?

During testing, I got those warnings when checking "Display all values in the same row" under "Multiple field settings" for the "Product variation: File(s) field.

When that option is checked, it makes it harder to determine which file to display download limits for.

jmoruzi’s picture

@jsacksick, Interesting that you mention Multiple field settings, my view does not show Multiple field settings for the Product variation: File(s) field. I did not change the view, except to troubleshoot the error.

jmoruzi’s picture

@jacksick: I just realized I had set the Allowed number of files on the product variation type to 1, which is why there was no Multiple field settings in the View. Now that I allowed more than 1 file to be uploaded the error is resolved. If I set the Allowed number of files back to 1, the error appears again.

With the Allowed number of files set to 1, or if no File download limit is set, the Downloads column in the view is empty. If the Allowed number of files is set to more than 1, and the File download limit is set to 10, then the Downloads column will show 0/10. But the downloads are not recorded. Even after the file is downloaded multiple times, the Download column still shows 0/10.

jsacksick’s picture

I just realized I had set the Allowed number of files on the product variation type to 1, which is why there was no Multiple field settings in the View. Now that I allowed more than 1 file to be uploaded the error is resolved. If I set the Allowed number of files back to 1, the error appears again.

I'm not sure we can easily account for that.

By the way, upgrading from dev is a bit of a problem, make sure to get the latest view from the code.

jmoruzi’s picture

@jsacksick, thanks for this. In my case it's not an issue to leave the Allowed number of files set higher than 1.

As for upgrading, I had the error after upgrading the Commerce File and Commerce License modules from dev, so I created a fresh install with the latest versions as described in the original issue above and still get the error. Setting the Allowed number of files to more then 1 on the product variation type is what resolved it.

Thanks again.

jsacksick’s picture

Category: Bug report » Support request
Status: Active » Fixed

Marking this as fixed then :).

Status: Fixed » Closed (fixed)

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

jsidigital’s picture

Actually I don't think this is fixed.

I have the same error and have not made any edits to the default format of the module.

If enabling the download limit, in any way this error shows.

I have tried all kinds of changes to the way I set up the configuration and all end up with the error.

Only way to avoid this is to not use download limit at all and remove the field from the view.

Hope someone can figure out what is going on. That is a nice feature that at the moment is not working for me. :(