Page 1 of 1

Extending Order/Basket

Posted: 05 Feb 2019, 11:09
by cnoelker
Hello,
I would like to add additional fields below the basket (e.g. for a remark by the customer or to have him select one of several delivery addresses) . What's the proper way to do this? Maybe store them as service attributes?
Also, there is already a field 'comment' in the order_base table. Is there a way to make this visible and editable to customers?
Claudia

Re: Extending Order/Basket

Posted: 06 Feb 2019, 10:30
by aimeos
The comment field is available at the summary page where customers can add some text. If you want to show the field in the basket too, you need to add code in the basket/standard client to set the content of that field in the basket object.

A delivery address can be selected in the address section of the checkout. You can rearrange the order of the sections in the checkout or even make a one page checkout if you show that information at a different place:
https://aimeos.org/docs/Configuration/C ... kout_steps

Re: Extending Order/Basket

Posted: 07 Feb 2019, 20:07
by cnoelker
Thank you for providing the link. Is there a way to download the complete configuration documentation as a single file, e.g. PDF? It always switches back to German, which I don't want to read (although it's my mothertongue).
Also, I always get lost inside the links.

Re: Extending Order/Basket

Posted: 08 Feb 2019, 12:55
by aimeos
The configuration documentation is currently available online only. The language switch may happen due to your browser is telling MediaWiki that your preferred language is German.

The best way to dig through the configuration docs is either to search for a configuration option whose name you know but don't know what's the complete string (e.g. "basket-add") or by starting at the overview page (https://aimeos.org/docs/Configuration) and digging deeper into where you want to change something, for example Frontend -> Shop HTML frontend -> Checkout. Then, there are all articles that care about the topic and a list of all configuration settings for that topic you can investigate if you don't really know the name of what you are searching for.

Hope that helps a bit :-)

Re: Extending Order/Basket

Posted: 11 Jun 2019, 12:50
by cnoelker
I need to add additional fields in the order. These are the steps:
* create order.php with addColumn() calls
* extend Aimeos\MShop\Order\Item\Base with my own class B2bItem with __construct(), getters and setters for my fields, toArray() and fromArray().
* extend Aimeos\MShop\Order\Manager\Base with my own class B2bManager with createItemBase() returning B2bItem(...)
* extend Aimeos\Client\Html\Common\Decorator with my own class B2bCheckout
* add the new fields in the SELECT/INSERT/UPDATE queries in mshop.php, set manager->base->name to B2bManager
* configure the decorator B2bCheckout for checkout.
* extend jqadm template so that the new fields are accessed with their getters.
* add input fields for my new order fields in the frontend

I got parts of it to work:
* The fields in the database are created. I filled them manually for the first test.
* When I access the order in the backend, then the values of the new fields are displayed (via the getters).
* The input fields in the frontend are displayed.
* B2bCheckout is called.

But: Saving the basket results in an error thrown in the process method of B2bCheckout: "Call to undefined method Aimeos\MShop\Order\Item\Base\Standard::getOrdername()"

$controller = \Aimeos\Controller\Frontend::create( $this->getContext(), 'basket' );
if (($orderName = $view->param('cs_ordername')) !== null) {
$controller->get()->setOrderername($orderName);
$controller->save();
}

Something must be missing. I checked my code with the example here: https://gist.github.com/boettner-it/081 ... 24907fe91b
In difference to the documentation (https://aimeos.org/docs/Developers/Libr ... gers_items), the GIST is extending the Base classes.
Could you please throw some light on this?

Re: Extending Order/Basket

Posted: 11 Jun 2019, 21:44
by aimeos
You should extend your B2bmanager from the standard order base manager.

What's probably missing in your configuration is to use your manager instead of the standard one, i.e.

Code: Select all

return [
    'order' => [
        'manager' => [
             'name' => 'B2bmanager',
        ]
    ]
];
in your ./config/mshop.php file. In the Gist example it's here: https://gist.github.com/boettner-it/081 ... hop-php-L7

Re: Extending Order/Basket

Posted: 12 Jun 2019, 09:03
by cnoelker
That configuration was available.
I changed every class to extend not the Base class but the one in the parent directory of Base.
Now, I get an error in the backend:
Error SQLSTATE[42S22]: Column not found: 1054 Unknown column 'mord.siteid' in 'where clause', /home/vhosts/biancab2b/typo3conf/ext/aimeos/Resources/Libraries/aimeos/aimeos-core/lib/mwlib/src/MW/DB/Statement/DBAL/Simple.php:91
Where does this come from? It's not in the code which I added.

Re: Extending Order/Basket

Posted: 12 Jun 2019, 17:32
by cnoelker
I tried as you wrote without the Base in the namespace. This doesn't work at all. The mshop.php needs the 'base' to overwrite the SQLs.
I ended up with the same code like I had before and finally got it working by separately excluding those parts which rely on my new fields and their getters and setters. Placing the calls to these functions at their target location one by one did finally work. I made sure to clean the cache and the autoloader frequently, but this did not seem to have any effect.

Then I tried to install the complete extension on the computer of a colleague - and I ran into exactly the same error messages, although the code worked fine on my computer. This is weird. Is there a way to tell Aimeos that it should completely reload everything?
Now, I just have to make my new field mandatory.

Re: Extending Order/Basket

Posted: 12 Jun 2019, 17:42
by aimeos
You are right, for the order base manager the config must be:

Code: Select all

return [
    'order' => [
        'manager' => [
            'base' => [
                 'name' => 'B2bmanager',
            ]
        ]
    ]
];
There is no code caching in Aimeos. Only keep care about the PHP OPCode cache and the APCu cache for configuration settings and translations.