Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Sample.php
Go to the documentation of this file.
1 <?php
7 
9 
19 {
20  const XML_PATH_SAMPLES_TITLE = 'catalog/downloadable/samples_title';
21 
25  const KEY_TITLE = 'title';
26  const KEY_SORT_ORDER = 'sort_order';
27  const KEY_SAMPLE_TYPE = 'sample_type';
28  const KEY_SAMPLE_FILE = 'sample_file';
29  const KEY_SAMPLE_FILE_CONTENT = 'sample_file_content';
30  const KEY_SAMPLE_URL = 'sample_url';
42  public function __construct(
43  \Magento\Framework\Model\Context $context,
44  \Magento\Framework\Registry $registry,
45  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
46  \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
47  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
48  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
49  array $data = []
50  ) {
51  parent::__construct(
52  $context,
53  $registry,
54  $extensionFactory,
56  $resource,
57  $resourceCollection,
58  $data
59  );
60  }
61 
67  protected function _construct()
68  {
69  $this->_init(\Magento\Downloadable\Model\ResourceModel\Sample::class);
70  parent::_construct();
71  }
72 
78  public function afterSave()
79  {
80  $this->getResource()->saveItemTitle($this);
81  return parent::afterSave();
82  }
83 
89  public function getUrl()
90  {
91  if ($this->getSampleUrl()) {
92  return $this->getSampleUrl();
93  } else {
94  return $this->getSampleFile();
95  }
96  }
97 
103  public function getBaseTmpPath()
104  {
105  return 'downloadable/tmp/samples';
106  }
107 
113  public function getBasePath()
114  {
115  return 'downloadable/files/samples';
116  }
117 
126  {
127  return $this->_getResource()->getSearchableData($productId, $storeId);
128  }
129 
134  public function getTitle()
135  {
136  return $this->getData(self::KEY_TITLE);
137  }
138 
143  public function getSortOrder()
144  {
145  return $this->getData(self::KEY_SORT_ORDER);
146  }
147 
152  public function getSampleType()
153  {
154  return $this->getData(self::KEY_SAMPLE_TYPE);
155  }
156 
161  public function getSampleFile()
162  {
163  return $this->getData(self::KEY_SAMPLE_FILE);
164  }
165 
170  public function getSampleFileContent()
171  {
172  return $this->getData(self::KEY_SAMPLE_FILE_CONTENT);
173  }
174 
179  public function getSampleUrl()
180  {
181  return $this->getData(self::KEY_SAMPLE_URL);
182  }
183 
190  public function setTitle($title)
191  {
192  return $this->setData(self::KEY_TITLE, $title);
193  }
194 
201  public function setSortOrder($sortOrder)
202  {
203  return $this->setData(self::KEY_SORT_ORDER, $sortOrder);
204  }
205 
210  public function setSampleType($sampleType)
211  {
212  return $this->setData(self::KEY_SAMPLE_TYPE, $sampleType);
213  }
214 
221  public function setSampleFile($sampleFile)
222  {
223  return $this->setData(self::KEY_SAMPLE_FILE, $sampleFile);
224  }
225 
232  public function setSampleFileContent(\Magento\Downloadable\Api\Data\File\ContentInterface $sampleFileContent = null)
233  {
234  return $this->setData(self::KEY_SAMPLE_FILE_CONTENT, $sampleFileContent);
235  }
236 
243  public function setSampleUrl($sampleUrl)
244  {
245  return $this->setData(self::KEY_SAMPLE_URL, $sampleUrl);
246  }
247 
253  public function getExtensionAttributes()
254  {
255  return $this->_getExtensionAttributes();
256  }
257 
264  public function setExtensionAttributes(\Magento\Downloadable\Api\Data\SampleExtensionInterface $extensionAttributes)
265  {
266  return $this->_setExtensionAttributes($extensionAttributes);
267  }
268 }
$title
Definition: default.phtml:14
setExtensionAttributes(\Magento\Downloadable\Api\Data\SampleExtensionInterface $extensionAttributes)
Definition: Sample.php:264
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
$resource
Definition: bulk.php:12
setSampleFileContent(\Magento\Downloadable\Api\Data\File\ContentInterface $sampleFileContent=null)
Definition: Sample.php:232
__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=[])
Definition: Sample.php:42
getSearchableData($productId, $storeId)
Definition: Sample.php:125