product-jsonld.tpl: "Attempt to read property "name" on null" on every product without a brand (PrestaShop 9)

Open Beginner friendly
#246 2 comments 0 reactions 0 assignees View on GitHub

@boo-code is already working on this.

Since Nov 2, 2026.

  • #252 by @boo-code — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
php
Domain
frontend

Research direction

The warning comes from the brand block in templates/_partials/microdata/product-jsonld.tpl, around lines 54-57 and 71-74, where $product_manufacturer is read as an object while the controller can set it to null. Compare with the guard already used in catalog/_partials/product-details.tpl. Done when a product without a brand renders no PHP warning in debug mode and the application/ld+json block stays valid JSON, with the brand falling back to the shop name.

Written by the indexing model from the issue text.

Description

Prerequisites
Describe the bug and add attachments

Since PrestaShop 9.0, ProductController::assignManufacturer() assigns product_manufacturer as null when the product has no brand, and as a presented array otherwise:
https://github.com/PrestaShop/PrestaShop/blob/9.2.0/controllers/front/ProductController.php#L883-L900

(8.2.x always assigned a Manufacturer object.)

templates/_partials/microdata/product-jsonld.tpl still reads it as an object:
https://github.com/PrestaShop/classic-theme/blob/3.1.2/templates/_partials/microdata/product-jsonld.tpl#L54-L57

{if $product_manufacturer->name OR $shop.name},
...
"name": "{if $product_manufacturer->name}{$product_manufacturer->name|escape:'html':'UTF-8'}{else}{$shop.name}{/if}"

On PHP 8 this raises Warning: Attempt to read property "name" on null twice on every product page without a brand. In debug mode the warnings are printed inside the JSON-LD <script>, which is then no longer valid JSON. The same lines are on develop.

catalog/_partials/product-details.tpl was already adapted ({if !empty($product_manufacturer.id)}); Hummingbird guards it with isset($product_manufacturer).

Steps to reproduce
  1. PrestaShop 9.0.1 (official Docker image) with demo data and the Classic theme; debug mode on.
  2. Open the page of a product without a brand, e.g. "Pack Mug + Framed poster" (id 15).
  3. Look at the page source, in the application/ld+json block.
Expected behavior

No warning; the brand falls back to the shop name, as on 8.2.x.

Actual Result
"brand": {
  "@type": "Brand",
  "name": "
Warning:  Attempt to read property "name" on null in .../product-jsonld.tpl.php on line 74
PrestaShop"
}

plus a first warning for line 71 (the {if} on line 54 of the template).

Suggested fix: use array access with !empty(), which works for null and for the presented array:

{if !empty($product_manufacturer.name) OR $shop.name},
  "brand": {
    "@type": "Brand",
    "name": "{if !empty($product_manufacturer.name)}{$product_manufacturer.name|escape:'html':'UTF-8'}{else}{$shop.name}{/if}"
  }
{/if}
PrestaShop version where the bug happens

9.0.1 (reproduced); 9.2.0 has the same controller code

Theme version where the bug happens

Classic 3.0.2 (reproduced); same template in 3.1.2 and on develop

PHP version(s) where the bug happened

8.4


Reported by PrestaChamps.

Dominant language
Smarty
Stars
50
Forks
99
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PrestaShop/classic-theme

All issues in PrestaShop/classic-theme

Similar issues

More Web Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.