Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Downloadable.php
Go to the documentation of this file.
1 <?php
8 
10 use Magento\Mtf\Client\Locator;
11 use Magento\Mtf\Client\Element\SimpleElement;
15 
19 class Downloadable extends Section
20 {
26  protected $addNewRow = '[data-index="link"] [data-action="add_new_row"]';
27 
33  protected $downloadableBlock = '[data-index="container_%s"]';
34 
40  protected $isDownloadableProduct = '[name="is_downloadable"]';
41 
49  public function getDownloadableBlock($type, SimpleElement $element = null)
50  {
51  $element = $element ?: $this->_rootElement;
52  return $this->blockFactory->create(
53  'Magento\Downloadable\Test\Block\Adminhtml\Catalog\Product\Edit\Section\Downloadable\\' . $type,
54  ['element' => $element->find(sprintf($this->downloadableBlock, strtolower($type)), Locator::SELECTOR_CSS)]
55  );
56  }
57 
66  public function getFieldsData($fields = null, SimpleElement $element = null)
67  {
68  $newFields = [];
69  if (isset($fields['downloadable_sample']['value'])) {
70  $newFields['downloadable_sample'] = $this->getDownloadableBlock('Samples')->getDataSamples(
71  $fields['downloadable_sample']['value']
72  );
73  }
74  if (isset($fields['downloadable_links']['value'])) {
75  $newFields['downloadable_links'] = $this->getDownloadableBlock('Links')->getDataLinks(
76  $fields['downloadable_links']['value']
77  );
78  }
79 
80  return $newFields;
81  }
82 
90  public function setFieldsData(array $fields, SimpleElement $element = null)
91  {
92  $context = $element ?: $this->_rootElement;
93  $isDownloadable = $context->find($this->isDownloadableProduct);
94  if ($isDownloadable->isVisible() && $isDownloadable->getAttribute('value') != '1') {
95  $isDownloadable->click();
96  }
97  if (isset($fields['downloadable_sample']['value'])) {
98  $this->getDownloadableBlock('Samples')->fillSamples($fields['downloadable_sample']['value']);
99  }
100 
101  if (isset($fields['downloadable_links']['value'])) {
102  $this->getDownloadableBlock('Links')->fillLinks($fields['downloadable_links']['value']);
103  }
104 
105  return $this;
106  }
107 
115  public function setIsDownloadable(string $downloadable = 'Yes', SimpleElement $element = null): void
116  {
117  $context = $element ?: $this->_rootElement;
118  $isDownloadable = $context->find($this->isDownloadableProduct);
119  $value = 'Yes' == $downloadable ? '1' : '0';
120  if ($isDownloadable->isVisible() && $isDownloadable->getAttribute('value') != $value) {
121  $isDownloadable->click();
122  }
123  }
124 }
$fields
Definition: details.phtml:14
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
setIsDownloadable(string $downloadable='Yes', SimpleElement $element=null)
$element
Definition: element.phtml:12