1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file was created by developers working at BitBag |
5
|
|
|
* Do you need more information about us and what we do? Visit our https://bitbag.io website! |
6
|
|
|
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace BitBag\SyliusWishlistPlugin\Services\Generator; |
12
|
|
|
|
13
|
|
|
use BitBag\SyliusWishlistPlugin\Command\Wishlist\WishlistItemInterface; |
14
|
|
|
use BitBag\SyliusWishlistPlugin\Model\Factory\VariantPdfModelFactoryInterface; |
15
|
|
|
use BitBag\SyliusWishlistPlugin\Model\VariantPdfModelInterface; |
16
|
|
|
use BitBag\SyliusWishlistPlugin\Resolver\VariantImageToDataUriResolverInterface; |
17
|
|
|
use Sylius\Component\Core\Model\ProductVariant; |
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
19
|
|
|
|
20
|
|
|
final class ModelCreator implements ModelCreatorInterface |
21
|
|
|
{ |
22
|
|
|
private VariantImageToDataUriResolverInterface $variantImageToDataUriResolver; |
23
|
|
|
|
24
|
|
|
private VariantPdfModelFactoryInterface $variantPdfModelFactory; |
25
|
|
|
|
26
|
|
|
public function __construct( |
27
|
|
|
VariantImageToDataUriResolverInterface $variantImageToDataUriResolver, |
28
|
|
|
VariantPdfModelFactoryInterface $variantPdfModelFactory |
29
|
|
|
) { |
30
|
|
|
$this->variantImageToDataUriResolver = $variantImageToDataUriResolver; |
31
|
|
|
$this->variantPdfModelFactory = $variantPdfModelFactory; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function createWishlistItemToPdf( |
35
|
|
|
WishlistItemInterface $wishlistProduct, |
36
|
|
|
Request $request, |
37
|
|
|
ProductVariant $variant |
38
|
|
|
): VariantPdfModelInterface |
39
|
|
|
{ |
40
|
|
|
$cartItem = $wishlistProduct->getCartItem()->getCartItem(); |
41
|
|
|
$quantity = $cartItem->getQuantity(); |
42
|
|
|
$baseUrl = $request->getSchemeAndHttpHost(); |
43
|
|
|
$urlToImage = $this->variantImageToDataUriResolver->resolve($variant, $baseUrl); |
44
|
|
|
$actualVariant = $cartItem->getVariant()->getCode(); |
|
|
|
|
45
|
|
|
|
46
|
|
|
return $this->variantPdfModelFactory->createWithVariantAndImagePath( |
47
|
|
|
$variant, |
48
|
|
|
$urlToImage, |
49
|
|
|
$quantity, |
50
|
|
|
$actualVariant |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|