1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace N98\Magento\Command\Eav\Attribute; |
4
|
|
|
|
5
|
|
|
use InvalidArgumentException; |
6
|
|
|
use N98\Magento\Command\AbstractMagentoCommand; |
7
|
|
|
use N98\Util\Console\Helper\Table\Renderer\RendererFactory; |
8
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Input\InputOption; |
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
12
|
|
|
use Symfony\Component\Process\Exception\RuntimeException; |
13
|
|
|
|
14
|
|
|
class ViewCommand extends AbstractMagentoCommand |
15
|
|
|
{ |
16
|
|
|
protected function configure() |
17
|
|
|
{ |
18
|
|
|
$this |
19
|
|
|
->setName('eav:attribute:view') |
20
|
|
|
->addArgument('entityType', InputArgument::REQUIRED, 'Entity Type Code like catalog_product') |
21
|
|
|
->addArgument('attributeCode', InputArgument::REQUIRED, 'Attribute Code') |
22
|
|
|
->setDescription('View informations about an EAV attribute') |
23
|
|
|
->addOption( |
24
|
|
|
'format', |
25
|
|
|
null, |
26
|
|
|
InputOption::VALUE_OPTIONAL, |
27
|
|
|
'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']' |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param InputInterface $input |
33
|
|
|
* @param OutputInterface $output |
34
|
|
|
* |
35
|
|
|
* @return int|void |
36
|
|
|
* @throws InvalidArgumentException |
37
|
|
|
*/ |
38
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
39
|
|
|
{ |
40
|
|
|
$this->detectMagento($output); |
41
|
|
|
if (!$this->initMagento()) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$entityType = $input->getArgument('entityType'); |
46
|
|
|
$attributeCode = $input->getArgument('attributeCode'); |
47
|
|
|
|
48
|
|
|
$attribute = $this->getAttribute($entityType, $attributeCode); |
49
|
|
|
if (!$attribute) { |
50
|
|
|
throw new InvalidArgumentException('Attribute was not found.'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$table = array( |
54
|
|
|
array('ID', $attribute->getId()), |
55
|
|
|
array('Code', $attribute->getName()), |
56
|
|
|
array('Attribute-Set-ID', $attribute->getAttributeSetId()), |
57
|
|
|
array('Visible-On-Front', $attribute->getIsVisibleOnFront() ? 'yes' : 'no'), |
58
|
|
|
array('Attribute-Model', $attribute->getAttributeModel() ? $attribute->getAttributeModel() : ''), |
59
|
|
|
array('Backend-Model', $attribute->getBackendModel() ? $attribute->getBackendModel() : ''), |
60
|
|
|
array('Backend-Table', $attribute->getBackendTable() ? $attribute->getBackendTable() : ''), |
61
|
|
|
array('Backend-Type', $attribute->getBackendType() ? $attribute->getBackendType() : ''), |
62
|
|
|
array('Source-Model', $attribute->getSourceModel() ? $attribute->getSourceModel() : ''), |
63
|
|
|
array('Cache-ID-Tags', $attribute->getCacheIdTags() ? implode(',', $attribute->getCacheIdTags()) : ''), |
64
|
|
|
array('Cache-Tags', $attribute->getCacheTags() ? implode(',', $attribute->getCacheTags()) : ''), |
65
|
|
|
array('Default-Value', $attribute->getDefaultValue() ? $attribute->getDefaultValue() : ''), |
66
|
|
|
array( |
67
|
|
|
'Flat-Columns', |
68
|
|
|
$attribute->getFlatColumns() ? implode(',', array_keys($attribute->getFlatColumns())) : '', |
69
|
|
|
), |
70
|
|
|
array('Flat-Indexes', $attribute->getFlatIndexes() ? implode(',', $attribute->getFlatIndexes()) : ''), |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
if ($attribute->getFrontend()) { |
74
|
|
|
$table[] = array('Frontend-Label', $attribute->getFrontend()->getLabel()); |
75
|
|
|
$table[] = array('Frontend-Class', trim($attribute->getFrontend()->getClass())); |
76
|
|
|
$table[] = array('Frontend-Input', trim($attribute->getFrontend()->getInputType())); |
77
|
|
|
$table[] = array( |
78
|
|
|
'Frontend-Input-Renderer-Class', |
79
|
|
|
trim($attribute->getFrontend()->getInputRendererClass()), |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
$this |
84
|
|
|
->getHelper('table') |
85
|
|
|
->setHeaders(array('Type', 'Value')) |
86
|
|
|
->renderByFormat($output, $table, $input->getOption('format')); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @param string $entityType |
91
|
|
|
* @param string $attributeCode |
92
|
|
|
* |
93
|
|
|
* @return \Mage_Eav_Model_Entity_Attribute_Abstract|false |
94
|
|
|
*/ |
95
|
|
|
protected function getAttribute($entityType, $attributeCode) |
96
|
|
|
{ |
97
|
|
|
return \Mage::getModel('eav/config')->getAttribute($entityType, $attributeCode); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|