N98\Magento\Command\Eav\Attribute\Create\DummyCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output ) : integer | void
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
return integer | void
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->detectMagento($output, true);
        if (!$this->initMagento()) {
            return;
        }
        $output->writeln("<warning>This only create sample attribute values, do not use on production environment</warning>");
        // Ask for Arguments
        $argument = $this->askForArguments($input, $output);
        if (!in_array($input->getArgument('locale'), $this->supportedLocales)) {
            $output->writeln(sprintf("<warning>Locale '%s' not supported, switch to default locale 'us_US'.</warning>", $input->getArgument('locale')));
            $argument['locale'] = "en_US";
        } else {
            $argument['locale'] = $input->getArgument('locale');
        }
        /** @var $attribute Mage_Eav_Model_Entity_Attribute */
        $attribute = Mage::getModel('eav/entity_attribute')->load($argument['attribute-id']);
        $dummyValues = new DummyValues();
        for ($i = 0; $i < $argument['values-number']; $i++) {
            $value = $dummyValues->createValue($argument['values-type'], $argument['locale']);
            if (!$this->attributeValueExists($attribute, $value)) {
                try {
                    $attribute->setData('option', array('value' => array('option' => array($value, $value))));
                    $attribute->save();
                } catch (\Exception $e) {
                    $output->writeln("<error>" . $e->getMessage() . "</error>");
                }
                $output->writeln("<comment>ATTRIBUTE VALUE: '" . $value . "' ADDED!</comment>\r");
            }
        }
    }