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\Factory; |
12
|
|
|
|
13
|
|
|
use BitBag\SyliusWishlistPlugin\Entity\WishlistInterface; |
14
|
|
|
use BitBag\SyliusWishlistPlugin\Entity\WishlistProductInterface; |
15
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
16
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
17
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
18
|
|
|
|
19
|
|
|
final class WishlistProductFactory implements WishlistProductFactoryInterface |
20
|
|
|
{ |
21
|
|
|
private FactoryInterface $wishlistProductFactory; |
22
|
|
|
|
23
|
|
|
public function __construct(FactoryInterface $wishlistProductFactory) |
24
|
|
|
{ |
25
|
|
|
$this->wishlistProductFactory = $wishlistProductFactory; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function createNew(): WishlistProductInterface |
29
|
|
|
{ |
30
|
|
|
/** @var WishlistProductInterface $wishlistProduct */ |
31
|
|
|
$wishlistProduct = $this->wishlistProductFactory->createNew(); |
32
|
|
|
|
33
|
|
|
return $wishlistProduct; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function createForWishlistAndProduct( |
37
|
|
|
WishlistInterface $wishlist, |
38
|
|
|
ProductInterface $product |
39
|
|
|
): WishlistProductInterface { |
40
|
|
|
$wishlistProduct = $this->createNew(); |
41
|
|
|
|
42
|
|
|
$wishlistProduct->setWishlist($wishlist); |
43
|
|
|
$wishlistProduct->setProduct($product); |
44
|
|
|
/** @var ProductVariantInterface $variant */ |
45
|
|
|
$variant = $product->getVariants()->first(); |
46
|
|
|
$wishlistProduct->setVariant($variant); |
47
|
|
|
|
48
|
|
|
return $wishlistProduct; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function createForWishlistAndVariant( |
52
|
|
|
WishlistInterface $wishlist, |
53
|
|
|
ProductVariantInterface $variant |
54
|
|
|
): WishlistProductInterface { |
55
|
|
|
$wishlistProduct = $this->createNew(); |
56
|
|
|
|
57
|
|
|
$wishlistProduct->setWishlist($wishlist); |
58
|
|
|
/** @var ProductInterface $product */ |
59
|
|
|
$product = $variant->getProduct(); |
60
|
|
|
$wishlistProduct->setProduct($product); |
61
|
|
|
$wishlistProduct->setVariant($variant); |
62
|
|
|
|
63
|
|
|
return $wishlistProduct; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|