1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\CoreBundle\DataFixtures\ORM; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
15
|
|
|
use Sylius\Bundle\CoreBundle\DataFixtures\DataFixture; |
16
|
|
|
use Sylius\Component\Product\Model\AttributeInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Default product attributes to play with Sylius. |
20
|
|
|
* |
21
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
22
|
|
|
* @author Gonzalo Vilaseca <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class LoadProductAttributeData extends DataFixture |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function load(ObjectManager $manager) |
30
|
|
|
{ |
31
|
|
|
$attribute = $this->createAttribute('T-Shirt brand', 't_shirt_brand', 'text', [$this->defaultLocale => 'Brand', 'es_ES' => 'Marca']); |
32
|
|
|
$manager->persist($attribute); |
33
|
|
|
|
34
|
|
|
$attribute = $this->createAttribute('T-Shirt collection', 't_shirt_collection', 'text', [$this->defaultLocale => 'Collection', 'es_ES' => 'Coleccion']); |
35
|
|
|
$manager->persist($attribute); |
36
|
|
|
|
37
|
|
|
$attribute = $this->createAttribute('T-Shirt material', 't_shirt_material', 'text', [$this->defaultLocale => 'Made of', 'es_ES' => 'Material']); |
38
|
|
|
$manager->persist($attribute); |
39
|
|
|
|
40
|
|
|
$attribute = $this->createAttribute('Sticker resolution', 'sticker_resolution', 'text', [$this->defaultLocale => 'Print resolution', 'es_ES' => 'Resolucion']); |
41
|
|
|
$manager->persist($attribute); |
42
|
|
|
|
43
|
|
|
$attribute = $this->createAttribute('Sticker paper', 'sticker_paper', 'text', [$this->defaultLocale => 'Paper', 'es_ES' => 'Papel']); |
44
|
|
|
$manager->persist($attribute); |
45
|
|
|
|
46
|
|
|
$attribute = $this->createAttribute('Mug material', 'mug_material', 'text', [$this->defaultLocale => 'Material', 'es_ES' => 'Material']); |
47
|
|
|
$manager->persist($attribute); |
48
|
|
|
|
49
|
|
|
$attribute = $this->createAttribute('Book author', 'book_author', 'text', [$this->defaultLocale => 'Author', 'es_ES' => 'Autor']); |
50
|
|
|
$manager->persist($attribute); |
51
|
|
|
|
52
|
|
|
$attribute = $this->createAttribute('Book ISBN', 'book_isbn', 'text', [$this->defaultLocale => 'ISBN', 'es_ES' => 'ISBN']); |
53
|
|
|
$manager->persist($attribute); |
54
|
|
|
|
55
|
|
|
$attribute = $this->createAttribute('Book pages', 'book_pages', 'integer', [$this->defaultLocale => 'Number of pages', 'es_ES' => 'Numero de paginas']); |
56
|
|
|
$manager->persist($attribute); |
57
|
|
|
|
58
|
|
|
$manager->flush(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function getOrder() |
65
|
|
|
{ |
66
|
|
|
return 20; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Create attribute. |
71
|
|
|
* |
72
|
|
|
* @param string $name |
73
|
|
|
* @param string $code |
74
|
|
|
* @param string $type |
75
|
|
|
* @param array $presentationTranslations |
76
|
|
|
* |
77
|
|
|
* @return AttributeInterface |
78
|
|
|
*/ |
79
|
|
|
protected function createAttribute($name, $code, $type, array $presentationTranslations) |
80
|
|
|
{ |
81
|
|
|
/* @var $attribute AttributeInterface */ |
82
|
|
|
$attribute = $this->getProductAttributeFactory()->createTyped($type); |
|
|
|
|
83
|
|
|
$attribute->setCode($code); |
84
|
|
|
|
85
|
|
|
foreach ($presentationTranslations as $locale => $presentation) { |
86
|
|
|
$attribute->setCurrentLocale($locale); |
87
|
|
|
$attribute->setFallbackLocale($locale); |
88
|
|
|
$attribute->setName($name); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$this->setReference('Sylius.Attribute.'.$code, $attribute); |
92
|
|
|
|
93
|
|
|
return $attribute; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
|
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: