-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathAbstractAttribute.php
1463 lines (1324 loc) · 39.7 KB
/
AbstractAttribute.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Eav\Model\Entity\Attribute;
use Magento\Framework\Api\AttributeValueFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
use Magento\Framework\Serialize\Serializer\Json;
/**
* Entity/Attribute/Model - attribute abstract
* phpcs:disable Magento2.Classes.AbstractApi
* @api
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
* @since 100.0.2
*/
abstract class AbstractAttribute extends \Magento\Framework\Model\AbstractExtensibleModel implements
AttributeInterface,
\Magento\Eav\Api\Data\AttributeInterface,
ResetAfterRequestInterface
{
public const TYPE_STATIC = 'static';
/**
* Const for empty string value.
*/
public const EMPTY_STRING = '';
/**
* Attribute name
*
* @var string
*/
protected $_name;
/**
* Entity instance
*
* @var \Magento\Eav\Model\Entity\AbstractEntity
*/
protected $_entity;
/**
* Backend instance
*
* @var \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
*/
protected $_backend;
/**
* Frontend instance
*
* @var \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
*/
protected $_frontend;
/**
* Source instance
*
* @var \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
*/
protected $_source;
/**
* @var array
*/
protected $_attributeIdCache = [];
/**
* Attribute data table name
*
* @var string
*/
protected $_dataTable = null;
/**
* @var \Magento\Eav\Model\Config
*/
protected $_eavConfig;
/**
* @var \Magento\Eav\Model\Entity\TypeFactory
*/
protected $_eavTypeFactory;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
/**
* @var \Magento\Eav\Model\ResourceModel\Helper
*/
protected $_resourceHelper;
/**
* @var \Magento\Framework\Validator\UniversalFactory
*/
protected $_universalFactory;
/**
* @var \Magento\Eav\Api\Data\AttributeOptionInterfaceFactory
*/
protected $optionDataFactory;
/**
* @var \Magento\Framework\Reflection\DataObjectProcessor
*/
protected $dataObjectProcessor;
/**
* @var \Magento\Framework\Api\DataObjectHelper
*/
protected $dataObjectHelper;
/**
* @var FrontendLabelFactory
*/
private $frontendLabelFactory;
/**
* Serializer Instance.
*
* @var Json
* @since 101.0.0
*/
protected $serializer;
/**
* Array of attribute types that have empty string as a possible value.
*
* @var array
*/
private $emptyStringTypes = [
'int',
'decimal',
'datetime',
'varchar',
'text',
'static',
];
/**
* @var \Magento\Eav\Api\Data\AttributeExtensionFactory
*/
private $eavExtensionFactory;
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
* @param AttributeValueFactory $customAttributeFactory
* @param \Magento\Eav\Model\Config $eavConfig
* @param \Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper
* @param \Magento\Framework\Validator\UniversalFactory $universalFactory
* @param \Magento\Eav\Api\Data\AttributeOptionInterfaceFactory $optionDataFactory
* @param \Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param \Magento\Eav\Api\Data\AttributeExtensionFactory|null $eavExtensionFactory
* @param FrontendLabelFactory|null $frontendLabelFactory
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @codeCoverageIgnore
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
AttributeValueFactory $customAttributeFactory,
\Magento\Eav\Model\Config $eavConfig,
\Magento\Eav\Model\Entity\TypeFactory $eavTypeFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Eav\Model\ResourceModel\Helper $resourceHelper,
\Magento\Framework\Validator\UniversalFactory $universalFactory,
\Magento\Eav\Api\Data\AttributeOptionInterfaceFactory $optionDataFactory,
\Magento\Framework\Reflection\DataObjectProcessor $dataObjectProcessor,
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
?\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
?\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = [],
?\Magento\Eav\Api\Data\AttributeExtensionFactory $eavExtensionFactory = null,
?FrontendLabelFactory $frontendLabelFactory = null
) {
parent::__construct(
$context,
$registry,
$extensionFactory,
$customAttributeFactory,
$resource,
$resourceCollection,
$data
);
$this->_eavConfig = $eavConfig;
$this->_eavTypeFactory = $eavTypeFactory;
$this->_storeManager = $storeManager;
$this->_resourceHelper = $resourceHelper;
$this->_universalFactory = $universalFactory;
$this->optionDataFactory = $optionDataFactory;
$this->dataObjectProcessor = $dataObjectProcessor;
$this->dataObjectHelper = $dataObjectHelper;
$this->eavExtensionFactory = $eavExtensionFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Eav\Api\Data\AttributeExtensionFactory::class);
$this->frontendLabelFactory = $frontendLabelFactory
?: \Magento\Framework\App\ObjectManager::getInstance()->get(FrontendLabelFactory::class);
}
/**
* Get Serializer instance.
*
* @return Json
* @since 101.0.0
*/
protected function getSerializer()
{
if ($this->serializer === null) {
$this->serializer = \Magento\Framework\App\ObjectManager::getInstance()->create(Json::class);
}
return $this->serializer;
}
/**
* Initialize resource model
*
* @return void
* @codeCoverageIgnore
*/
protected function _construct()
{
$this->_init(\Magento\Eav\Model\ResourceModel\Entity\Attribute::class);
}
/**
* Load attribute data by code
*
* @param string|int|\Magento\Eav\Model\Entity\Type $entityType
* @param string $code
* @return $this
* @throws LocalizedException
*/
public function loadByCode($entityType, $code)
{
\Magento\Framework\Profiler::start('load_by_code');
if (is_numeric($entityType)) {
$entityTypeId = $entityType;
} elseif (is_string($entityType)) {
$entityType = $this->_eavTypeFactory->create()->loadByCode($entityType);
}
if ($entityType instanceof \Magento\Eav\Model\Entity\Type) {
$entityTypeId = $entityType->getId();
}
if (empty($entityTypeId)) {
throw new LocalizedException(__('The entity supplied is invalid. Verify the entity and try again.'));
}
$this->_getResource()->loadByCode($this, $entityTypeId, $code);
$this->_afterLoad();
\Magento\Framework\Profiler::stop('load_by_code');
return $this;
}
/**
* Get attribute name
*
* @return string
* @codeCoverageIgnore
*/
public function getName()
{
return $this->_getData('attribute_code');
}
/**
* Specify attribute identifier
*
* @param int $data
* @return $this
* @codeCoverageIgnore
*/
public function setAttributeId($data)
{
$this->_data['attribute_id'] = $data;
return $this;
}
/**
* @inheritdoc
* @codeCoverageIgnore
*/
public function getAttributeId()
{
return $this->_getData('attribute_id');
}
/**
* Set attribute code
*
* @param string $data
* @return $this
* @codeCoverageIgnore
*/
public function setAttributeCode($data)
{
return $this->setData('attribute_code', $data);
}
/**
* @inheritdoc
* @codeCoverageIgnore
*/
public function getAttributeCode()
{
return $this->_getData('attribute_code');
}
/**
* Set attribute model class.
*
* @param array $data
* @return $this
* @codeCoverageIgnore
*/
public function setAttributeModel($data)
{
return $this->setData('attribute_model', $data);
}
/**
* Returns attribute model
*
* @return array
* @codeCoverageIgnore
*/
public function getAttributeModel()
{
return $this->_getData('attribute_model');
}
/**
* Set backend type
*
* @param string $data
* @return $this
* @codeCoverageIgnore
*/
public function setBackendType($data)
{
return $this->setData('backend_type', $data);
}
/**
* @inheritdoc
* @codeCoverageIgnore
*/
public function getBackendType()
{
return $this->_getData('backend_type');
}
/**
* Set backend model
*
* @param string $data
* @return $this
* @codeCoverageIgnore
*/
public function setBackendModel($data)
{
return $this->setData('backend_model', $data);
}
/**
* @inheritdoc
* @codeCoverageIgnore
*/
public function getBackendModel()
{
return $this->_getData('backend_model');
}
/**
* Set backend table
*
* @param string $data
* @return $this
* @codeCoverageIgnore
*/
public function setBackendTable($data)
{
return $this->setData('backend_table', $data);
}
/**
* Returns is visible on front
*
* @return bool
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
* @codeCoverageIgnore
*/
public function getIsVisibleOnFront()
{
return $this->_getData('is_visible_on_front');
}
/**
* Returns default value
*
* @return string|null
* @codeCoverageIgnore
*/
public function getDefaultValue()
{
return $this->_getData('default_value');
}
/**
* Set default value for the element.
*
* @param string $defaultValue
* @return $this
* @codeCoverageIgnore
*/
public function setDefaultValue($defaultValue)
{
return $this->setData('default_value', $defaultValue);
}
/**
* Returns attribute set id
*
* @return int
* @codeCoverageIgnore
*/
public function getAttributeSetId()
{
return $this->_getData('attribute_set_id');
}
/**
* Set attribute set id
*
* @param int $id
* @return $this
* @codeCoverageIgnore
*/
public function setAttributeSetId($id)
{
$this->_data['attribute_set_id'] = $id;
return $this;
}
/**
* @inheritdoc
* @codeCoverageIgnore
*/
public function getEntityTypeId()
{
return $this->_getData('entity_type_id');
}
/**
* Set entity type id
*
* @param int|string $id
* @return $this
* @codeCoverageIgnore
*/
public function setEntityTypeId($id)
{
$this->_data['entity_type_id'] = $id;
return $this;
}
/**
* Set entity type
*
* @param string $type
* @return $this
* @codeCoverageIgnore
*/
public function setEntityType($type)
{
$this->setData('entity_type', $type);
return $this;
}
/**
* Get attribute alias as "entity_type/attribute_code"
*
* @param \Magento\Eav\Model\Entity\AbstractEntity $entity exclude this entity
* @return string
*/
public function getAlias($entity = null)
{
$alias = '';
if ($entity === null || $entity->getType() !== $this->getEntity()->getType()) {
$alias .= $this->getEntity()->getType() . '/';
}
$alias .= $this->getAttributeCode();
return $alias;
}
/**
* Set attribute name
*
* @param string $name
* @return $this
* @codeCoverageIgnore
*/
public function setName($name)
{
return $this->setData('attribute_code', $name);
}
/**
* Retrieve entity type
*
* @return \Magento\Eav\Model\Entity\Type
* @codeCoverageIgnore
*/
public function getEntityType()
{
return $this->_eavConfig->getEntityType($this->getEntityTypeId());
}
/**
* Set attribute entity instance
*
* @param \Magento\Eav\Model\Entity\AbstractEntity $entity
* @return $this
* @codeCoverageIgnore
*/
public function setEntity($entity)
{
$this->_entity = $entity;
return $this;
}
/**
* Retrieve entity instance
*
* @return \Magento\Eav\Model\Entity\AbstractEntity
*/
public function getEntity()
{
if (!$this->_entity) {
$this->_entity = $this->getEntityType()->getEntity();
}
return $this->_entity;
}
/**
* Retrieve entity type
*
* @return string
* @codeCoverageIgnore
*/
public function getEntityIdField()
{
return $this->getEntity()->getValueEntityIdField();
}
/**
* Retrieve backend instance
*
* @return \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend
* @throws LocalizedException
*/
public function getBackend()
{
if (empty($this->_backend)) {
if (!$this->getBackendModel()) {
$this->setBackendModel($this->_getDefaultBackendModel());
}
$backend = $this->_universalFactory->create($this->getBackendModel());
if (!$backend) {
throw new LocalizedException(
__(
'The "%1" backend model is invalid. Verify the backend model and try again.',
$this->getBackendModel()
)
);
}
$this->_backend = $backend->setAttribute($this);
}
return $this->_backend;
}
/**
* Retrieve frontend instance
*
* @return \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
*/
public function getFrontend()
{
if (empty($this->_frontend)) {
if (!$this->getFrontendModel()) {
$this->setFrontendModel($this->_getDefaultFrontendModel());
}
$this->_frontend = $this->_universalFactory->create($this->getFrontendModel())->setAttribute($this);
}
return $this->_frontend;
}
/**
* Retrieve source instance
*
* @return \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
* @throws LocalizedException
*/
public function getSource()
{
if (empty($this->_source)) {
if (!$this->getSourceModel()) {
$this->_source = $this->_getDefaultSourceModel();
} else {
$this->_source = $this->getSourceModel();
}
$source = $this->_universalFactory->create($this->_source);
if (!$source) {
throw new LocalizedException(
__(
'Source model "%1" not found for attribute "%2"',
$this->getSourceModel(),
$this->getAttributeCode()
)
);
}
$this->_source = $source->setAttribute($this);
}
return $this->_source;
}
/**
* Whether possible attribute values are retrieved from finite source
*
* @return bool
*/
public function usesSource()
{
$input = $this->getFrontendInput();
return $input === 'select' || $input === 'multiselect' || $this->_getData('source_model') != '';
}
/**
* Returns default backend model
*
* @return string
* @codeCoverageIgnore
*/
protected function _getDefaultBackendModel()
{
return \Magento\Eav\Model\Entity::DEFAULT_BACKEND_MODEL;
}
/**
* Returns default frontend model
*
* @return string
* @codeCoverageIgnore
*/
protected function _getDefaultFrontendModel()
{
return \Magento\Eav\Model\Entity::DEFAULT_FRONTEND_MODEL;
}
/**
* Returns default source model
*
* @return string
* @codeCoverageIgnore
*/
protected function _getDefaultSourceModel()
{
return $this->getEntityType()->getEntity()->getDefaultAttributeSourceModel();
}
/**
* Check if Value is empty.
*
* @param array|null|bool|int|float|string $value
* @return bool
*/
public function isValueEmpty($value)
{
return (is_array($value) && count($value) == 0)
|| $value === null
|| ($value === false && $this->getBackend()->getType() != 'int')
|| ($value === self::EMPTY_STRING && $this->isInEmptyStringTypes());
}
/**
* Check if attribute empty value is valid.
*
* @param array|null|bool|int|float|string $value
* @return bool
* @since 100.1.6
*/
public function isAllowedEmptyTextValue($value)
{
return $this->isInEmptyStringTypes() && $value === self::EMPTY_STRING;
}
/**
* Check is attribute type in allowed empty string types.
*
* @return bool
*/
private function isInEmptyStringTypes()
{
return in_array($this->getBackend()->getType(), $this->emptyStringTypes);
}
/**
* Check if attribute in specified set
*
* @param int|int[] $setId
* @return bool
*/
public function isInSet($setId)
{
if (!$this->hasAttributeSetInfo()) {
return true;
}
if (is_array($setId) && count(array_intersect($setId, array_keys($this->getAttributeSetInfo())))) {
return true;
}
if (!is_array($setId) && array_key_exists($setId, $this->getAttributeSetInfo())) {
return true;
}
return false;
}
/**
* Check if attribute in specified group
*
* @param int $setId
* @param int $groupId
* @return bool
*/
public function isInGroup($setId, $groupId)
{
$dataPath = sprintf('attribute_set_info/%s/group_id', $setId);
if ($this->isInSet($setId) && $this->getData($dataPath) == $groupId) {
return true;
}
return false;
}
/**
* Return attribute id
*
* @param string $entityType
* @param string $code
* @return int
*/
public function getIdByCode($entityType, $code)
{
$cacheKey = "{$entityType}|{$code}";
if (!isset($this->_attributeIdCache[$cacheKey])) {
$this->_attributeIdCache[$cacheKey] = $this->getResource()->getIdByCode($entityType, $code);
}
return $this->_attributeIdCache[$cacheKey];
}
/**
* Check if attribute is static
*
* @return bool
*/
public function isStatic()
{
return $this->getBackendType() == self::TYPE_STATIC || $this->getBackendType() == '';
}
/**
* Get attribute backend table name
*
* @return string
*/
public function getBackendTable()
{
if ($this->_dataTable === null) {
if ($this->isStatic()) {
$this->_dataTable = $this->getEntityType()->getValueTablePrefix();
} else {
$backendTable = trim((string)$this->_getData('backend_table'));
if (empty($backendTable)) {
$entityTable = [$this->getEntityType()->getEntityTablePrefix(), $this->getBackendType()];
$backendTable = $this->getResource()->getTable($entityTable);
}
$this->_dataTable = $backendTable;
}
}
return $this->_dataTable;
}
/**
* Retrieve flat columns definition
*
* @return array
*/
public function getFlatColumns()
{
// If source model exists - get definition from it
if ($this->usesSource() && $this->getBackendType() != self::TYPE_STATIC) {
return $this->getSource()->getFlatColumns();
}
return $this->_getFlatColumnsDdlDefinition();
}
/**
* Retrieve flat columns DDL definition
*
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function _getFlatColumnsDdlDefinition()
{
$columns = [];
switch ($this->getBackendType()) {
case 'static':
$describe = $this->_getResource()->describeTable($this->getBackend()->getTable());
if (!isset($describe[$this->getAttributeCode()])) {
break;
}
$prop = $describe[$this->getAttributeCode()];
$type = $prop['DATA_TYPE'];
$size = $prop['LENGTH'] ? $prop['LENGTH'] : null;
$columns[$this->getAttributeCode()] = [
'type' => $this->_resourceHelper->getDdlTypeByColumnType($type),
'length' => $size,
'unsigned' => $prop['UNSIGNED'] ? true : false,
'nullable' => $prop['NULLABLE'],
'default' => $prop['DEFAULT'],
'extra' => null,
];
break;
case 'datetime':
$columns[$this->getAttributeCode()] = [
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DATETIME,
'unsigned' => false,
'nullable' => true,
'default' => null,
'extra' => null,
];
break;
case 'decimal':
$columns[$this->getAttributeCode()] = [
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_DECIMAL,
'length' => '12,4',
'unsigned' => false,
'nullable' => true,
'default' => null,
'extra' => null,
];
break;
case 'int':
$columns[$this->getAttributeCode()] = [
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
'unsigned' => false,
'nullable' => true,
'default' => null,
'extra' => null,
];
break;
case 'text':
$columns[$this->getAttributeCode()] = [
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'unsigned' => false,
'nullable' => true,
'default' => null,
'extra' => null,
'length' => \Magento\Framework\DB\Ddl\Table::MAX_TEXT_SIZE,
];
break;
case 'varchar':
$columns[$this->getAttributeCode()] = [
'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
'length' => '255',
'unsigned' => false,
'nullable' => true,
'default' => null,
'extra' => null,
];
break;
default:
break;
}
return $columns;
}
/**
* Retrieve flat columns definition in old format (before MMDB support)
*
* Used in database compatible mode
*
* @deprecated 101.0.0
* @see MMDB
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _getFlatColumnsOldDefinition()
{
$columns = [];
switch ($this->getBackendType()) {
case 'static':
$describe = $this->_getResource()->describeTable($this->getBackend()->getTable());
if (!isset($describe[$this->getAttributeCode()])) {
break;
}
$prop = $describe[$this->getAttributeCode()];
$columns[$this->getAttributeCode()] = [
'type' => $prop['DATA_TYPE'] . ($prop['LENGTH'] ? "({$prop['LENGTH']})" : ""),
'unsigned' => $prop['UNSIGNED'] ? true : false,
'is_null' => $prop['NULLABLE'],
'default' => $prop['DEFAULT'],
'extra' => null,
];
break;
case 'datetime':
$columns[$this->getAttributeCode()] = [
'type' => 'datetime',
'unsigned' => false,
'is_null' => true,
'default' => null,
'extra' => null,
];
break;
case 'decimal':
$columns[$this->getAttributeCode()] = [
'type' => 'decimal(12,4)',
'unsigned' => false,
'is_null' => true,
'default' => null,
'extra' => null,
];
break;
case 'int':
$columns[$this->getAttributeCode()] = [
'type' => 'int',
'unsigned' => false,
'is_null' => true,
'default' => null,
'extra' => null,
];
break;
case 'text':
$columns[$this->getAttributeCode()] = [
'type' => 'text',
'unsigned' => false,
'is_null' => true,
'default' => null,
'extra' => null,
];
break;
case 'varchar':
$columns[$this->getAttributeCode()] = [
'type' => 'varchar(255)',
'unsigned' => false,
'is_null' => true,
'default' => null,
'extra' => null,
];
break;
default:
break;
}