Extending managers
Forum rules
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your TYPO3, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Extending managers
Hi Aimeos team,
I extended the stock manager a long time ago by adding a new field to the database, "status". Now I'm trying to adapt my custom solution to "the easy way" following this tutorial: https://aimeos.org/docs/2025.x/models/extend-managers/
However, when I use the following code in my decorator:
...the status property is not available. I need to remove the "stock." prefix to make it work. However, it is then named without the prefix. What am I doing wrong?
I extended the stock manager a long time ago by adding a new field to the database, "status". Now I'm trying to adapt my custom solution to "the easy way" following this tutorial: https://aimeos.org/docs/2025.x/models/extend-managers/
However, when I use the following code in my decorator:
Code: Select all
private $attr = [
'stock.status'=> [
'internalcode' => 'status',
'label'=>'Product Stock Status',
'type'=> 'string',
],
];Re: Extending managers
Can you post your complete decorator, please?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
Re: Extending managers
Yes, of course:
I use the property in templates/admin/jqadm/product/item-stock.php:
(EDIT: Fixed a small mistake)
Code: Select all
<?php
namespace Aimeos\MShop\Stock\Manager\Decorator;
/**
* @package MShop
* @subpackage Stock
*/
class Status extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
private $attr = [
'stock.status'=> [
'internalcode' => 'status',
'label'=>'Product Stock Status',
'type'=> 'string', // integer, float, etc.
],
];
public function getSaveAttributes() : array
{
return parent::getSaveAttributes() + $this->createAttributes( $this->attr );
}
public function getSearchAttributes( bool $sub = true ) : array
{
return parent::getSearchAttributes( $sub ) + $this->createAttributes( $this->attr );
}
}Code: Select all
<td class="stock-status optional">
<select class="form-control custom-select item-typeid" tabindex="<?= $this->get( 'tabindex' ); ?>"
v-bind:name="`<?= $enc->js( $this->formparam( ['stock', '_idx_', 'stock.status'] ) ) ?>`.replace( '_idx_', idx )"
placeholder="<?= $enc->attr( $this->translate( 'admin', 'Availability status (optional)' ) ) ?>"
v-bind:readonly="!can('change', idx)"
v-model="item['stock.status']" >
<option value=""></option>
<option value="low" v-bind:selected="item['stock.status'] == 'low'">Niedriger Bestand</option>
<option value="remainder" v-bind:selected="item['stock.status'] == 'remainder'">Restbestand Kollektionsende</option>
<option value="delay" v-bind:selected="item['stock.status'] == 'delay'">Verzögerte Lieferung</option>
<option value="uncertain" v-bind:selected="item['stock.status'] == 'uncertain'">Evtl. nicht lieferbar</option>
</select>
</td>Re: Extending managers
In Common\Item\Base function toArray() line 433, only values with a key not containing a '.' are injected into the array.
https://github.com/aimeos/aimeos-core/b ... #L431-L436
Am I right that this prevents the decorator from working the expected way?
https://github.com/aimeos/aimeos-core/b ... #L431-L436
Am I right that this prevents the decorator from working the expected way?
Re: Extending managers
At least the strpos() in fromArray() and toArray() prevents the data from being added and returned by that methods.
This change may fix the issue without returning the hidden data like ".catalog":
Then, FALSE and 0 will skip, dots in the middle will pass.
What do you think?
This change may fix the issue without returning the hidden data like ".catalog":
Code: Select all
if( strpos( $key, '.' ) === false ) {
// to
if( !strpos( $key, '.' ) ) {
What do you think?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,
Re: Extending managers
Sounds like a good solution to me!
Re: Extending managers
Done in dev-master and 2025.10.x-dev
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos,
give us a star
If you like Aimeos,