Unable to save new product
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!
Unable to save new product
Hi,
i'm starting using Aimeos but i can't figure out why my custom product import is not working and doesn't give any error.
I created the following job controller:
Laravel Version: 6.20.31
Aimeos Version: 2021.07.4
Php Version: 8.0.9
i'm starting using Aimeos but i can't figure out why my custom product import is not working and doesn't give any error.
I created the following job controller:
Code: Select all
class Standard extends Base implements Iface
{
public function getName() : string
{
return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Product import via json');
}
public function getDescription() : string
{
return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Import all products from json');
}
public function run()
{
$context = $this->getContext();
$manager = MShop::create($context,'product');
$logger = $context->getLogger();
try {
$item = $manager->create([
'product.code' => 'TEST',
'product.label' => 'TEST PRODUCT',
'product.type' => "default",
'product.status' => 1,
'price.currencyid' => "EUR",
'price.quantity' => 1,
'price.value' => 1.20,
'price.taxrate' => 22.0,
'catalog.code' => "F1",
]);
$item = $manager->save($item, true);
$logger->log("Id: " . $item->getId());
}
catch (\Throwable $e) {
$manager->rollback();
$logger->log('Product import error: ' . $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
}
Aimeos Version: 2021.07.4
Php Version: 8.0.9
Re: Unable to save new product
First, you have to create a factory class because for "product/import" there's no default one available (only for "product/import/csv" and "product/import/xml"):
https://aimeos.org/docs/latest/cronjobs ... r/#factory
Furthermore, the namespace is missing in your file:
Execute the importer using:
https://aimeos.org/docs/latest/cronjobs ... r/#factory
Furthermore, the namespace is missing in your file:
Code: Select all
namespace Aimeos\Controller\Jobs\Product\Import;
class Standard extends Base implements Iface
{
public function getName() : string
{
return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Product import via json');
}
public function getDescription() : string
{
return $this->getContext()->getI18n()->dt( 'controller/jobs', 'Import all products from json');
}
public function run()
{
$context = $this->getContext();
$manager = MShop::create($context,'product');
$logger = $context->getLogger();
try {
$item = $manager->create([
'product.code' => 'TEST',
'product.label' => 'TEST PRODUCT',
'product.type' => "default",
'product.status' => 1,
'price.currencyid' => "EUR",
'price.quantity' => 1,
'price.value' => 1.20,
'price.taxrate' => 22.0,
'catalog.code' => "F1",
]);
$item = $manager->save($item, true);
$logger->log("Id: " . $item->getId());
}
catch (\Throwable $e) {
$manager->rollback();
$logger->log('Product import error: ' . $e->getMessage() . "\n" . $e->getTraceAsString());
}
}
}
Code: Select all
php artisan aimeos:jobs product/import
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