Page 1 of 1

How to work with item types after 17 Dec 2018 commit

Posted: 07 Jul 2019, 20:00
by FedericoCánovas
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.

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

Posted: 08 Jul 2019, 09:50
by aimeos
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() );

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

Posted: 11 Jul 2019, 16:22
by FedericoCánovas
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

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

Posted: 12 Jul 2019, 09:29
by aimeos
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.