@@ -146,6 +146,48 @@ class Product extends CodeGeneratorCommand
146146 ],
147147 ];
148148
149+ protected $ physical_columns = [
150+ 'weight ' => [
151+ 'col_name ' => 'weight ' ,
152+ 'php_type ' => 'float ' ,
153+ 'mysql_type ' => 'FLOAT ' ,
154+ 'col_parameters ' => null ,
155+ 'col_options ' => [],
156+ 'nullable ' => true ,
157+ 'default_value ' => null ,
158+ ],
159+ 'length ' => [
160+ 'col_name ' => 'length ' ,
161+ 'php_type ' => 'float ' ,
162+ 'mysql_type ' => 'FLOAT ' ,
163+ 'col_parameters ' => null ,
164+ 'col_options ' => [],
165+ 'nullable ' => true ,
166+ 'default_value ' => null ,
167+ ],
168+ 'width ' => [
169+ 'col_name ' => 'width ' ,
170+ 'php_type ' => 'float ' ,
171+ 'mysql_type ' => 'FLOAT ' ,
172+ 'col_parameters ' => null ,
173+ 'col_options ' => [],
174+ 'nullable ' => true ,
175+ 'default_value ' => null ,
176+ ],
177+ 'height ' => [
178+ 'col_name ' => 'height ' ,
179+ 'php_type ' => 'float ' ,
180+ 'mysql_type ' => 'FLOAT ' ,
181+ 'col_parameters ' => null ,
182+ 'col_options ' => [],
183+ 'nullable ' => true ,
184+ 'default_value ' => null ,
185+ ],
186+ ];
187+
188+ protected $ interface = 'App\Base\Interfaces\Model\ProductInterface ' ;
189+ protected $ traits = ['App\Base\Traits\ProductTrait ' ];
190+
149191 /**
150192 * {@inheritdoc}
151193 */
@@ -186,6 +228,13 @@ protected function execute(InputInterface $input, OutputInterface $output) : int
186228 $ migration_order = 100 + $ last_migration_id ;
187229 }
188230
231+ $ isPhysical = $ this ->confirmMessage ('Is a physical product? ' , 'Creating a virtual product ' );
232+ if ($ isPhysical ) {
233+ $ this ->columns = array_merge ($ this ->columns , $ this ->physical_columns );
234+ $ this ->interface = 'App\Base\Interfaces\Model\PhysicalProductInterface ' ;
235+ $ this ->traits [] = 'App\Base\Traits\PhysicalProductTrait ' ;
236+ }
237+
189238 do {
190239 $ column_info = $ this ->askColumnInfo ();
191240 if ($ column_info ) {
@@ -336,36 +385,22 @@ protected function getModelFileContents($className): string
336385namespace App \\Site \\Models;
337386
338387use App \\Base \\Abstracts \\Models \\FrontendModel;
339- use App\Base\Interfaces\Model\ProductInterface;
388+ use " .str_replace ('\\' ,'\\\\' , $ this ->interface ).";
389+ use " .implode ("; \nuse " , $ this ->traits ).";
390+ use App\Base\GraphQl\GraphQLExport;
340391
341392/** \n" . $ comment . " */
342- class " . $ className . " extends FrontendModel implements ProductInterface
393+ #[GraphQLExport]
394+ class " . $ className . " extends FrontendModel implements " .$ this ->getUtils ()->getClassBasename ($ this ->interface )."
343395{
344- public function isPhysical(): bool
345- {
346- return true;
347- }
348-
349- public function getId(): int
350- {
351- return \$this->getData('id');
352- }
353-
354- public function getPrice(): float
355- {
356- return \$this->getData('price') ?? 0.0;
357- }
358-
359- public function getTaxClassId(): ?int
360- {
361- return \$this->getData('tax_class_id');
362- }
363-
364- public function getName() : ?string
365- {
366- return \$this->getData('title');
367- }
396+ use " .implode ("; \n use " , array_map (fn ($ t ) => $ this ->getUtils ()->getClassBasename ($ t ), $ this ->traits )).";
368397
398+ /**
399+ * {@inheritdoc}
400+ *
401+ * @return string
402+ */
403+ #[GraphQLExport]
369404 public function getSku(): string
370405 {
371406 return \$this->getData('sku')?? ' " .$ this ->getUtils ()->pascalCaseToSnakeCase ($ className )."_' . \$this->getId();
0 commit comments