To Add a new field to order ,below the invoice number

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!
User avatar
archanaep
Posts: 8
Joined: 10 Aug 2023, 06:07

To Add a new field to order ,below the invoice number

Post by archanaep » 10 Oct 2023, 06:31

I'm new to Aimeos, and I'm using Aimeos 2023.07 with Laravel 9 and PHP 8. Could you please provide guidance on how to add a new field named 'priority' below the invoice number on the order details page within Aimeos' admin interface? Thank you in advance.

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

Re: To Add a new field to order ,below the invoice number

Post by aimeos » 12 Oct 2023, 08:55

1.) Create you own extension here:
https://aimeos.org/extensions

2.) Create a database migration and a manager decorator to add the new field in your extension:
https://aimeos.org/docs/latest/models/extend-managers/

3.) Copy the order/item.php template to your extension and add your new field there:
https://aimeos.org/docs/latest/admin/jq ... templates/
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
archanaep
Posts: 8
Joined: 10 Aug 2023, 06:07

Re: To Add a new field to order ,below the invoice number

Post by archanaep » 14 Oct 2023, 09:25

Hi,

Thank you for your reply. I followed your instructions and added a new field to the mshop_order table. I also created and extended the manager and item files, and added code to the template folder. However, I am having trouble displaying, updating, and saving data in the new field. I am also having an issue with the macro definition for the get and set methods.

Please let me know if you have any suggestions.

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

Re: To Add a new field to order ,below the invoice number

Post by aimeos » 16 Oct 2023, 07:05

Add your new field in the template like this one but replace "order.relatedid" with "priority":
https://github.com/aimeos/ai-admin-jqad ... #L247-L259

The value of "priority" is automatically saved because it gets added to the item here:
https://github.com/aimeos/ai-admin-jqad ... d.php#L468

The manager will then save and fetch the value if the decorator is correctly implemented and configured (!)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
archanaep
Posts: 8
Joined: 10 Aug 2023, 06:07

Re: To Add a new field to order ,below the invoice number

Post by archanaep » 23 Oct 2023, 06:00

The value of "priority" is automatically saved because it gets added to the item here:
https://github.com/aimeos/ai-admin-jqad ... d.php#L468
1)Don't know what I missed? I have added new field as per your instruction. Is the decorator created under the service anymore? Or is it enough to create under the manager directly?

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

Re: To Add a new field to order ,below the invoice number

Post by aimeos » 24 Oct 2023, 07:57

Please show your code (diffs only, not full files)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
archanaep
Posts: 8
Joined: 10 Aug 2023, 06:07

Re: To Add a new field to order ,below the invoice number

Post by archanaep » 27 Oct 2023, 10:27

hi,
Added a field to mshop_order table in packages\myext-ext\setup\default\schema

Code: Select all

'table' => array(
		'mshop_order' => function ( \Aimeos\Upscheme\Schema\Table $table ) {
			$table->engine = 'InnoDB';
			//$table->addColumn( 'priority', 'string', array( 'length' => 64 ) );
			$table->string( 'priority' );
			return $table;
		},
		)
Decorator file in \packages\myext-ext\src\MShop\Order\Manager\Decorator

Code: Select all


namespace Aimeos\MShop\Order\Manager\Decorator;

 
class Myproject extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
    private $searchConfig = array(
        'order.priority'=> array(
            'code'=>'order.priority',
            'internalcode'=>'mord."priority"',
            'label'=>'order priority',
            'type'=> 'string', // integer, float, etc.
            'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR, // _INT, _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 );
    }
	

   
}
And item file in packages\myext-ext\src\MShop\Order\Item

Code: Select all

<?php 

/**
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
 * @package MShop
 * @subpackage Order
 */

namespace Aimeos\MShop\Order\Item;

 
class Myproject extends Standard
{
    private $values;
 
    public function __construct( array $values )
    {
        parent::__construct( 'order.', $values );
        $this->values = $values;
    }
 
    /**
     * Returns priority for the priority order
     *
     * @return string|null order priority of the order
     */
   public function getPriority() : string
	{
		return (string) $this->get( 'order.priority','' ) ;
	}


	
	public function setPriority( ?string $value ) : \Aimeos\Mshop\Order\Item\Iface
	{
		return $this->set( 'order.priority', (string) $value );
	}

   $item = parent::fromArray( $list, $private );

		foreach( $list as $key => $value )
		{
			switch( $key )
			{
				case 'order.priority': $item = $item->setPriority( $value ); break;
				
			}

			unset( $list[$key] );
		}
		dd($item);
		return $item;
    public function toArray( $private = false )
    {
        $list = parent::toArray( $private );
 
        if( $private === true ) {
            $list['order.priority'] = $this->getPriority();
        }
 dd($list);
        return $list;
    }
}

The template file is packages\myext-ext\templates\admin\jqadm\order

Code: Select all

div class="col-8">
	<input class="form-control item-priority" type="text" tabindex="1"
	name="<?= $enc->attr( $this->formparam( array( 'item', 'order.priority' ) ) ) ?>"	placeholder="<?= $enc->attr( $this->translate( 'admin', 'Priority (optional)' ) ) ?>"
	value="<?= $enc->attr( $this->get( 'itemData/priority' ) ) ?>"
	:readonly="!can('change')">
</div>
And the config is config/mshop.php

Code: Select all

  'order' => [
        'manager' => [
        		       'decorators' => [
                'local' => ['Myproject']
            ]
        ],
		'item' => [
            
                'local' => ['Myproject']
            ],
			
        ],
.
Thank you for your response.

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

Re: To Add a new field to order ,below the invoice number

Post by aimeos » 31 Oct 2023, 10:45

archanaep wrote: 27 Oct 2023, 10:27

Code: Select all

'table' => array(
	'mshop_order' => function ( \Aimeos\Upscheme\Schema\Table $table ) {
		$table->string( 'priority' );
	},
)
This is correct.
archanaep wrote: 27 Oct 2023, 10:27 Decorator file in \packages\myext-ext\src\MShop\Order\Manager\Decorator

Code: Select all

namespace Aimeos\MShop\Order\Manager\Decorator;
 
class Myproject extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
    private $searchConfig = array(
        'order.priority'=> array(
            'code'=>'order.priority',
            'internalcode'=>'mord."priority"',
            'label'=>'order priority',
            'type'=> 'string', // integer, float, etc.
            'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR, // _INT, _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 );
    }
}
Here, the key and code is wrong because it must be "priority" only. In 2023.10+, you can strip the $searchConfig value down to:

Code: Select all

        'priority'=> array(
            'internalcode'=>'mord."priority"',
            'label'=>'order priority',
        ),
archanaep wrote: 27 Oct 2023, 10:27 And item file in packages\myext-ext\src\MShop\Order\Item
The order item class is unused and must be removed.
archanaep wrote: 27 Oct 2023, 10:27 The template file is packages\myext-ext\templates\admin\jqadm\order

Code: Select all

div class="col-8">
	<input class="form-control item-priority" type="text" tabindex="1"
	name="<?= $enc->attr( $this->formparam( array( 'item', 'order.priority' ) ) ) ?>"	placeholder="<?= $enc->attr( $this->translate( 'admin', 'Priority (optional)' ) ) ?>"
	value="<?= $enc->attr( $this->get( 'itemData/priority' ) ) ?>"
	:readonly="!can('change')">
</div>
Here, it must be only "priority" too:

Code: Select all

	name="<?= $enc->attr( $this->formparam( array( 'item', 'priority' ) ) ) ?>"
archanaep wrote: 27 Oct 2023, 10:27 And the config is config/mshop.php

Code: Select all

 
 'order' => [
    'manager' => [
        'decorators' => [
            'local' => ['Myproject']
        ]
    ],
    'item' => [
        'local' => ['Myproject']
    ],
],
.
The "item" config is unused and must be removed.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
archanaep
Posts: 8
Joined: 10 Aug 2023, 06:07

Re: To Add a new field to order ,below the invoice number

Post by archanaep » 01 Nov 2023, 09:47

Thank you for your valuable reply. I modified the code in the template and decorator files, and the data now saves and updates successfully.

User avatar
archanaep
Posts: 8
Joined: 10 Aug 2023, 06:07

Re: To Add a new field to order ,below the invoice number

Post by archanaep » 08 Aug 2024, 09:48

Hi,
I am getting error while editing catalog product from admin after adding new field in order section using Aimeos extension. Is there any mistake in adding only the desired folder like order inside Mshop and corresponding folder in JQAdm in the extension ?If so, what other files should be added? What should be done to access only the order folder from the extension folder and the rest of the from default folder?
The error is:
Aimeos\MShop\Common\Item\Lists\Standard::setRefId(): Argument #1 ($refid) must be of type string, null given, called in /xx/xx/xx/xx/packages/myext-ext/src/Admin/JQAdm/Product/Category/Standard.php on line 250

Post Reply