Add column to mshop_order_base

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
matteovg7
Posts: 14
Joined: 12 Dec 2019, 16:13

Add column to mshop_order_base

Post by matteovg7 » 03 Mar 2020, 15:19

Hi, I want to add a column to the table mshop_order_base.
I followed the guide from https://aimeos.org/docs/Developers/Libr ... gers_items creating a decorator but I'm unable to retrieve this field in the manager.
With the table mshop_order I done the same and it works without problems in its relative manager.
Which are the differences of extending a table of a item and a subitem?
Thank you.

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

Re: Add column to mshop_order_base

Post by aimeos » 04 Mar 2020, 15:20

Make sure you use the right configuration, e.g. "mshop/order/manager/base/decorator/local" with "['Mydecorator']" to wrap a local decorator ("local" means it uses the same namespace as the manager you want do decorate + "\Decorator") around the order base manager.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

matteovg7
Posts: 14
Joined: 12 Dec 2019, 16:13

Re: Add column to mshop_order_base

Post by matteovg7 » 04 Mar 2020, 16:56

Now I tried to decorate mshop_order_base_product and I have the same problem.
This is ext/vg7/config/mshop.php:

Code: Select all

<?php
return [
    'order' => [
        'manager' => [
            'name' => 'OrderVG7',
            'decorators' => [
                'local' => ['OrderIdPrint']
            ],
            'base' => [
                'name' => 'OrderBaseVG7',
                'address' => [
                    'name' => 'OrderBaseAddressVG7'
                ],
                'product' => [
                    'name' => 'OrderBaseProductVG7',
                    'decorators' => [
                        'local' => ['OrderBaseProductIdPrint']
                    ]
                ]
            ]
        ],
        'item' => [
            'name' => 'OrderVG7',
            'base' => [
                'name' => 'OrderBaseVG7',
                'address' => [
                    'name' => 'OrderBaseAddressVG7'
                ],
                'product' => [
                    'name' => 'OrderBaseProductVG7'
                ]
            ]
        ]
    ],
];
and this is the decorator in ext/vg7/lib/custom/src/MShop/Order/Manager/Base/Product/Decorator/OrderBaseProductIdPrint.php:

Code: Select all

<?php
namespace Aimeos\MShop\Order\Manager\Base\Product\Decorator;

class OrderBaseProductIdPrint extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
    private $attr = [
        'id_print' => [
            'code' => 'id_print',
            'internalcode' => 'mordbapr."id_print"',
            'type' => 'integer',
            'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT,
        ],
    ];

    public function getSaveAttributes()
    {
        return parent::getSaveAttributes() + $this->createAttributes( $this->attr );
    }

    public function getSearchAttributes( $sub = true )
    {
        return parent::getSearchAttributes( $sub ) + $this->createAttributes( $this->attr );
    }
}

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

Re: Add column to mshop_order_base

Post by aimeos » 05 Mar 2020, 14:49

Your code and configuration seems to be OK but the item configuration is useless and should be removed:

Code: Select all

        'item' => [
            'name' => 'OrderVG7',
            'base' => [
                'name' => 'OrderBaseVG7',
                'address' => [
                    'name' => 'OrderBaseAddressVG7'
                ],
                'product' => [
                    'name' => 'OrderBaseProductVG7'
                ]
            ]
        ]
because the items must be instantiated by the createItemBase() method of your managers. With decorators, you can get/set the new properties with the generic get( 'name' ) and set( 'name', 'value' ) methods that are available in all items.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

matteovg7
Posts: 14
Joined: 12 Dec 2019, 16:13

Re: Add column to mshop_order_base

Post by matteovg7 » 16 Mar 2020, 11:04

Ok, I removed the item configuration, but the problem is still here.

I tried to investigate more accurately and I found that, for example in the method saveItem() of the manager of order/base/product, when executes $columns = $this->getObject()->getSaveAttributes(), $columns is empty because getObject() doesn't return the decorator but the manager itself.
I believe that there is a bug of populating $object with the decorator for order/base and its child, but I'm not able to investigate more further.
Can you please address me to the right way?

I also found that the "Custom Way" of this guide https://aimeos.org/docs/Developers/Libr ... gers_items it works so the problems are only with the decorator mode.

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

Re: Add column to mshop_order_base

Post by aimeos » 16 Mar 2020, 14:19

You haven't configured any decorator for the order base manager, only for the order base product manager according to your posted configuration. Thus, the array for the custom save attribute is empty.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

matteovg7
Posts: 14
Joined: 12 Dec 2019, 16:13

Re: Add column to mshop_order_base

Post by matteovg7 » 17 Mar 2020, 09:35

Yes, now I want to decorate only order base product.

The getObject() method is referring of the order base product manager class, and with my configuration I expect that return the OrderBaseProductIdPrint decorator, but return the order base product manager itself.

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

Re: Add column to mshop_order_base

Post by aimeos » 18 Mar 2020, 08:47

Sorry, was looking at the wrong place.

We've made a change so decorators are now passed down to submanagers.
Can you update and confirm that it's working now?

Code: Select all

composer req aimeos/aimeos-core:2019.10.x-dev
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

matteovg7
Posts: 14
Joined: 12 Dec 2019, 16:13

Re: Add column to mshop_order_base

Post by matteovg7 » 18 Mar 2020, 11:24

Ok, now it works, thank you!

Post Reply