1 | <?php |
||
22 | class Demo |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * File model instance |
||
27 | * @var \gplcart\core\models\File $file |
||
28 | */ |
||
29 | protected $file; |
||
30 | |||
31 | /** |
||
32 | * Category model instance |
||
33 | * @var \gplcart\core\models\Category $category |
||
34 | */ |
||
35 | protected $category; |
||
36 | |||
37 | /** |
||
38 | * Category group model instance |
||
39 | * @var \gplcart\core\models\CategoryGroup $category_group |
||
40 | */ |
||
41 | protected $category_group; |
||
42 | |||
43 | /** |
||
44 | * Product model instance |
||
45 | * @var \gplcart\core\models\Product $product |
||
46 | */ |
||
47 | protected $product; |
||
48 | |||
49 | /** |
||
50 | * Collection model instance |
||
51 | * @var \gplcart\core\models\Collection $collection |
||
52 | */ |
||
53 | protected $collection; |
||
54 | |||
55 | /** |
||
56 | * Collection item model instance |
||
57 | * @var \gplcart\core\models\CollectionItem $collection_item |
||
58 | */ |
||
59 | protected $collection_item; |
||
60 | |||
61 | /** |
||
62 | * An array of created entity IDs |
||
63 | * Entity keys are preserved to guarantee their order upon deletion |
||
64 | * E.g, collection items must be deleted before the related collection |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $created = array( |
||
68 | 'file' => array(), |
||
69 | 'product' => array(), |
||
70 | 'category' => array(), |
||
71 | 'category_group' => array(), |
||
72 | 'collection_item' => array(), |
||
73 | 'collection' => array() |
||
74 | ); |
||
75 | |||
76 | /** |
||
77 | * The store ID |
||
78 | * @var integer |
||
79 | */ |
||
80 | protected $store_id; |
||
81 | |||
82 | /** |
||
83 | * @param FileModel $file |
||
84 | * @param ProductModel $product |
||
85 | * @param CategoryModel $category |
||
86 | * @param CollectionModel $collection |
||
87 | * @param CategoryGroupModel $category_group |
||
88 | * @param CollectionItemModel $collection_item |
||
89 | */ |
||
90 | public function __construct(FileModel $file, ProductModel $product, |
||
103 | |||
104 | /** |
||
105 | * Creates all demo content |
||
106 | * @param integer $store_id |
||
107 | * @param \gplcart\modules\demo\models\Demo $model |
||
108 | * @return boolean |
||
109 | */ |
||
110 | public function create($store_id, \gplcart\modules\demo\models\Demo $model) |
||
128 | |||
129 | /** |
||
130 | * Creates collections |
||
131 | */ |
||
132 | protected function createCollections() |
||
139 | |||
140 | /** |
||
141 | * Creates files |
||
142 | */ |
||
143 | protected function createFiles() |
||
163 | |||
164 | /** |
||
165 | * Creates collection items |
||
166 | */ |
||
167 | protected function createCollectionItems() |
||
174 | |||
175 | /** |
||
176 | * Create category groups |
||
177 | */ |
||
178 | protected function createCategoryGroups() |
||
185 | |||
186 | /** |
||
187 | * Creates demo categories |
||
188 | */ |
||
189 | protected function createCategories() |
||
196 | |||
197 | /** |
||
198 | * Creates demo products |
||
199 | */ |
||
200 | protected function createProducts() |
||
207 | |||
208 | /** |
||
209 | * Creates product images |
||
210 | */ |
||
211 | protected function createProductImages() |
||
239 | |||
240 | /** |
||
241 | * Copy files from module to file directory |
||
242 | * @param string $source |
||
243 | * @param string $directory |
||
244 | * @return string |
||
245 | */ |
||
246 | protected function copyFile($source, $directory) |
||
254 | |||
255 | /** |
||
256 | * Deletes all created demo content |
||
257 | * @param integer $store_id |
||
258 | * @param \gplcart\modules\demo\models\Demo $model |
||
259 | */ |
||
260 | public function delete($store_id, $model) |
||
294 | |||
295 | } |
||
296 |