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

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 afterSave ()
 
 getUrl ()
 
 getBaseTmpPath ()
 
 getBasePath ()
 
 getSearchableData ($productId, $storeId)
 
 getTitle ()
 
 getSortOrder ()
 
 getSampleType ()
 
 getSampleFile ()
 
 getSampleFileContent ()
 
 getSampleUrl ()
 
 setTitle ($title)
 
 setSortOrder ($sortOrder)
 
 setSampleType ($sampleType)
 
 setSampleFile ($sampleFile)
 
 setSampleFileContent (\Magento\Downloadable\Api\Data\File\ContentInterface $sampleFileContent=null)
 
 setSampleUrl ($sampleUrl)
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\Downloadable\Api\Data\SampleExtensionInterface $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)
 
- Public Member Functions inherited from SampleInterface
 getId ()
 
 setId ($id)
 
 setSampleFileContent (ContentInterface $sampleFileContent=null)
 

Data Fields

const XML_PATH_SAMPLES_TITLE = 'catalog/downloadable/samples_title'
 
const KEY_TITLE = 'title'
 
const KEY_SORT_ORDER = 'sort_order'
 
const KEY_SAMPLE_TYPE = 'sample_type'
 
const KEY_SAMPLE_FILE = 'sample_file'
 
const KEY_SAMPLE_FILE_CONTENT = 'sample_file_content'
 
const KEY_SAMPLE_URL = 'sample_url'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 

Protected Member Functions

 _construct ()
 
- 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)
 

Additional Inherited Members

- 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 = []
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

Downloadable sample model

@method int getProductId()

@api

Since
100.0.2

Definition at line 18 of file Sample.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Api\ExtensionAttributesFactory  $extensionFactory,
\Magento\Framework\Api\AttributeValueFactory  $customAttributeFactory,
\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
\Magento\Framework\Api\AttributeValueFactory$customAttributeFactory
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data

Definition at line 42 of file Sample.php.

50  {
51  parent::__construct(
52  $context,
53  $registry,
54  $extensionFactory,
56  $resource,
57  $resourceCollection,
58  $data
59  );
60  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _construct()

_construct ( )
protected

Initialize resource

Returns
void

Definition at line 67 of file Sample.php.

68  {
69  $this->_init(\Magento\Downloadable\Model\ResourceModel\Sample::class);
70  parent::_construct();
71  }

◆ afterSave()

afterSave ( )

After save process

Returns
$this

Definition at line 78 of file Sample.php.

79  {
80  $this->getResource()->saveItemTitle($this);
81  return parent::afterSave();
82  }

◆ getBasePath()

getBasePath ( )

Retrieve sample files path

Returns
string

Implements ComponentInterface.

Definition at line 113 of file Sample.php.

114  {
115  return 'downloadable/files/samples';
116  }

◆ getBaseTmpPath()

getBaseTmpPath ( )

Retrieve base tmp path

Returns
string

Implements ComponentInterface.

Definition at line 103 of file Sample.php.

104  {
105  return 'downloadable/tmp/samples';
106  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

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

Returns
\Magento\Downloadable\Api\Data\SampleExtensionInterface|null
}

Returns
\Magento\Downloadable\Api\Data\SampleExtensionInterface|null

Implements SampleInterface.

Definition at line 253 of file Sample.php.

◆ getSampleFile()

getSampleFile ( )

{Return file path or null when type is 'url'

Returns
string|null relative file path
} @codeCoverageIgnore

Implements SampleInterface.

Definition at line 161 of file Sample.php.

162  {
163  return $this->getData(self::KEY_SAMPLE_FILE);
164  }

◆ getSampleFileContent()

getSampleFileContent ( )

{Retrieve sample file content

Returns
\Magento\Downloadable\Api\Data\File\ContentInterface|null
} @codeCoverageIgnore

Implements SampleInterface.

Definition at line 170 of file Sample.php.

171  {
172  return $this->getData(self::KEY_SAMPLE_FILE_CONTENT);
173  }

◆ getSampleType()

getSampleType ( )

{

Returns
string
} @codeCoverageIgnore

Implements SampleInterface.

Definition at line 152 of file Sample.php.

153  {
154  return $this->getData(self::KEY_SAMPLE_TYPE);
155  }

◆ getSampleUrl()

getSampleUrl ( )

{Return URL or NULL when type is 'file'

Returns
string|null file URL
} @codeCoverageIgnore

Implements SampleInterface.

Definition at line 179 of file Sample.php.

180  {
181  return $this->getData(self::KEY_SAMPLE_URL);
182  }

◆ getSearchableData()

getSearchableData (   $productId,
  $storeId 
)

Retrieve links searchable data

Parameters
int$productId
int$storeId
Returns
array

Implements ComponentInterface.

Definition at line 125 of file Sample.php.

126  {
127  return $this->_getResource()->getSearchableData($productId, $storeId);
128  }

◆ getSortOrder()

getSortOrder ( )

{Sort order index for sample

Returns
int
} @codeCoverageIgnore

Implements SampleInterface.

Definition at line 143 of file Sample.php.

144  {
145  return $this->getData(self::KEY_SORT_ORDER);
146  }

◆ getTitle()

getTitle ( )

{Sample title

Returns
string
} @codeCoverageIgnore

Implements SampleInterface.

Definition at line 134 of file Sample.php.

135  {
136  return $this->getData(self::KEY_TITLE);
137  }

◆ getUrl()

getUrl ( )

Retrieve sample URL

Returns
string

Definition at line 89 of file Sample.php.

90  {
91  if ($this->getSampleUrl()) {
92  return $this->getSampleUrl();
93  } else {
94  return $this->getSampleFile();
95  }
96  }

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Downloadable\Api\Data\SampleExtensionInterface  $extensionAttributes)

{Set an extension attributes object.

Parameters
\Magento\Downloadable\Api\Data\SampleExtensionInterface$extensionAttributes
Returns
$this
}

Parameters
\Magento\Downloadable\Api\Data\SampleExtensionInterface$extensionAttributes
Returns
$this

Implements SampleInterface.

Definition at line 264 of file Sample.php.

265  {
267  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

◆ setSampleFile()

setSampleFile (   $sampleFile)

Set file path or null when type is 'url'

Parameters
string$sampleFile
Returns
$this

Implements SampleInterface.

Definition at line 221 of file Sample.php.

222  {
223  return $this->setData(self::KEY_SAMPLE_FILE, $sampleFile);
224  }

◆ setSampleFileContent()

setSampleFileContent ( \Magento\Downloadable\Api\Data\File\ContentInterface  $sampleFileContent = null)

Set sample file content

Parameters
\Magento\Downloadable\Api\Data\File\ContentInterface$sampleFileContent
Returns
$this

Definition at line 232 of file Sample.php.

233  {
234  return $this->setData(self::KEY_SAMPLE_FILE_CONTENT, $sampleFileContent);
235  }

◆ setSampleType()

setSampleType (   $sampleType)
Parameters
string$sampleType
Returns
$this

Implements SampleInterface.

Definition at line 210 of file Sample.php.

211  {
212  return $this->setData(self::KEY_SAMPLE_TYPE, $sampleType);
213  }

◆ setSampleUrl()

setSampleUrl (   $sampleUrl)

Set sample URL

Parameters
string$sampleUrl
Returns
$this

Implements SampleInterface.

Definition at line 243 of file Sample.php.

244  {
245  return $this->setData(self::KEY_SAMPLE_URL, $sampleUrl);
246  }

◆ setSortOrder()

setSortOrder (   $sortOrder)

Set sort order index for sample

Parameters
int$sortOrder
Returns
$this

Implements SampleInterface.

Definition at line 201 of file Sample.php.

202  {
203  return $this->setData(self::KEY_SORT_ORDER, $sortOrder);
204  }

◆ setTitle()

setTitle (   $title)

Set sample title

Parameters
string$title
Returns
$this

Implements SampleInterface.

Definition at line 190 of file Sample.php.

191  {
192  return $this->setData(self::KEY_TITLE, $title);
193  }
$title
Definition: default.phtml:14

Field Documentation

◆ KEY_SAMPLE_FILE

const KEY_SAMPLE_FILE = 'sample_file'

Definition at line 28 of file Sample.php.

◆ KEY_SAMPLE_FILE_CONTENT

const KEY_SAMPLE_FILE_CONTENT = 'sample_file_content'

Definition at line 29 of file Sample.php.

◆ KEY_SAMPLE_TYPE

const KEY_SAMPLE_TYPE = 'sample_type'

Definition at line 27 of file Sample.php.

◆ KEY_SAMPLE_URL

const KEY_SAMPLE_URL = 'sample_url'

Definition at line 30 of file Sample.php.

◆ KEY_SORT_ORDER

const KEY_SORT_ORDER = 'sort_order'

Definition at line 26 of file Sample.php.

◆ KEY_TITLE

const KEY_TITLE = 'title'

#+ Constants for field names

Definition at line 25 of file Sample.php.

◆ XML_PATH_SAMPLES_TITLE

const XML_PATH_SAMPLES_TITLE = 'catalog/downloadable/samples_title'

Definition at line 20 of file Sample.php.


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