Unable to save new product

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!
mgrifa
Posts: 1
Joined: 06 Aug 2021, 10:31

Unable to save new product

Post by mgrifa » 06 Aug 2021, 10:38

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:

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());
        }
    }
}
Laravel Version: 6.20.31
Aimeos Version: 2021.07.4
Php Version: 8.0.9

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

Re: Unable to save new product

Post by aimeos » 07 Aug 2021, 10:21

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:

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());
        }
    }
}
Execute the importer using:

Code: Select all

php artisan aimeos:jobs product/import
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply