Extend Physical properties
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!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Extend Physical properties
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.
1.
An example of my new input is described below, ive removed bloat so its clearer.
2.
I have created a global decorator and updated the respective config.
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.
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.
Decorating the characteristics properties required me overriding the following methods.
...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
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>
I have created a global decorator and updated the respective config.
Code: Select all
admin/jqadm/product/physical/decorators/global/Physical
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;
}
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
Code: Select all
get,save,toArray,fromArray,getPropertyTypes,excludeItems,render
----
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
Re: Extend Physical properties
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, give us a star
If you like Aimeos, give us a star
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Extend Physical properties
Thank you for the feedback, Im glad that what I was doing is correct although it might not necessarily feel like it
Re: Extend Physical properties
The next version will have configurable physical properties:
https://github.com/aimeos/ai-admin-jqad ... b1296e2d8a
https://github.com/aimeos/ai-admin-jqad ... b1296e2d8a
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Extend Physical properties
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,
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,
Re: Extend Physical properties
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, give us a star
If you like Aimeos, give us a star
-
- Posts: 72
- Joined: 22 Mar 2021, 16:56
Re: Extend Physical properties
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
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
Re: Extend Physical properties
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 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.
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#c427createanet 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
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star