Get reference company table
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!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
- IvanIgniter
- Posts: 58
- Joined: 01 Dec 2021, 07:41
Get reference company table
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?
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?
Re: Get reference company table
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:
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, give us a star
If you like Aimeos, give us a star
- IvanIgniter
- Posts: 58
- Joined: 01 Dec 2021, 07:41
Re: Get reference company table
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.
Re: Get reference company table
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, give us a star
If you like Aimeos, give us a star
- IvanIgniter
- Posts: 58
- Joined: 01 Dec 2021, 07:41
Re: Get reference company table
Ok.. but I can't picture out how to do that. Can you give me a sample or a url how it was done?
Re: Get reference company table
Add a schema file ./<yourext>/lib/custom/setup/default/schema/order.php:
Then, add a decorator for the order base manager in ./<yourext>/lib/custom/src/MShop/Order/Manager/Base/Decorator/Company.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;
},
),
);
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, give us a star
If you like Aimeos, give us a star
- IvanIgniter
- Posts: 58
- Joined: 01 Dec 2021, 07:41
Re: Get reference company table
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?
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?
Re: Get reference company table
Like written before, you can see how it's done in the order base manager:
https://github.com/aimeos/aimeos-core/b ... #L913-L919
https://github.com/aimeos/aimeos-core/b ... #L913-L919
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star