createValue() public method

Create random value
public createValue ( string $type, $locale ) : integer | string
$type string
return integer | string
Example #1
0
 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  *
  * @return int|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");
         }
     }
 }