Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
SalesSetup Class Reference
Inheritance diagram for SalesSetup:
EavSetup

Public Member Functions

 __construct (ModuleDataSetupInterface $setup, Context $context, CacheInterface $cache, CollectionFactory $attrGroupCollectionFactory, ScopeConfigInterface $config)
 
 addAttribute ($entityTypeId, $code, array $attr)
 
 getDefaultEntities ()
 
 getConfigModel ()
 
 getEncryptor ()
 
 getConnection ()
 
 getTable ($table)
 
 updateEntityTypes ()
 
- Public Member Functions inherited from EavSetup
 __construct (ModuleDataSetupInterface $setup, Context $context, CacheInterface $cache, CollectionFactory $attrGroupCollectionFactory)
 
 getSetup ()
 
 getAttributeGroupCollectionFactory ()
 
 cleanCache ()
 
 installDefaultGroupIds ()
 
 addEntityType ($code, array $params)
 
 updateEntityType ($code, $field, $value=null)
 
 getEntityType ($id, $field=null)
 
 getEntityTypeId ($entityTypeId)
 
 removeEntityType ($id)
 
 getAttributeSetSortOrder ($entityTypeId, $sortOrder=null)
 
 addAttributeSet ($entityTypeId, $name, $sortOrder=null, $setId=null)
 
 updateAttributeSet ($entityTypeId, $id, $field, $value=null)
 
 getAttributeSet ($entityTypeId, $id, $field=null)
 
 getAttributeSetId ($entityTypeId, $setId)
 
 removeAttributeSet ($entityTypeId, $id)
 
 setDefaultSetToEntityType ($entityType, $attributeSet='Default')
 
 getAllAttributeSetIds ($entityTypeId=null)
 
 getDefaultAttributeSetId ($entityType)
 
 getAttributeGroupSortOrder ($entityTypeId, $setId, $sortOrder=null)
 
 addAttributeGroup ($entityTypeId, $setId, $name, $sortOrder=null)
 
 convertToAttributeGroupCode ($groupName)
 
 updateAttributeGroup ($entityTypeId, $setId, $id, $field, $value=null)
 
 getAttributeGroup ($entityTypeId, $setId, $id, $field=null)
 
 getAttributeGroupByCode ($entityTypeId, $setId, $code, $field=null)
 
 getAttributeGroupId ($entityTypeId, $setId, $groupId)
 
 removeAttributeGroup ($entityTypeId, $setId, $id)
 
 getDefaultAttributeGroupId ($entityType, $attributeSetId=null)
 
 getAttributesNumberInGroup ($entityTypeId, $setId, $groupId)
 
 addAttribute ($entityTypeId, $code, array $attr)
 
 addAttributeOption ($option)
 
 updateAttribute ($entityTypeId, $id, $field, $value=null, $sortOrder=null)
 
 getAttribute ($entityTypeId, $id, $field=null)
 
 getAttributeId ($entityTypeId, $id)
 
 getAttributeTable ($entityTypeId, $id)
 
 removeAttribute ($entityTypeId, $code)
 
 getAttributeSortOrder ($entityTypeId, $setId, $groupId, $sortOrder=null)
 
 addAttributeToSet ($entityTypeId, $setId, $groupId, $attributeId, $sortOrder=null)
 
 addAttributeToGroup ($entityType, $setId, $groupId, $attributeId, $sortOrder=null)
 
 getDefaultEntities ()
 
 installEntities ($entities=null)
 

Data Fields

const ORDER_ENTITY_TYPE_ID = 5
 
const INVOICE_PRODUCT_ENTITY_TYPE_ID = 6
 
const CREDITMEMO_PRODUCT_ENTITY_TYPE_ID = 7
 
const SHIPMENT_PRODUCT_ENTITY_TYPE_ID = 8
 

Protected Member Functions

 _flatTableExist ($table)
 
 _addFlatAttribute ($table, $attribute, $attr)
 
 _addGridAttribute ($table, $attribute, $attr, $entityTypeId)
 
 _getAttributeColumnDefinition ($code, $data)
 

Protected Attributes

 $config
 
 $encryptor
 
 $_flatEntityTables
 
 $_flatEntitiesGrid = ['order', 'invoice', 'shipment', 'creditmemo']
 

Detailed Description

Sales module setup class

@SuppressWarnings(PHPMD.CouplingBetweenObjects) @codeCoverageIgnore

Definition at line 23 of file SalesSetup.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( ModuleDataSetupInterface  $setup,
Context  $context,
CacheInterface  $cache,
CollectionFactory  $attrGroupCollectionFactory,
ScopeConfigInterface  $config 
)

Constructor

Parameters
ModuleDataSetupInterface$setup
Context$context
CacheInterface$cache
CollectionFactory$attrGroupCollectionFactory
ScopeConfigInterface$config

Definition at line 69 of file SalesSetup.php.

75  {
76  $this->config = $config;
77  $this->encryptor = $context->getEncryptor();
78  parent::__construct($setup, $context, $cache, $attrGroupCollectionFactory);
79  }
$setup
Definition: trigger.php:12

Member Function Documentation

◆ _addFlatAttribute()

_addFlatAttribute (   $table,
  $attribute,
  $attr 
)
protected

Add attribute as separate column in the table

Parameters
string$table
string$attribute
array$attr
Returns
$this

Definition at line 159 of file SalesSetup.php.

160  {
161  $tableInfo = $this->getConnection()
162  ->describeTable($this->getTable($table));
163  if (isset($tableInfo[$attribute])) {
164  return $this;
165  }
166  $columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr);
167  $this->getConnection()->addColumn(
168  $this->getTable($table),
169  $attribute,
170  $columnDefinition
171  );
172  return $this;
173  }
$attr
Definition: text.phtml:8
_getAttributeColumnDefinition($code, $data)
Definition: SalesSetup.php:206
$table
Definition: trigger.php:14

◆ _addGridAttribute()

_addGridAttribute (   $table,
  $attribute,
  $attr,
  $entityTypeId 
)
protected

Add attribute to grid table if necessary

Parameters
string$table
string$attribute
array$attr
string$entityTypeId
Returns
$this

Definition at line 184 of file SalesSetup.php.

185  {
186  if (in_array($entityTypeId, $this->_flatEntitiesGrid) && !empty($attr['grid'])) {
187  $columnDefinition = $this->_getAttributeColumnDefinition($attribute, $attr);
188  $this->getConnection()->addColumn(
189  $this->getTable($table . '_grid'),
190  $attribute,
191  $columnDefinition
192  );
193  }
194  return $this;
195  }
$attr
Definition: text.phtml:8
_getAttributeColumnDefinition($code, $data)
Definition: SalesSetup.php:206
$table
Definition: trigger.php:14

◆ _flatTableExist()

_flatTableExist (   $table)
protected

Check if table exist for flat entity

Parameters
string$table
Returns
bool

Definition at line 117 of file SalesSetup.php.

118  {
119  $tablesList = $this->getConnection()
120  ->listTables();
121  return in_array(
122  strtoupper($this->getTable($table)),
123  array_map('strtoupper', $tablesList)
124  );
125  }
$table
Definition: trigger.php:14

◆ _getAttributeColumnDefinition()

_getAttributeColumnDefinition (   $code,
  $data 
)
protected

Retrieve definition of column for create in flat table

Parameters
string$code
array$data
Returns
array @SuppressWarnings(PHPMD.CyclomaticComplexity) @SuppressWarnings(PHPMD.NPathComplexity)

Definition at line 206 of file SalesSetup.php.

207  {
208  // Convert attribute type to column info
209  $data['type'] = isset($data['type']) ? $data['type'] : 'varchar';
210  $type = null;
211  $length = null;
212  switch ($data['type']) {
213  case 'timestamp':
215  break;
216  case 'datetime':
218  break;
219  case 'decimal':
221  $length = '12,4';
222  break;
223  case 'int':
225  break;
226  case 'text':
228  $length = 65536;
229  break;
230  case 'char':
231  case 'varchar':
233  $length = 255;
234  break;
235  }
236  if ($type !== null) {
237  $data['type'] = $type;
238  $data['length'] = $length;
239  }
240 
241  $data['nullable'] = isset($data['required']) ? !$data['required'] : true;
242  $data['comment'] = isset($data['comment']) ? $data['comment'] : ucwords(str_replace('_', ' ', $code));
243  return $data;
244  }
$type
Definition: item.phtml:13
$code
Definition: info.phtml:12

◆ addAttribute()

addAttribute (   $entityTypeId,
  $code,
array  $attr 
)

Add entity attribute. Overwritten for flat entities support

Parameters
int | string$entityTypeId
string$code
array$attr
Returns
$this

Definition at line 135 of file SalesSetup.php.

136  {
137  if (isset(
138  $this->_flatEntityTables[$entityTypeId]
139  ) && $this->_flatTableExist(
140  $this->_flatEntityTables[$entityTypeId]
141  )
142  ) {
143  $this->_addFlatAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr);
144  $this->_addGridAttribute($this->_flatEntityTables[$entityTypeId], $code, $attr, $entityTypeId);
145  } else {
146  parent::addAttribute($entityTypeId, $code, $attr);
147  }
148  return $this;
149  }
$attr
Definition: text.phtml:8
_addFlatAttribute($table, $attribute, $attr)
Definition: SalesSetup.php:159
_addGridAttribute($table, $attribute, $attr, $entityTypeId)
Definition: SalesSetup.php:184
$code
Definition: info.phtml:12

◆ getConfigModel()

getConfigModel ( )

Get config model

Returns
ScopeConfigInterface

Definition at line 293 of file SalesSetup.php.

294  {
295  return $this->config;
296  }

◆ getConnection()

getConnection ( )
Returns
\Magento\Framework\DB\Adapter\AdapterInterface

Definition at line 309 of file SalesSetup.php.

310  {
311  return $this->getSetup()->getConnection(self::$connectionName);
312  }

◆ getDefaultEntities()

getDefaultEntities ( )
Returns
array

Definition at line 249 of file SalesSetup.php.

250  {
251  $entities = [
252  'order' => [
253  'entity_type_id' => self::ORDER_ENTITY_TYPE_ID,
254  'entity_model' => \Magento\Sales\Model\ResourceModel\Order::class,
255  'table' => 'sales_order',
256  'increment_model' => \Magento\Eav\Model\Entity\Increment\NumericValue::class,
257  'increment_per_store' => true,
258  'attributes' => [],
259  ],
260  'invoice' => [
261  'entity_type_id' => self::INVOICE_PRODUCT_ENTITY_TYPE_ID,
262  'entity_model' => \Magento\Sales\Model\ResourceModel\Order\Invoice::class,
263  'table' => 'sales_invoice',
264  'increment_model' => \Magento\Eav\Model\Entity\Increment\NumericValue::class,
265  'increment_per_store' => true,
266  'attributes' => [],
267  ],
268  'creditmemo' => [
269  'entity_type_id' => self::CREDITMEMO_PRODUCT_ENTITY_TYPE_ID,
270  'entity_model' => \Magento\Sales\Model\ResourceModel\Order\Creditmemo::class,
271  'table' => 'sales_creditmemo',
272  'increment_model' => \Magento\Eav\Model\Entity\Increment\NumericValue::class,
273  'increment_per_store' => true,
274  'attributes' => [],
275  ],
276  'shipment' => [
277  'entity_type_id' => self::SHIPMENT_PRODUCT_ENTITY_TYPE_ID,
278  'entity_model' => \Magento\Sales\Model\ResourceModel\Order\Shipment::class,
279  'table' => 'sales_shipment',
280  'increment_model' => \Magento\Eav\Model\Entity\Increment\NumericValue::class,
281  'increment_per_store' => true,
282  'attributes' => [],
283  ],
284  ];
285  return $entities;
286  }

◆ getEncryptor()

getEncryptor ( )
Returns
EncryptorInterface

Definition at line 301 of file SalesSetup.php.

302  {
303  return $this->encryptor;
304  }

◆ getTable()

getTable (   $table)

Get table name

Parameters
string$table
Returns
string

Definition at line 320 of file SalesSetup.php.

321  {
322  return $this->getSetup()->getTable($table, self::$connectionName);
323  }
$table
Definition: trigger.php:14

◆ updateEntityTypes()

updateEntityTypes ( )

Update entity types

Returns
void

Definition at line 330 of file SalesSetup.php.

331  {
332  $this->updateEntityType(
333  \Magento\Sales\Model\Order::ENTITY,
334  'entity_model',
335  \Magento\Sales\Model\ResourceModel\Order::class
336  );
337  $this->updateEntityType(
338  \Magento\Sales\Model\Order::ENTITY,
339  'increment_model',
340  \Magento\Eav\Model\Entity\Increment\NumericValue::class
341  );
342  $this->updateEntityType(
343  'invoice',
344  'entity_model',
345  \Magento\Sales\Model\ResourceModel\Order::class
346  );
347  $this->updateEntityType(
348  'invoice',
349  'increment_model',
350  \Magento\Eav\Model\Entity\Increment\NumericValue::class
351  );
352  $this->updateEntityType(
353  'creditmemo',
354  'entity_model',
355  \Magento\Sales\Model\ResourceModel\Order\Creditmemo::class
356  );
357  $this->updateEntityType(
358  'creditmemo',
359  'increment_model',
360  \Magento\Eav\Model\Entity\Increment\NumericValue::class
361  );
362  $this->updateEntityType(
363  'shipment',
364  'entity_model',
365  \Magento\Sales\Model\ResourceModel\Order\Shipment::class
366  );
367  $this->updateEntityType(
368  'shipment',
369  'increment_model',
370  \Magento\Eav\Model\Entity\Increment\NumericValue::class
371  );
372  }
updateEntityType($code, $field, $value=null)
Definition: EavSetup.php:231

Field Documentation

◆ $_flatEntitiesGrid

$_flatEntitiesGrid = ['order', 'invoice', 'shipment', 'creditmemo']
protected

Definition at line 109 of file SalesSetup.php.

◆ $_flatEntityTables

$_flatEntityTables
protected
Initial value:
= [
'order' => 'sales_order',
'order_payment' => 'sales_order_payment',
'order_item' => 'sales_order_item',
'order_address' => 'sales_order_address',
'order_status_history' => 'sales_order_status_history',
'invoice' => 'sales_invoice',
'invoice_item' => 'sales_invoice_item',
'invoice_comment' => 'sales_invoice_comment',
'creditmemo' => 'sales_creditmemo',
'creditmemo_item' => 'sales_creditmemo_item',
'creditmemo_comment' => 'sales_creditmemo_comment',
'shipment' => 'sales_shipment',
'shipment_item' => 'sales_shipment_item',
'shipment_track' => 'sales_shipment_track',
'shipment_comment' => 'sales_shipment_comment',
]

Definition at line 86 of file SalesSetup.php.

◆ $config

$config
protected

Definition at line 48 of file SalesSetup.php.

◆ $encryptor

$encryptor
protected

Definition at line 53 of file SalesSetup.php.

◆ CREDITMEMO_PRODUCT_ENTITY_TYPE_ID

const CREDITMEMO_PRODUCT_ENTITY_TYPE_ID = 7

This should be set explicitly

Definition at line 38 of file SalesSetup.php.

◆ INVOICE_PRODUCT_ENTITY_TYPE_ID

const INVOICE_PRODUCT_ENTITY_TYPE_ID = 6

This should be set explicitly

Definition at line 33 of file SalesSetup.php.

◆ ORDER_ENTITY_TYPE_ID

const ORDER_ENTITY_TYPE_ID = 5

This should be set explicitly

Definition at line 28 of file SalesSetup.php.

◆ SHIPMENT_PRODUCT_ENTITY_TYPE_ID

const SHIPMENT_PRODUCT_ENTITY_TYPE_ID = 8

This should be set explicitly

Definition at line 43 of file SalesSetup.php.


The documentation for this class was generated from the following file: