1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* WellCommerce Open-Source E-Commerce Platform |
4
|
|
|
* |
5
|
|
|
* This file is part of the WellCommerce package. |
6
|
|
|
* |
7
|
|
|
* (c) Adam Piotrowski <[email protected]> |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, |
10
|
|
|
* please view the LICENSE file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace WellCommerce\Bundle\FeatureBundle\Enhancer; |
14
|
|
|
|
15
|
|
|
use WellCommerce\Bundle\CatalogBundle\Entity\Extra\ProductExtraTrait; |
16
|
|
|
use WellCommerce\Bundle\CatalogBundle\Entity\Product; |
17
|
|
|
use WellCommerce\Bundle\FeatureBundle\Entity\FeatureSet; |
18
|
|
|
use WellCommerce\Bundle\FeatureBundle\Entity\ProductFeature; |
19
|
|
|
use WellCommerce\Component\DoctrineEnhancer\AbstractMappingEnhancer; |
20
|
|
|
use WellCommerce\Component\DoctrineEnhancer\Definition\ManyToOneDefinition; |
21
|
|
|
use WellCommerce\Component\DoctrineEnhancer\Definition\MappingDefinitionCollection; |
22
|
|
|
use WellCommerce\Component\DoctrineEnhancer\Definition\OneToManyDefinition; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class ProductMappingEnhancer |
26
|
|
|
* |
27
|
|
|
* @author Adam Piotrowski <[email protected]> |
28
|
|
|
*/ |
29
|
|
|
final class ProductMappingEnhancer extends AbstractMappingEnhancer |
30
|
|
|
{ |
31
|
|
|
protected function configureMappingDefinition(MappingDefinitionCollection $collection) |
32
|
|
|
{ |
33
|
|
|
$collection->add(new ManyToOneDefinition([ |
34
|
|
|
'fieldName' => 'featureSet', |
35
|
|
|
'joinColumns' => [ |
36
|
|
|
[ |
37
|
|
|
'name' => 'feature_set_id', |
38
|
|
|
'referencedColumnName' => 'id', |
39
|
|
|
'onDelete' => 'SET NULL', |
40
|
|
|
], |
41
|
|
|
], |
42
|
|
|
'targetEntity' => FeatureSet::class, |
43
|
|
|
])); |
44
|
|
|
|
45
|
|
|
$collection->add(new OneToManyDefinition([ |
46
|
|
|
'fieldName' => 'features', |
47
|
|
|
'targetEntity' => ProductFeature::class, |
48
|
|
|
'mappedBy' => 'product', |
49
|
|
|
'orphanRemoval' => true, |
50
|
|
|
])); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getSupportedEntityClass(): string |
54
|
|
|
{ |
55
|
|
|
return Product::class; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function getExtraTraitClass(): string |
59
|
|
|
{ |
60
|
|
|
return ProductExtraTrait::class; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|