How to work with item types after 17 Dec 2018 commit

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
FedericoCánovas
Posts: 7
Joined: 16 Jul 2018, 17:50
Contact:

How to work with item types after 17 Dec 2018 commit

Post by FedericoCánovas » 07 Jul 2019, 20:00

Hi there,

I have a project with an older version of Aimeos in which I was using getTypeId() and getTypeName() item methods.

I was trying to use the same methods on a new project with an updated version of Aimeos but I noticed that these methods has been removed in this commit

What is the proper way to get the same results with the current version?

Here is an example of a piece of code where I'm using these methods:

Code: Select all

            $options  = [];
            $variantAttributes = $variantProduct->getRefItems('attribute', null, 'variant');
            foreach ($variantAttributes as $variantAttribute) {
                if (empty($options[$variantAttribute->getTypeId()])) {
                    $options[$variantAttribute->getTypeId()] = [
                        'attribute_id'   => $variantAttribute->getTypeId(),
                        'attribute_code' => $variantAttribute->getType(),
                        'values'         => [],
                        'label'          => $variantAttribute->getTypeName(),
                        'code'           => $variantAttribute->getType(),
                        'position'       => 0
                    ];
                }
                $options[$variantAttribute->getTypeId()]['values'][] = [
                    'value_index' => $variantAttribute->getId(),
                    'label'       => $variantAttribute->getLabel()
                ];
            }
Thanks.

User avatar
aimeos
Administrator
Posts: 3207
Joined: 01 Jan 1970, 00:00

Re: How to work with item types after 17 Dec 2018 commit

Post by aimeos » 08 Jul 2019, 09:50

Instead of "$variantAttribute->getTypeId()" you should use "$variantAttribute->getType()" now. The getTypeName() method has been removed and you should translate the attribute type code with:

Code: Select all

$this->translate( 'client/code', $variantAttribute->getType() );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

FedericoCánovas
Posts: 7
Joined: 16 Jul 2018, 17:50
Contact:

Re: How to work with item types after 17 Dec 2018 commit

Post by FedericoCánovas » 11 Jul 2019, 16:22

Ok. I see that type id has been substituted by the type code in relationships.

What's happens if you change the type code of an attribute type that has already been related to attributes, these attributes to products and so?

As I see, the related attribute remains with the old code

User avatar
aimeos
Administrator
Posts: 3207
Joined: 01 Jan 1970, 00:00

Re: How to work with item types after 17 Dec 2018 commit

Post by aimeos » 12 Jul 2019, 09:29

Yes, the codes stay the same if you change the values in the type table. The behavior is now consistent to document oriented systems like Solr or ElasticSearch.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply