Mapping different products

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!
Bevi
Posts: 33
Joined: 25 Sep 2017, 20:57

Mapping different products

Post by Bevi » 25 Sep 2017, 21:33

Hi, how am I supposed to make a different mapping for each category? Is it even possible, or will I have to make a new shop for every kind of product?

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

Re: Mapping different products

Post by aimeos » 26 Sep 2017, 11:11

Can you explain that in more detail please?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Bevi
Posts: 33
Joined: 25 Sep 2017, 20:57

Re: Mapping different products

Post by Bevi » 26 Sep 2017, 14:39

I have the following categories in my shop:

1.Wheels
2.Modeling
3.Clothes
4Electronics

each of them needs a different mapping in order to import their own csv, but, as far as I know, I could only make 1 type of mapping in the shop.php.
What should I do?

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

Re: Mapping different products

Post by aimeos » 26 Sep 2017, 15:32

You can copy and extend from the existing factory (https://github.com/aimeos/ai-controller ... actory.php), e.g. to a sub-directory controller/jobs/src/Controller/Jobs/Product/Import/Csv/Clothes/Factory.php in your own Aimeos extension. In the createController() method of your new factory add this:

Code: Select all

public static function createController( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos, $name = null )
{
	$mapping = [
		// ...
	];
	$context->getConfig()->set( 'controller/jobs/product/import/csv/mapping', $mapping );
	return parent::createController( $context, $aimeos, $name );
}
Then, you can execute the importer for each category with the required mapping:

Code: Select all

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

Bevi
Posts: 33
Joined: 25 Sep 2017, 20:57

Re: Mapping different products

Post by Bevi » 26 Sep 2017, 21:39

I'm getting this error:

Code: Select all

[Symfony\Component\Debug\Exception\FatalThrowableError] Call to undefined method Aimeos\Controller\Jobs\Common\Factory\Base::createController()
Are you sure it's:

Code: Select all

  return parent::createController( $context, $aimeos, $name );
?

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

Re: Mapping different products

Post by aimeos » 26 Sep 2017, 22:00

You may have forgotten to extend from the existing class like this:

Code: Select all

class Factory
	extends \Aimeos\Controller\Jobs\Product\Import\Csv\Factory
	implements \Aimeos\Controller\Jobs\Common\Factory\Iface
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Bevi
Posts: 33
Joined: 25 Sep 2017, 20:57

Re: Mapping different products

Post by Bevi » 27 Sep 2017, 16:03

I can now execute

Code: Select all

php artisan aimeos:jobs "product/import/csv/pneumatici"
(please note "pneumatici" is my product name), but I'm still reading from the mapping array in shop.php

So i tried to put 'name' => 'Pneumatici', in the shop.php (not sure if it's the right thing to do) and now I'm getting this error:

Code: Select all

[Aimeos\Controller\Jobs\Exception]
  Class "\Aimeos\Controller\Jobs\Product\Import\Csv\Pneumatici" not available
What should I do from here?

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

Re: Mapping different products

Post by aimeos » 28 Sep 2017, 08:02

The full code for the file "controller/jobs/src/Controller/Jobs/Product/Import/Csv/Clothes/Standard.php" in you own Aimeos extension is:

Code: Select all

namespace Aimeos\Controller\Jobs\Product\Import\Csv\Clothes;

class Factory
   extends \Aimeos\Controller\Jobs\Product\Import\Csv\Factory
   implements \Aimeos\Controller\Jobs\Common\Factory\Iface
{
    public static function createController( \Aimeos\MShop\Context\Item\Iface $context, \Aimeos\Bootstrap $aimeos, $name = null )
    {
        $mapping = [
            // mapping for clothes
        ];
        $context->getConfig()->set( 'controller/jobs/product/import/csv/mapping', $mapping );
        return parent::createController( $context, $aimeos, $name );
    }
}
Then you can execute:

Code: Select all

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

antonlinderer
Posts: 42
Joined: 14 Sep 2017, 09:59

Re: Mapping different products

Post by antonlinderer » 14 Nov 2017, 09:02

Just a small correction... the mentioned code is for file "controller/jobs/src/Controller/Jobs/Product/Import/Csv/Clothes/Factory.php" and thel code for the file "controller/jobs/src/Controller/Jobs/Product/Import/Csv/Clothes/Standard.php" remains the same as in the file "controller/jobs/src/Controller/Jobs/Product/Import/Csv/Standard.php"

Post Reply