Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
ClassModel Class Reference
Inheritance diagram for ClassModel:
AbstractExtensibleModel TaxClassInterface AbstractModel CustomAttributesDataInterface ExtensibleDataInterface DataObject ExtensibleDataInterface

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Tax\Model\TaxClass\Factory $classFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 _construct ()
 
 beforeDelete ()
 
 getClassId ()
 
 getClassName ()
 
 getClassType ()
 
 setClassId ($classId)
 
 setClassName ($className)
 
 setClassType ($classType)
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\Tax\Api\Data\TaxClassExtensionInterface $extensionAttributes)
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 

Data Fields

const KEY_ID = 'class_id'
 
const KEY_NAME = 'class_name'
 
const KEY_TYPE = 'class_type'
 
const TAX_CLASS_TYPE_CUSTOMER = 'CUSTOMER'
 
const TAX_CLASS_TYPE_PRODUCT = 'PRODUCT'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 

Protected Member Functions

 checkClassCanBeDeleted ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $_classFactory
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Additional Inherited Members

- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Tax class model

Definition at line 15 of file ClassModel.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Api\ExtensionAttributesFactory  $extensionFactory,
AttributeValueFactory  $customAttributeFactory,
\Magento\Tax\Model\TaxClass\Factory  $classFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Api\ExtensionAttributesFactory$extensionFactory
AttributeValueFactory$customAttributeFactory
TaxClass\Factory$classFactory
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data

Definition at line 51 of file ClassModel.php.

60  {
61  parent::__construct(
62  $context,
63  $registry,
64  $extensionFactory,
66  $resource,
67  $resourceCollection,
68  $data
69  );
70  $this->_classFactory = $classFactory;
71  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _construct()

_construct ( )
Returns
void

Definition at line 76 of file ClassModel.php.

77  {
78  $this->_init(\Magento\Tax\Model\ResourceModel\TaxClass::class);
79  }

◆ beforeDelete()

beforeDelete ( )

Validate tax class can be deleted

Returns
$this
Exceptions

Definition at line 122 of file ClassModel.php.

123  {
124  $this->checkClassCanBeDeleted();
125  return parent::beforeDelete();
126  }

◆ checkClassCanBeDeleted()

checkClassCanBeDeleted ( )
protected

Check whether this class can be deleted

Returns
bool
Exceptions
CouldNotDeleteException

Definition at line 87 of file ClassModel.php.

88  {
89  if (!$this->getId()) {
90  throw new CouldNotDeleteException(__('This class no longer exists.'));
91  }
92 
93  $typeModel = $this->_classFactory->create($this);
94 
95  if ($typeModel->getAssignedToRules()->getSize() > 0) {
96  throw new CouldNotDeleteException(
97  __(
98  'You cannot delete this tax class because it is used in Tax Rules.'
99  . ' You have to delete the rules it is used in first.'
100  )
101  );
102  }
103 
104  if ($typeModel->isAssignedToObjects()) {
105  throw new CouldNotDeleteException(
106  __(
107  'You cannot delete this tax class because it is used in existing %1(s).',
108  $typeModel->getObjectTypeName()
109  )
110  );
111  }
112 
113  return true;
114  }
__()
Definition: __.php:13

◆ getClassId()

getClassId ( )

@codeCoverageIgnoreStart {Get tax class ID.

Returns
int|null
}

Implements TaxClassInterface.

Definition at line 132 of file ClassModel.php.

133  {
134  return $this->getData(self::KEY_ID);
135  }

◆ getClassName()

getClassName ( )

{Get tax class name.

Returns
string
}

Implements TaxClassInterface.

Definition at line 140 of file ClassModel.php.

141  {
142  return $this->getData(self::KEY_NAME);
143  }

◆ getClassType()

getClassType ( )

{Get tax class type.

Returns
string
}

Implements TaxClassInterface.

Definition at line 148 of file ClassModel.php.

149  {
150  return $this->getData(self::KEY_TYPE);
151  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

{Retrieve existing extension attributes object or create a new one.

Returns
\Magento\Tax\Api\Data\TaxClassExtensionInterface|null
}

Returns
\Magento\Tax\Api\Data\TaxClassExtensionInterface|null

Implements TaxClassInterface.

Definition at line 193 of file ClassModel.php.

◆ setClassId()

setClassId (   $classId)

Set tax class ID.

Parameters
int$classId
Returns
$this

Implements TaxClassInterface.

Definition at line 159 of file ClassModel.php.

160  {
161  return $this->setData(self::KEY_ID, $classId);
162  }

◆ setClassName()

setClassName (   $className)

Set tax class name.

Parameters
string$className
Returns
$this

Implements TaxClassInterface.

Definition at line 170 of file ClassModel.php.

171  {
172  return $this->setData(self::KEY_NAME, $className);
173  }
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ setClassType()

setClassType (   $classType)

Set tax class type.

Parameters
string$classType
Returns
$this

Implements TaxClassInterface.

Definition at line 181 of file ClassModel.php.

182  {
183  return $this->setData(self::KEY_TYPE, $classType);
184  }

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Tax\Api\Data\TaxClassExtensionInterface  $extensionAttributes)

{Set an extension attributes object.

Parameters
\Magento\Tax\Api\Data\TaxClassExtensionInterface$extensionAttributes
Returns
$this
}

Parameters
\Magento\Tax\Api\Data\TaxClassExtensionInterface$extensionAttributes
Returns
$this

Implements TaxClassInterface.

Definition at line 204 of file ClassModel.php.

205  {
207  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

Field Documentation

◆ $_classFactory

$_classFactory
protected

Definition at line 39 of file ClassModel.php.

◆ KEY_ID

const KEY_ID = 'class_id'

#+ Constants defined for keys of array, makes typos less likely

Definition at line 21 of file ClassModel.php.

◆ KEY_NAME

const KEY_NAME = 'class_name'

Definition at line 22 of file ClassModel.php.

◆ KEY_TYPE

const KEY_TYPE = 'class_type'

Definition at line 23 of file ClassModel.php.

◆ TAX_CLASS_TYPE_CUSTOMER

const TAX_CLASS_TYPE_CUSTOMER = 'CUSTOMER'

#- Defines Customer Tax Class string

Definition at line 29 of file ClassModel.php.

◆ TAX_CLASS_TYPE_PRODUCT

const TAX_CLASS_TYPE_PRODUCT = 'PRODUCT'

Defines Product Tax Class string

Definition at line 34 of file ClassModel.php.


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