How to add additional fields to a product
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Posts: 1
- Joined: 29 Aug 2021, 18:27
How to add additional fields to a product
Hello ,need to extend mshop_product table can i do it same as users , what in need extend instead of '\Aimeos\MShop\Common\Manager\Decorator\Base' becouse i don't found same methods in Product .Can i see some examples like your code but for my table or maybe documentation link ? I saw https://aimeos.org/docs/Developers/Libr ... ema_update but did no understand how use is for my table I use 2020.10.7 versionaimeos wrote: ↑21 Aug 2019, 13:43 Starting with the upcoming 2019.10 release, managing custom columns will be super easy.
Extend the table (like already available) in ./ext/<your_extension>/lib/custom/setup/default/schema/customer.php:Extend the customer manager by the 'mycolumn' column in ./ext/<your_extension>/lib/custom/src/MShop/Customer/Manager/Decorator/Myproject.php:Code: Select all
return array( 'table' => array( 'users' => function ( \Doctrine\DBAL\Schema\Schema $schema ) { $table = $schema->getTable( 'users' ); $table->addColumn( 'mycolumn', 'string', array( 'length' => 64 ) ); return $schema; }, );
Configure the new decorator in configuration (mshop section):Code: Select all
namespace Aimeos\MShop\Customer\Manager\Decorator; class Myproject extends \Aimeos\MShop\Common\Manager\Decorator\Base { private $attr = [ 'mycolumn' => [ 'code' => 'mycolumn', 'internalcode' => 'mcus."mycolumn"', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR, ] ]; public function getSaveAttributes() { return parent::getSaveAttributes() + $this->createAttributes( $this->attr ); } public function getSearchAttributes( $withsub = true ) { return parent::getSearchAttributes( $withsub ) + $this->createAttributes( $this->attr ); } }
Aimeos cares about storing and retrieving the data automatically without any further code. Now you can do:Code: Select all
'mshop' => [ 'customer' => [ 'manager' => [ 'decorator' => [ 'local' => ['Myproject'] ] ] ] ]
Code: Select all
$manager = \Aimeos\MShop::create( $context, 'customer' ); $item = $manager->createItem()->set( 'mycolumn', 'myvalue' ); $item = $manager->saveItem( $item ); $search = $manager->createSearch(); $search->setConditions( $search->compare( '==', 'mycolumn', 'myvalue' ) ); foreach( $manager->searchItems( $search ) as $item ) { echo $item->get( 'mycolumn', 'default value' ); }
Re: How to add additional fields to a product
It's the same as for customers, just replace every occurence of "customer" by "product" including the in the file names.
The latest documentation is available here:
https://aimeos.org/docs/latest/models/extend-managers/
The latest documentation is available here:
https://aimeos.org/docs/latest/models/extend-managers/
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