Help with Adding Custom Manager and Admin Panel in Aimeos Headless
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!
- PaoloLegaspi
- Posts: 35
- Joined: 07 Nov 2024, 15:02
Re: Help with Adding Custom Manager and Admin Panel in Aimeos Headless
Hi, thanks for getting back to me!
I went ahead and followed the customer JSON standard you suggested. To make things easier, I used Mshop Create since it lets me skip creating a frontend controller for the Inquiry domain. However, I ran into an issue—I'm seeing an error in the logs that says:
Do you have any suggestions on how I can fix this? Here's the code for the post function:
Inquiry Manager
Thanks in advance for your help!
I went ahead and followed the customer JSON standard you suggested. To make things easier, I used Mshop Create since it lets me skip creating a frontend controller for the Inquiry domain. However, I ran into an issue—I'm seeing an error in the logs that says:
Code: Select all
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'prodid' cannot be null:
INSERT INTO "mshop_inquiry" (
"prodid", "email", "name", "mobile", "information", "status",
"mtime", "editor", "siteid", "ctime"
) VALUES (
?, ?, ?, ?, ?, ?,
?, ?, ?, ?
)
[null,null,null,null,null,null,"2024-11-19 13:48:37","127.0.0.1","1.","2024-11-19 13:48:37"]
Code: Select all
public function post(ServerRequestInterface $request, ResponseInterface $response): \Psr\Http\Message\ResponseInterface
{
$view = $this->view();
try {
$body = (string) $request->getBody();
if (($payload = json_decode($body)) === null || !isset($payload->data->attributes)) {
throw new \Aimeos\Client\JsonApi\Exception('Invalid JSON in body', 400);
}
$manager = \Aimeos\MShop::create($this->context(), 'inquiry');
$manager->begin();
$attributes = (array)$payload->data->attributes;
$item = $manager->create()
->set('prodid', $attributes['inquiry.prodid'])
->set('email', $attributes['inquiry.email'])
->set('name', $attributes['inquiry.name'])
->set('mobile', $attributes['inquiry.mobile'])
->set('information', $attributes['inquiry.information']);
$item = $manager->save($item);
$status = 201;
$view->item = $item;
$manager->commit();
} catch (\Aimeos\MShop\Exception $e) {
$status = 404;
$view->errors = $this->getErrorDetails($e, 'mshop');
} catch (\Exception $e) {
$status = $e->getCode() >= 100 && $e->getCode() < 600 ? $e->getCode() : 500;
$view->errors = $this->getErrorDetails($e);
}
return $this->render( $response, $view, $status );
}
Code: Select all
class Standard extends \Aimeos\MShop\Common\Manager\Base implements \Aimeos\MShop\Common\Manager\Iface
{
public function getSaveAttributes(): array
{
return $this->createAttributes([
'prodid' => [
'code' => 'product_inquiry.prodid',
'internalcode' => 'prodInq."prodid"',
'label' => 'Product ID',
'type' => 'int',
'public' => false
],
'email' => [
'code' => 'product_inquiry.email',
'internalcode' => 'prodInq."email"',
'label' => 'Email',
'type' => 'string',
'public' => true
],
'name' => [
'code' => 'product_inquiry.name',
'internalcode' => 'prodInq."name"',
'label' => 'Name',
'type' => 'string',
'public' => true
],
'mobile' => [
'code' => 'product_inquiry.mobile',
'internalcode' => 'prodInq."mobile"',
'label' => 'Mobile',
'type' => 'string'
],
'information' => [
'code' => 'product_inquiry.information',
'internalcode' => 'prodInq."information"',
'label' => 'Information',
'type' => 'string'
],
'status' => [
'code' => 'product_inquiry.status',
'internalcode' => 'prodInq."status"',
'label' => 'Status',
'type' => 'int',
'public' => true
]
]);
}
protected function prefix(): string
{
return 'product_inquiry.';
}
protected function alias(string $code = null): string
{
return 'prodInq';
}
}
- PaoloLegaspi
- Posts: 35
- Joined: 07 Nov 2024, 15:02
Re: Help with Adding Custom Manager and Admin Panel in Aimeos Headless
Update: I managed to fix the error. The issue was with my Manager setup, and I resolved it by creating an Item class for my new domain.