Modify users 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!
yong
Posts: 43
Joined: 10 Apr 2019, 12:55

Re: Modify users table

Post by yong » 23 Jul 2019, 16:02

The mshop_customer and mshop_customer_list are empty but i don't understand why i've a constraint violation !
Please help !

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

Re: Modify users table

Post by aimeos » 23 Jul 2019, 21:08

You've probably extended from the Standard class, not from the Laravel class. The Standard class refers in its lists and property sub-manager to the mshop_customer_* tables instead of the users_* tables.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

yong
Posts: 43
Joined: 10 Apr 2019, 12:55

Re: Modify users table

Post by yong » 24 Jul 2019, 07:57

Hi ! when i execute artisan aimeos:setup , there's not any error but in the database some columns have wrong data ( for example i've not any data in the 'email' column , the columns 'company' and 'website' have the email and some others columns are wrong )

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

Re: Modify users table

Post by aimeos » 24 Jul 2019, 19:40

The bind() calls in our saveItem() method doesn't correspond to your SQL statement in your config
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

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

Re: Modify users table

Post by aimeos » 21 Aug 2019, 13:41

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:

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;
		},
);
Extend the customer manager by the 'mycolumn' column in ./ext/<your_extension>/lib/custom/src/MShop/Customer/Manager/Decorator/Myproject.php:

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 );
	}
}
Configure the new decorator in ./config/shop.php (mshop section):

Code: Select all

	'mshop' => [
		'customer' => [
			'manager' => [
				'decorator' => [
					'local' => ['Myproject']
				]
			]
		]
	]
Aimeos cares about storing and retrieving the data automatically without any further code. Now you can do:

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' );
}
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply