Programaticaly import products no csv

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!
NoAd
Posts: 2
Joined: 03 Nov 2022, 19:46

Programaticaly import products no csv

Post by NoAd » 03 Nov 2022, 20:06

Hello, I;m new to aimeos.

Is there a class that will help mass add products? i got product list from json api.

In documentation i found that i should probably use theese:
https://aimeos.org/docs/2022.x/models/managing-items/

Code: Select all

$manager = \Aimeos\MShop::create( $context, 'product' );
$item = $manager->create(/* pass some data from my json api here */);
but I can't get what to send as $context inside laravel

I use laravel 9.38 (latest), php 8.1, aimeos 2022.x (latest) on VPS/linux debian 11 on apache 2.4

I try to implement aimeos product import inside laravel nova action.

Can someone show a laravel code example for creating one empty item?

below some code example for easier anwser:

Code: Select all

<?php

namespace App\Nova\Actions\Aimeos;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Collection;
use Laravel\Nova\Actions\Action;
use Laravel\Nova\Fields\ActionFields;
use Laravel\Nova\Http\Requests\NovaRequest;

class ImportProduct extends Action
{
    use InteractsWithQueue, Queueable;

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {
    		$manager = \Aimeos\MShop::create( $context, 'product' ); //Call to product manager; But what to send as $context?
    		$item = $manager->create(); // create empty item
    		/* this code returns a error: Unidentified variable $context */
    }
}

NoAd
Posts: 2
Joined: 03 Nov 2022, 19:46

Re: Programaticaly import products no csv

Post by NoAd » 06 Nov 2022, 08:59

any support in this case will be appreciated

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

Re: Programaticaly import products no csv

Post by aimeos » 06 Nov 2022, 19:15

Use this to get the Aimeos context and create a new item:

Code: Select all

$context = app('aimeos.context')->get();
$manager = \Aimeos\MShop::create( $context, 'product' );
$item = $manager->create()->setCode( 'test' );
$manager->save( $item );
Documentation: https://aimeos.org/docs/latest/laravel/ ... os-objects
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply