forked from ergonode/exporter-shopware-6-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProductCoverMapper.php
43 lines (37 loc) · 1.42 KB
/
ProductCoverMapper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Copyright © Ergonode Sp. z o.o. All rights reserved.
* See LICENSE.txt for license details.
*/
declare(strict_types=1);
namespace Ergonode\ExporterShopware6\Infrastructure\Mapper\Product;
use Ergonode\Channel\Domain\Entity\Export;
use Ergonode\Core\Domain\ValueObject\Language;
use Ergonode\ExporterShopware6\Domain\Entity\Shopware6Channel;
use Ergonode\ExporterShopware6\Infrastructure\Mapper\ProductMapperInterface;
use Ergonode\ExporterShopware6\Infrastructure\Model\Product\Shopware6ProductMedia;
use Ergonode\ExporterShopware6\Infrastructure\Model\Shopware6Product;
use Ergonode\Product\Domain\Entity\AbstractProduct;
class ProductCoverMapper implements ProductMapperInterface
{
public function map(
Shopware6Channel $channel,
Export $export,
Shopware6Product $shopware6Product,
AbstractProduct $product,
?Language $language = null
): Shopware6Product {
$media = $shopware6Product->getMedia();
if (!empty($media)) {
usort(
$media,
function (Shopware6ProductMedia $firstMediaElement, Shopware6ProductMedia $secondMediaElement) {
return $firstMediaElement->getPosition() > $secondMediaElement->getPosition();
},
);
$coverMedia = reset($media);
$shopware6Product->setCoverId($coverMedia->getId());
}
return $shopware6Product;
}
}