Replace 'pav' function in script type attribute

Since I use a lot of script type attributes, which make use of the ‘pav’ function in Core 1.x, I have to convert all those scripts to get them ready for Core 2.x.
Basically, it works this way:

The old script section

{% set value = pav('attributeCode') %}
{% set valueUnit = findRecord('Unit', {'id': value.referenceValue }) %}

is now changed to

{% set product = entity | putAttributesToEntity %}
{% set value = product.attributeCodeValue %}
{% set valueUnit = findEntity('Unit', {'id': product.attributeCodeValueUnitId}) %}

In the end, I will create an AI prompt to get all the script type attributes converted and prepared for AtroCore 2.x.

So my question is: Are there any other changes I have to do, especially on some attribute types (including “advanced data type” attributes)?

Hello Mathias!
We will look into it!

Thank you for your feedback!
There are several types of attributes whose values can be stored in multiple fields and which you may need to review in your scripts, such as range int/range float, link.
For the first ones, the values can be obtained as follows:

{% set valueFrom = product.attributeCodeValueFrom %}{% set valueTo = product.attributeCodeValueTo %}

For link attributes:

{% set valueId = product.attributeCodeValueId %}{% set valueName = product.attributeCodeValueName %}

Also, pay attention to the attributesDefs object, which is located in the product or other entities for which attributes are available, describing all virtual fields associated with attributes. It can help you in the future when writing scripts.

1 Like