Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Visual.php
Go to the documentation of this file.
1 <?php
7 
14 class Visual extends AbstractSwatch
15 {
19  protected $_template = 'Magento_Swatches::catalog/product/attribute/visual.phtml';
20 
31  protected function createStoreValues($storeId, $optionId)
32  {
33  $value = [];
34  $value['store' . $storeId] = '';
35  $value['defaultswatch' . $storeId] = '';
36  $value['swatch' . $storeId] = '';
37  $storeValues = $this->getStoreOptionValues($storeId);
38  $swatchStoreValue = null;
39 
40  if (isset($storeValues['swatch'])) {
41  $swatchStoreValue = $storeValues['swatch'];
42  }
43 
44  if (isset($storeValues[$optionId])) {
45  $value['store' . $storeId] = $storeValues[$optionId];
46  }
47 
48  if (isset($swatchStoreValue[$optionId])) {
49  $value['defaultswatch' . $storeId] = $swatchStoreValue[$optionId];
50  }
51 
52  $swatchStoreValue = $this->reformatSwatchLabels($swatchStoreValue);
53  if (isset($swatchStoreValue[$optionId])) {
54  $value['swatch' . $storeId] = $swatchStoreValue[$optionId];
55  }
56 
57  return $value;
58  }
59 
66  public function getJsonConfig()
67  {
68  $values = [];
69  foreach ($this->getOptionValues() as $value) {
70  $values[] = $value->getData();
71  }
72 
73  $data = [
74  'attributesData' => $values,
75  'uploadActionUrl' => $this->getUrl('swatches/iframe/show'),
76  'isSortable' => (int)(!$this->getReadOnly() && !$this->canManageOptionDefaultOnly()),
77  'isReadOnly' => (int)$this->getReadOnly()
78  ];
79 
80  return json_encode($data);
81  }
82 
90  protected function reformatSwatchLabels($swatchStoreValue = null)
91  {
92  if ($swatchStoreValue === null) {
93  return;
94  }
95  $newSwatch = [];
96  foreach ($swatchStoreValue as $key => $value) {
97  if ($value[0] == '#') {
98  $newSwatch[$key] = 'background: '.$value;
99  } elseif ($value[0] == '/') {
100  $mediaUrl = $this->swatchHelper->getSwatchMediaUrl();
101  $newSwatch[$key] = 'background: url('.$mediaUrl.$value.'); background-size: cover;';
102  }
103  }
104  return $newSwatch;
105  }
106 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16