/
Config.php
154 lines (138 loc) · 3.22 KB
/
Config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Block\Adminhtml\Product\Edit\Tab\Variations;
use Magento\Backend\Block\Widget;
use Magento\Backend\Block\Widget\Tab\TabInterface;
use Magento\Catalog\Model\Product;
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
/**
* Adminhtml catalog super product configurable tab
*/
class Config extends Widget implements TabInterface
{
/**
* @var string
*/
protected $_template = 'catalog/product/edit/super/config.phtml';
/**
* Core registry
*
* @var \Magento\Framework\Registry
*/
protected $_coreRegistry;
/**
* @var Configurable
*/
protected $configurableType;
/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Registry $coreRegistry
* @param Configurable $configurableType
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Registry $coreRegistry,
Configurable $configurableType,
array $data = []
) {
$this->_coreRegistry = $coreRegistry;
$this->configurableType = $configurableType;
parent::__construct($context, $data);
}
/**
* Initialize block
*
* @return void
*/
protected function _construct()
{
parent::_construct();
$this->setProductId($this->getRequest()->getParam('id'));
$this->setId('config_super_product');
$this->setCanEditPrice(true);
$this->setCanReadPrice(true);
}
/**
* Retrieve Tab class (for loading)
*
* @return string
*/
public function getTabClass()
{
return 'ajax';
}
/**
* Retrieve currently edited product object
*
* @return Product
*/
public function getProduct()
{
return $this->_coreRegistry->registry('current_product');
}
/**
* Retrieve Tab label
*
* @return \Magento\Framework\Phrase
*/
public function getTabLabel()
{
return __('Configurations');
}
/**
* Retrieve Tab title
*
* @return \Magento\Framework\Phrase
*/
public function getTabTitle()
{
return __('Configurations');
}
/**
* Can show tab flag
*
* @return bool
*/
public function canShowTab()
{
return true;
}
/**
* Check is a hidden tab
*
* @return bool
*/
public function isHidden()
{
return false;
}
/**
* Get parent tab code
*
* @return string
*/
public function getParentTab()
{
return 'product-details';
}
/**
* @return bool
*/
public function isHasVariations()
{
return $this->getProduct()->getTypeId() === Configurable::TYPE_CODE
&& $this->configurableType->getUsedProducts($this->getProduct());
}
/**
* @return $this
*/
protected function _prepareLayout()
{
$this->setData('opened', $this->getProduct()->getTypeId() === Configurable::TYPE_CODE);
return parent::_prepareLayout();
}
}