How to reuse Translator?


#1

Initial problem:
the full import is way too long to run every night (and completely unnecessary since we do not update our whole product catalog data daily).

Solution idea:
write a script that queries
https://api.akeneo.com/documentation/filter.html#on-creation-or-update-date
based on “updated since” and we provide it with a date of our interest.

Our idea on the approach:
Reuse importer class:

and simply convert akeneo data to spryker-format with Translator defined at

Problem:
I pinned the code down to something like:

$translator = new ProductImportTranslationStagePlugin();
$out = new DataImportWriteStream(new ProductConcreteDataImporterPlugin());

    try {
        $productCursor = $akeneo->getProductsListPerPage(2,false, $queryParams);
        foreach($productCursor->getItems() as $item){
            //convert using dictionary
            $translatedItem = $translator->process($item,$out,$item);
           (...)

But what I’m currently getting is Logger for middleware process does not configured. Call MiddlewareLoggerTrait::initLogger() first.

Final question:
How do I convert Akeneo “array product” into “spryker-importer” format that importer class accepts?


#2

Hi janmyszkier!

it is not good idea to instantiate plugins somewhere except dependency provider.

If full import is not applicable for your daily product catalog update you can add new middleware process to do it.

you can reuse all plugins from full import. Only one thing that you need to implement is ReadStream (like SprykerEco\Zed\AkeneoPimMiddlewareConnector\Business\Stream\Akeneo\ProductAkeneoApiReadStream) but provide your pagination and query parameters to
$this->akeneoPimService
->getAllProducts();


#3

@valerio8787 please read my question again.
You answer me how to use AKENEO in my plugin and this is not what my question is about. If you didn’t spot this yet, my question already (and successfully) uses akeneo’s getAllproducts equivalent, which is

 $productCursor = $akeneo->getProductsListPerPage(2,false, $queryParams);

I’m NOT asking how to fetch products. I’m asking how to use the Translator defined in ProductImportTranslationStagePlugin. Code sample would be great. Thank you in advance.


#4

Sorry @janmyszkier, you are right i didn’t answer on your question. I suggested the way how resolve your initial problem with introducing of new import process (with differenet input stream). instead of it. So you can reuse ProductImportTranslationStagePlugin only in Middleware context process. And it is not possible just instantiate it and use it somewhere.