Get reference company table

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
IvanIgniter
Posts: 58
Joined: 01 Dec 2021, 07:41

Get reference company table

Post by IvanIgniter » 22 Dec 2021, 06:34

I am using laravel 6.x, PHP 7.4, Docker desktop/Ubuntu and the Aimeos 2021

I would like to include to get refence item the company table same like as customer reference item in Order domain.
Please help how would I do that?

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

Re: Get reference company table

Post by aimeos » 22 Dec 2021, 18:00

The customer items are added by the order base manager in the search() method or request:
https://github.com/aimeos/aimeos-core/b ... #L913-L919

The easiest way is to create a decorator for that manager which retrieves the items you want and attach them to the items too. Here's the documentation how to create a decorator for a manager:
https://aimeos.org/docs/latest/models/e ... /#easy-way

Then, add your own search() method:

Code: Select all

public function search( \Aimeos\MW\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
{
	$items = $this->getManager()->search( $search, $ref, $total;
	// fetch items based on IDs in $item and add them to $items
	return $items;
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
IvanIgniter
Posts: 58
Joined: 01 Dec 2021, 07:41

Re: Get reference company table

Post by IvanIgniter » 23 Dec 2021, 10:08

Yeah, I noticed that but what I wanted to know is how to call the entire company table record from mshop_order_base.customerid. Instead of calling the records from customer table, I want to call a different table company table records.

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

Re: Get reference company table

Post by aimeos » 24 Dec 2021, 07:59

You need to extend the order base table/manager first and add your new property for the company ID if "company" is an own data domain. Then, you can add the decorator to fetch the company records for the retrieved orders.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
IvanIgniter
Posts: 58
Joined: 01 Dec 2021, 07:41

Re: Get reference company table

Post by IvanIgniter » 06 Jan 2022, 02:29

Ok.. but I can't picture out how to do that. Can you give me a sample or a url how it was done?

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

Re: Get reference company table

Post by aimeos » 06 Jan 2022, 08:39

Add a schema file ./<yourext>/lib/custom/setup/default/schema/order.php:

Code: Select all

<?php
return array(
  'table' => array(
    'mshop_order_base' => function ( \Doctrine\DBAL\Schema\Schema $schema ) {

        $table = $schema->getTable( 'mshop_order_base' );
        $table->addColumn(  'companyid', 'string', array( 'length' => 36, 'notnull' => false ) );
        return $schema;
    },
  ),
);
Then, add a decorator for the order base manager in ./<yourext>/lib/custom/src/MShop/Order/Manager/Base/Decorator/Company.php:

Code: Select all

namespace Aimeos\MShop\Order\Manager\Base\Decorator;

class Company extends \Aimeos\MShop\Common\Manager\Decorator\Base
{
    private $attr = [
        'companyid' => [
            'code' => 'companyid',
            'internalcode' => 'mordba."companyid"',
            'label' => 'Company ID',
            'type' => 'string',
            'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR,
        ],
    ];

    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 );
    }

    public function search( \Aimeos\MW\Criteria\Iface $search, array $ref = [], int &$total = null ) : \Aimeos\Map
    {
        $items = $this->getManager()->search( $search, $ref, $total );

       // order base IDs as keys and company IDs as values
	$map = $items->call( 'get', ['companyid'] )->all();
        // fetch company records
        // add company records to $items
        return $items;
    }
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

User avatar
IvanIgniter
Posts: 58
Joined: 01 Dec 2021, 07:41

Re: Get reference company table

Post by IvanIgniter » 10 Jan 2022, 03:55

Thank you for the sample codes.
I have tried it but I can't find in the documentation how to fetch deferent tables like companies table or a users table which is not part of a domain. Please include the same time how does Aimeos fetch different tables that is not part of a domain?

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

Re: Get reference company table

Post by aimeos » 11 Jan 2022, 08:41

Like written before, you can see how it's done in the order base manager:
https://github.com/aimeos/aimeos-core/b ... #L913-L919
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply