1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Created by solutionDrive GmbH |
7
|
|
|
* |
8
|
|
|
* @copyright 2018 solutionDrive GmbH |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace solutionDrive\SyliusProductBundlesPlugin\Service; |
12
|
|
|
|
13
|
|
|
use solutionDrive\SyliusProductBundlesPlugin\Entity\ProductBundleInterface; |
14
|
|
|
use solutionDrive\SyliusProductBundlesPlugin\Service\Options\ProductBundleSlotOptionsInterface; |
15
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
16
|
|
|
use Sylius\Component\Resource\Factory\FactoryInterface; |
17
|
|
|
|
18
|
|
|
class ProductBundleCreator implements ProductBundleCreatorInterface |
19
|
|
|
{ |
20
|
|
|
/** @var FactoryInterface */ |
21
|
|
|
private $productBundleFactory; |
22
|
|
|
|
23
|
|
|
/** @var ProductBundleManipulatorInterface */ |
24
|
|
|
private $productBundleManipulator; |
25
|
|
|
|
26
|
|
|
public function __construct( |
27
|
|
|
FactoryInterface $productBundleFactory, |
28
|
|
|
ProductBundleManipulatorInterface $productBundleManipulator |
29
|
|
|
) { |
30
|
|
|
$this->productBundleFactory = $productBundleFactory; |
31
|
|
|
$this->productBundleManipulator = $productBundleManipulator; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function createProductBundle(ProductInterface $productBundleProduct): void |
35
|
|
|
{ |
36
|
|
|
/** @var ProductBundleInterface $productBundle */ |
37
|
|
|
$productBundle = $this->productBundleFactory->createNew(); |
38
|
|
|
$productBundle->setProduct($productBundleProduct); |
39
|
|
|
$this->productBundleManipulator->setProductBundle($productBundle); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getProductBundle(): ProductBundleInterface |
43
|
|
|
{ |
44
|
|
|
return $this->productBundleManipulator->getProductBundle(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
|
|
public function addSlot( |
51
|
|
|
string $slotName, |
52
|
|
|
?ProductBundleSlotOptionsInterface $options = null, |
53
|
|
|
array $products = [] |
54
|
|
|
): void { |
55
|
|
|
$this->productBundleManipulator->addSlot($slotName, $options, $products); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|