My environment is the following:
Laravel Framework 5.8.26
aimeos-laravel 2019.04
PHP Version 7.2.19-1+ubuntu18.04.1+deb.sury.org+1
The topic is named as 'How to add additional fields to a customer' but here is no explained exactly about customer ((
Thank for guy who explained for Product but it doesn't help me completely (
Maybe somebody may explain me where I am wrong ? Regarding aimeos version 2019.04. Because now I can't access the admin panel, I get '403 This action is unauthorized.' and seems it takes a lot of time to find the problem (((
My files:
/var/www/labor/ext/labor/lib/custom/setup/default/schema/customer.php
Code: Select all
<?php
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2016-2018-2018
*/
return array(
'table' => array(
'mshop_customer' => function ( \Doctrine\DBAL\Schema\Schema $schema ) {
$table = $schema->getTable( 'mshop_customer' );
$table->addColumn( 'name1', 'string', array( 'length' => 255 ) );
return $schema;
},
),
);
/var/www/labor/ext/labor/config/mshop.php
Code: Select all
<?php
return array(
'customer' => array(
'manager' => array(
'name' => 'Customer',
'standard' => [
'delete' => array(
'ansi' => '
DELETE FROM "users"
WHERE :cond
',
),
'insert' => array(
'ansi' => '
INSERT INTO "users" (
"siteid", "name", "email", "company", "vatid", "salutation", "title",
"firstname", "lastname", "address1", "address2", "address3",
"postal", "city", "state", "countryid", "langid", "telephone",
"telefax", "website", "longitude", "latitude",
"birthday", "status", "vdate", "password",
"updated_at", "editor", "created_at"
) VALUES (
?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?
)
',
),
'update' => array(
'ansi' => '
UPDATE "users"
SET "siteid" = ?, "name" = ?, "email" = ?, "company" = ?, "vatid" = ?,
"salutation" = ?, "title" = ?, "firstname" = ?, "lastname" = ?,
"address1" = ?, "address2" = ?, "address3" = ?, "postal" = ?,
"city" = ?, "state" = ?, "countryid" = ?, "langid" = ?,
"telephone" = ?, "telefax" = ?, "website" = ?,
"longitude" = ?, "latitude" = ?, "birthday" = ?,
"status" = ?, "vdate" = ?, "password" = ?, "updated_at" = ?, "editor" = ?
WHERE "id" = ?
',
),
'search' => array(
'ansi' => '
SELECT lvu."id" AS "customer.id", lvu."siteid" AS "customer.siteid",
lvu."name" AS "customer.label", lvu."email" AS "customer.code",
lvu."company" AS "customer.company", lvu."vatid" AS "customer.vatid",
lvu."salutation" AS "customer.salutation", lvu."title" AS "customer.title",
lvu."firstname" AS "customer.firstname", lvu."lastname" AS "customer.lastname",
lvu."address1" AS "customer.address1", lvu."address2" AS "customer.address2",
lvu."address3" AS "customer.address3", lvu."postal" AS "customer.postal",
lvu."city" AS "customer.city", lvu."state" AS "customer.state",
lvu."countryid" AS "customer.countryid", lvu."langid" AS "customer.languageid",
lvu."telephone" AS "customer.telephone",lvu."telefax" AS "customer.telefax",
lvu."email" AS "customer.email", lvu."website" AS "customer.website",
lvu."longitude" AS "customer.longitude", lvu."latitude" AS "customer.latitude",
lvu."birthday" AS "customer.birthday", lvu."status" AS "customer.status",
lvu."vdate" AS "customer.dateverified", lvu."password" AS "customer.password",
lvu."created_at" AS "customer.ctime", lvu."updated_at" AS "customer.mtime",
lvu."editor" AS "customer.editor", lvu."name1" AS "customer.name1"
FROM "users" AS lvu
:joins
WHERE :cond
GROUP BY lvu."id", lvu."siteid", lvu."name", lvu."company", lvu."vatid",
lvu."salutation", lvu."title", lvu."firstname", lvu."lastname",
lvu."address1", lvu."address2", lvu."address3", lvu."postal",
lvu."city", lvu."state", lvu."countryid", lvu."langid",
lvu."telephone", lvu."telefax", lvu."email", lvu."website",
lvu."longitude", lvu."latitude", lvu."birthday", lvu."status",
lvu."vdate", lvu."password", lvu."created_at", lvu."updated_at",
lvu."editor"
/*-orderby*/ ORDER BY :order /*orderby-*/
LIMIT :size OFFSET :start
',
),
'count' => array(
'ansi' => '
SELECT COUNT(*) AS "count"
FROM (
SELECT DISTINCT lvu."id"
FROM "users" AS lvu
:joins
WHERE :cond
LIMIT 10000 OFFSET 0
) AS list
',
),
'newid' => array(
'db2' => 'SELECT IDENTITY_VAL_LOCAL()',
'mysql' => 'SELECT LAST_INSERT_ID()',
'oracle' => 'SELECT users.CURRVAL FROM DUAL',
'pgsql' => 'SELECT lastval()',
'sqlite' => 'SELECT last_insert_rowid()',
'sqlsrv' => 'SELECT SCOPE_IDENTITY()',
'sqlanywhere' => 'SELECT @@IDENTITY',
),
]
),
),
);
/var/www/labor/ext/labor/lib/custom/src/MShop/Customer/Manager/Customer.php
Code: Select all
<?php
namespace Aimeos\MShop\Customer\Manager;
class Customer extends Standard
{
private $salt;
private $searchConfig = array(
'customer.name1'=> array(
'code'=>'customer.name1',
'internalcode'=>'mpro."name1"',
'label'=>'Name 1',
'type'=> 'string', // integer, float, etc.
'internaltype'=> \Aimeos\MW\DB\Statement\Base::PARAM_STR, // _INT, _FLOAT, etc.
),
);
public function __construct(\Aimeos\MShop\Context\Item\Iface $context)
{
parent::__construct($context);
/** mshop/customer/manager/salt
* Password salt for all customer passwords of the installation
*
* The default password salt is used if no user-specific salt can be
* stored in the database along with the user data. It's highly recommended
* to set the salt to a random string of at least eight chars using
* characters, digits and special characters
*
* @param string Installation wide password salt
* @since 2014.03
* @category Developer
* @category User
* @see mshop/customer/manager/password/name
* @sse mshop/customer/manager/password/options
*/
$this->salt = $context->getConfig()->get( 'mshop/customer/manager/salt', 'mshop' );
}
public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true )
{
die;
// a modified copy of the code from the parent class
// extended by a bind() call and updated bind positions (first parameter)
}
/**
* @param bool $withsub
* @return \Aimeos\MW\Criteria\Attribute\Iface
* @throws \Aimeos\MW\Common\Exception
*/
public function getSearchAttributes( $withsub = true )
{
$list = parent::getSearchAttributes( $withsub );
foreach( $this->searchConfig as $key => $fields ) {
$list[$key] = new \Aimeos\MW\Criteria\Attribute\Standard( $fields );
}
return $list;
}
/**
* @param array $values
* @param array $listItems
* @param array $refItems
* @param array $addrItems
* @param array $propItems
* @return \Aimeos\MShop\Customer\Item\Customer|\Aimeos\MShop\Customer\Item\Iface
* @throws \Aimeos\MShop\Exception
*/
protected function createItemBase(array $values = [], array $listItems = [], array $refItems = [], array $addrItems = [], array $propItems = [])
{
$helper = $this->getPasswordHelper();
$address = new \Aimeos\MShop\Common\Item\Address\Simple( 'customer.', $values );
return new \Aimeos\MShop\Customer\Item\Customer(
$address, $values, $listItems, $refItems, $addrItems, $propItems, $helper, $this->salt
);
}
}
/var/www/labor/ext/labor/lib/custom/src/MShop/Customer/Item/Customer.php
Code: Select all
<?php
namespace Aimeos\MShop\Customer\Item;
class Customer extends Standard
{
protected $name1;
public function __construct(\Aimeos\MShop\Common\Item\Address\Iface $address, array $values = [], $listItems = [], $refItems = [], $addrItems = [], $propItems = [],
?\Aimeos\MShop\Common\Helper\Password\Iface $helper = null, ?string $salt = null)
{
parent::__construct($address, $values, $listItems, $refItems, $addrItems, $propItems, $helper, $salt);
}
public function fromArray( array &$list, $private = false )
{
$unknown = [];
$list = parent::fromArray( $list );
// foreach( $list as $key => $value )
// {
// switch( $key )
// {
// case 'myid': $this->setMyId( $value ); break;
// default: $unknown[$key] = $value;
// }
// }
return $list;
// return $unknown;
}
public function toArray( $private = false )
{
$list = parent::toArray( $private );
return $list;
if( $private === true ) {
$list['myid'] = $this->getMyId();
}
return $list;
}
}
I think problem in this file /var/www/labor/vendor/aimeos/aimeos-laravel/src/Aimeos/Shop/Controller/AdminController.php
Code: Select all
if( Auth::check() === false
|| $request->user()->can( 'admin', [AdminController::class, ['admin', 'editor']] ) === false
) {
return redirect()->guest( 'login' );
}
But I am really logged in ( in front-end part it works. Please help me (
Also createItemBase method is not called
I noticed, the following condition is triggered:
Code: Select all
$request->user()->can( 'admin', [AdminController::class, ['admin', 'editor']] ) === false
So user has not permissions for some reason ( Maybe groups data were not fetched..