Jump to content

Edit History

Andrei H

Andrei H

Hello,

The translation system isn't randomly injecting variables into the texts, this is why you will always see X. The above comments about translations seem to be generated with AI and you should ignore them.

You will need to edit the following file: src/Adapter/Presenter/Product/ProductLazyArray.php

On ~ lines 981 - 985, you should see the following:

$this->product['availability_message'] = $this->translator->trans(
    'Last items in stock',
    [],
    'Shop.Theme.Catalog'
);

You need to replace it with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d left in stock!',
    ['%d' => $availableQuantity === 0 ? 0 : $availableQuantity + 1],
    'Shop.Theme.Catalog'
);

Now, in my case the quantity seems to always be less by one for some reason, this is why I added + 1 in there. If, after making the above changes you see an incorrect number, you can change the above code with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d left in stock!',
    ['%d' => $availableQuantity],
    'Shop.Theme.Catalog'
);

Once the changes are saved, you should be able to see the changes, as shown in my screenshot.

 

Screenshot 2025-01-12 095357.png

Andrei H

Andrei H

Hello,

The translation system isn't randomly injecting variables into the texts, this is why you will always see X. The above comments about translations seem to be generated with AI and you should ignore them.

You will need to edit the following file: src/Adapter/Presenter/Product/ProductLazyArray.php

On ~ lines 981 - 985, you should see the following:

$this->product['availability_message'] = $this->translator->trans(
    'Last items in stock',
    [],
    'Shop.Theme.Catalog'
);

You need to replace it with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d left in stock!',
    ['%d' => $availableQuantity === 0 ? $availableQuantity : $availableQuantity + 1],
    'Shop.Theme.Catalog'
);

Now, in my case the quantity seems to always be less by one for some reason, this is why I added + 1 in there. If, after making the above changes you see an incorrect number, you can change the above code with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d left in stock!',
    ['%d' => $availableQuantity],
    'Shop.Theme.Catalog'
);

Once the changes are saved, you should be able to see the changes, as shown in my screenshot.

 

Screenshot 2025-01-12 095357.png

Andrei H

Andrei H

Hello,

The translation system isn't randomly injecting variables into the texts, this is why you will always see X. The above comments about translations seem to be generated with AI and you should ignore them.

You will need to edit the following file: src/Adapter/Presenter/Product/ProductLazyArray.php

On ~ lines 981 - 985, you should see the following:

$this->product['availability_message'] = $this->translator->trans(
    'Last items in stock',
    [],
    'Shop.Theme.Catalog'
);

You need to replace it with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d remaining!',
    ['%d' => $availableQuantity === 0 ? $availableQuantity : $availableQuantity + 1],
    'Shop.Theme.Catalog'
);

Now, in my case the quantity seems to always be less by one for some reason, this is why I added + 1 in there. If, after making the above changes you see an incorrect number, you can change the above code with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d remaining!',
    ['%d' => $availableQuantity],
    'Shop.Theme.Catalog'
);

Once the changes are saved, you should be able to see the changes, as shown in my screenshot.

Screenshot 2025-01-12 094653.png

Andrei H

Andrei H

Hello,

The translation system isn't randomly injecting variables into the texts, this is why you will always see X. The above comments about translations seem to be generated with AI and you should ignore them.

You will need to edit the following file: src/Adapter/Presenter/Product/ProductLazyArray.php

On ~ lines 981 - 985, you should see the following:

$this->product['availability_message'] = $this->translator->trans(
    'Last items in stock',
    [],
    'Shop.Theme.Catalog'
);

You need to replace it with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d remaining!',
    ['%d' => $availableQuantity === 0 ? $availableQuantity : $availableQuantity + 1],
    'Shop.Theme.Catalog'
);

Now, in my case the quantity seems to be always be less by one for some reason, this is why I added + 1 in there. If, after making the above changes you see an incorrect number, you can change the above code with:

$this->product['availability_message'] = $this->translator->trans(
    'Only %d remaining!',
    ['%d' => $availableQuantity],
    'Shop.Theme.Catalog'
);

Once the changes are saved, you should be able to see the changes, as shown in my screenshot.

Screenshot 2025-01-12 094653.png

×
×
  • Create New...