Extend Physical properties

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)
Spam and unrelated posts will be removed immediately!
createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Extend Physical properties

Post by createanet » 01 Apr 2021, 09:31

I hope I may get some advice on extending the existing physical properties please.

I have copied to the HTML template and updated the respective config.

Code: Select all

ext/XXX/admin/jqadm/templates/product/item-physical-standard.php

1.

An example of my new input is described below, ive removed bloat so its clearer.

Code: Select all

<div
        <label><?= $enc->html( $this->translate( 'admin', 'Net Weight' ) ); ?></label>
        <input type="number" 
            name="<?= $enc->attr( $this->formparam( array( 'physical', 'package-net-weight' ) ) ); ?>"
            value="<?= $enc->attr( $this->get( 'physicalData/package-net-weight' ) ); ?>"
        >
    </div>
</div>
2.

I have created a global decorator and updated the respective config.

Code: Select all

admin/jqadm/product/physical/decorators/global/Physical
3.

I found in order to get this working it was necessary for me to override the following methods to make a change to the "toArray" method.

Code: Select all

toArray, fromArray, render, save, get

Code: Select all

    protected function toArray(Iface $item, bool $copy = false): array
    {
        $data = [];
        $types = ['package-length', 'package-height', 'package-width', 'package-weight', 'package-net-weight'];

        foreach ($item->getPropertyItems($types, false) as $item) {
            $data[$item->getType()] = $item->getValue();
        }

        return $data;
    }
This is working to an extent, but it feel wrong that in having to override so many methods to adapt the property types?

3.

I notice when saving, it was also creating/getting the same prop/value for characteristics.

It appears that characteristics and physical are the same, however there are types excluded from characteristics.

Therefore I found I am now need to decorate the characteristics properties to exclude physical properties

4.

Code: Select all

admin/jqadm/product/characteristic/property/decorators/global/Characteristic
Decorating the characteristics properties required me overriding the following methods.

Code: Select all

get,save,toArray,fromArray,getPropertyTypes,excludeItems,render
...in order to modify the "excludeItems" and add the new property type to ignore.

----

None of this feels right, I feels like I should be extending the class and not using a decorator. This would mean I would no longer need to copy methods from the original class that are called in the decorator that have no change.

Am I doing something wrong ? :)

Thanks in advance

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

Re: Extend Physical properties

Post by aimeos » 06 Apr 2021, 07:46

You don't do something wrong but it's not very elegant to extend the physical properties yet. You are right, the physical properties are just regular properties and would show up in the "Characteristics" tab too if they are not excluded. For future versions, we will check if there's an easier way to add new physical properties.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Extend Physical properties

Post by createanet » 06 Apr 2021, 14:34

Thank you for the feedback, Im glad that what I was doing is correct although it might not necessarily feel like it :)

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

Re: Extend Physical properties

Post by aimeos » 18 Apr 2021, 08:36

The next version will have configurable physical properties:
https://github.com/aimeos/ai-admin-jqad ... b1296e2d8a
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Extend Physical properties

Post by createanet » 10 Sep 2021, 10:45

Hello,

Im still on 2020, so not picked up the changes in the new version.

I've noticed an issue now when cloning the product in the admin, all physical properties are grouped under the characteristics now? Do i need to implement some changes on the copy() method?

Thanks,

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

Re: Extend Physical properties

Post by aimeos » 11 Sep 2021, 09:15

Tested with dev-master and 2020.10 but we can't reproduce that. Do you have the latest 2020.10 packages installed?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Extend Physical properties

Post by createanet » 13 Sep 2021, 07:57

Sorry, I got to the bottom of the issue Friday.

As I mentioned Im still on 2020.10 release, which wont pick this update up.

Your implementation was almost identical to mine, my issue however is that for me to make these changes I have used a global decorators. ie.

/admin/clients/product/physical/decorators/global/..
/admin/clients/product/characteristic/property/decorators/global/..

My first problem was I had failed to implement the copy method, which means it was never calling the toArray I implemented which in turn would call the excludeItems which had the logic to exclude properties like we discussed.

Im still questioning if I should actually just extend the class instead, the issue with decorators is I can only tap into public methods so im having to implement protected methods so I have access.

Is there any possibility we could apply this same update onto the 2020.10 branch as I see it's still receiving updates being the LTS? No problem if not :)

Thanks

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

Re: Extend Physical properties

Post by aimeos » 13 Sep 2021, 19:07

createanet wrote: 13 Sep 2021, 07:57 Im still questioning if I should actually just extend the class instead, the issue with decorators is I can only tap into public methods so im having to implement protected methods so I have access.
Yes, if you want to overwrite the protected methods, you have to extend the class like you've mentioned.
createanet wrote: 13 Sep 2021, 07:57 Is there any possibility we could apply this same update onto the 2020.10 branch as I see it's still receiving updates being the LTS? No problem if not :)
We are only applying bugfixes to the 2020.10 LTS branch since some months. Don't know if that change applies for a bugfix. Also note, that beginning of next year (in 3.5 months), 2020.10 LTS will be only supported by the paid ELTS package offered by the Aimeos company: https://aimeos.com/support#c427
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Extend Physical properties

Post by createanet » 21 Sep 2021, 09:31

Thanks :)

Post Reply