@@ -45,21 +45,48 @@ class Product extends CodeGeneratorCommand
4545 'nullable ' => true ,
4646 'default_value ' => null ,
4747 ],
48- 'name ' => [
49- 'col_name ' => 'name ' ,
48+ 'title ' => [
49+ 'col_name ' => 'title ' ,
5050 'php_type ' => 'string ' ,
5151 'mysql_type ' => 'VARCHAR ' ,
5252 'col_parameters ' => [255 ],
5353 'col_options ' => [],
5454 'nullable ' => true ,
5555 'default_value ' => null ,
5656 ],
57+ 'content ' => [
58+ 'col_name ' => 'content ' ,
59+ 'php_type ' => 'string ' ,
60+ 'mysql_type ' => 'TEXT ' ,
61+ 'col_parameters ' => null ,
62+ 'col_options ' => [],
63+ 'nullable ' => true ,
64+ 'default_value ' => null ,
65+ ],
5766 'tax_class_id ' => [
5867 'col_name ' => 'tax_class_id ' ,
5968 'php_type ' => 'int ' ,
6069 'mysql_type ' => 'INT ' ,
6170 'col_parameters ' => null ,
62- 'col_options ' => ['UNSIGNED ' ],
71+ 'col_options ' => ['\'UNSIGNED \'' ],
72+ 'nullable ' => true ,
73+ 'default_value ' => null ,
74+ ],
75+ 'website_id ' => [
76+ 'col_name ' => 'website_id ' ,
77+ 'php_type ' => 'int ' ,
78+ 'mysql_type ' => 'INT ' ,
79+ 'col_parameters ' => null ,
80+ 'col_options ' => ['\'UNSIGNED \'' ],
81+ 'nullable ' => true ,
82+ 'default_value ' => null ,
83+ ],
84+ 'user_id ' => [
85+ 'col_name ' => 'user_id ' ,
86+ 'php_type ' => 'int ' ,
87+ 'mysql_type ' => 'INT ' ,
88+ 'col_parameters ' => null ,
89+ 'col_options ' => ['\'UNSIGNED \'' ],
6390 'nullable ' => true ,
6491 'default_value ' => null ,
6592 ],
@@ -72,6 +99,51 @@ class Product extends CodeGeneratorCommand
7299 'nullable ' => true ,
73100 'default_value ' => null ,
74101 ],
102+ 'url ' => [
103+ 'col_name ' => 'url ' ,
104+ 'php_type ' => 'string ' ,
105+ 'mysql_type ' => 'VARCHAR ' ,
106+ 'col_parameters ' => [255 ],
107+ 'col_options ' => [],
108+ 'nullable ' => true ,
109+ 'default_value ' => null ,
110+ ],
111+ 'locale ' => [
112+ 'col_name ' => 'locale ' ,
113+ 'php_type ' => 'string ' ,
114+ 'mysql_type ' => 'VARCHAR ' ,
115+ 'col_parameters ' => [10 ],
116+ 'col_options ' => [],
117+ 'nullable ' => true ,
118+ 'default_value ' => null ,
119+ ],
120+ 'meta_keywords ' => [
121+ 'col_name ' => 'meta_keywords ' ,
122+ 'php_type ' => 'string ' ,
123+ 'mysql_type ' => 'VARCHAR ' ,
124+ 'col_parameters ' => [1024 ],
125+ 'col_options ' => [],
126+ 'nullable ' => true ,
127+ 'default_value ' => null ,
128+ ],
129+ 'meta_description ' => [
130+ 'col_name ' => 'meta_description ' ,
131+ 'php_type ' => 'string ' ,
132+ 'mysql_type ' => 'VARCHAR ' ,
133+ 'col_parameters ' => [1024 ],
134+ 'col_options ' => [],
135+ 'nullable ' => true ,
136+ 'default_value ' => null ,
137+ ],
138+ 'html_title ' => [
139+ 'col_name ' => 'html_title ' ,
140+ 'php_type ' => 'string ' ,
141+ 'mysql_type ' => 'VARCHAR ' ,
142+ 'col_parameters ' => [1024 ],
143+ 'col_options ' => [],
144+ 'nullable ' => true ,
145+ 'default_value ' => null ,
146+ ],
75147 ];
76148
77149 /**
@@ -220,7 +292,7 @@ protected function askColumnInfo(): ?array
220292 }
221293
222294 $ question = new Question ('Column options (comma separated): ' );
223- $ options = array_map ("strtoupper " , array_filter (array_map ("trim " , explode (", " , $ helper ->ask ($ this ->input , $ this ->output , $ question )))));
295+ $ options = array_map ("strtoupper " , array_filter (array_map ("trim " , explode (", " , ( string ) $ helper ->ask ($ this ->input , $ this ->output , $ question )))));
224296 foreach ($ options as $ k => $ option ) {
225297 if (!is_numeric ($ option ) && !empty ($ option ) && $ option != 'NULL ' ) {
226298 $ options [$ k ] = "' " . $ option . "' " ;
@@ -263,11 +335,11 @@ protected function getModelFileContents($className): string
263335
264336namespace App \\Site \\Models;
265337
266- use App \\Base \\Abstracts \\Models \\BaseModel ;
338+ use App \\Base \\Abstracts \\Models \\FrontendModel ;
267339use App\Base\Interfaces\Model\ProductInterface;
268340
269341/** \n" . $ comment . " */
270- class " . $ className . " extends BaseModel implements ProductInterface
342+ class " . $ className . " extends FrontendModel implements ProductInterface
271343{
272344 public function isPhysical(): bool
273345 {
@@ -291,12 +363,22 @@ public function getTaxClassId(): ?int
291363
292364 public function getName() : ?string
293365 {
294- return \$this->getData('name ');
366+ return \$this->getData('title ');
295367 }
296368
297369 public function getSku(): string
298370 {
299- return \$this->getData('sku')?? 'product_' . \$this->getId();
371+ return \$this->getData('sku')?? ' " .$ this ->getUtils ()->pascalCaseToSnakeCase ($ className )."_' . \$this->getId();
372+ }
373+
374+ /**
375+ * {@inheritdoc}
376+ *
377+ * @return string
378+ */
379+ public function getRewritePrefix(): string
380+ {
381+ return ' " .$ this ->getUtils ()->pascalCaseToSnakeCase ($ className )."';
300382 }
301383}
302384 " ;
@@ -338,7 +420,7 @@ protected function getMigrationFileContents($className, $modelClassName, $migrat
338420
339421class " . $ className . " extends DBMigration
340422{
341- protected \$tableName = ' " . $ migration_table . "';
423+ protected string \$tableName = ' " . $ migration_table . "';
342424
343425 public function getName(): string
344426 {
@@ -352,6 +434,9 @@ public function addDBTableDefinition(Table \$table): Table
352434 ->addColumn('created_at', 'TIMESTAMP', null, [], false, 'CURRENT_TIMESTAMP()')
353435 ->addColumn('updated_at', 'TIMESTAMP', null, [], false, 'CURRENT_TIMESTAMP()')
354436 ->addIndex(null, 'id', Index::TYPE_PRIMARY)
437+ ->addForeignKey('fk_ " .$ migration_table ."_website_id', ['website_id'], 'website', ['id'])
438+ ->addForeignKey('fk_ " .$ migration_table ."_owner_id', ['user_id'], 'user', ['id'])
439+ ->addForeignKey('fk_ " .$ migration_table ."_language_locale', ['locale'], 'language', ['locale'])
355440 ->setAutoIncrementColumn('id');
356441
357442 return \$table;
0 commit comments