Created
December 16, 2020 20:23
-
-
Save seanr/eb038934c3c1b8a133e38103f31d9723 to your computer and use it in GitHub Desktop.
Attribute Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Drush\Drush; | |
use Drupal\commerce_product\Entity\ProductAttributeValue; | |
use Symfony\Component\Yaml\Yaml; | |
$yml = file_get_contents('/app/config/templates/commerce-attributes/attributes.yml'); | |
$attributes = Yaml::parse($yml); | |
// For each attribute | |
foreach ($attributes as $attribute) { | |
$machineName = strtolower($attribute['machine_name']); | |
$machineName = preg_replace('/[^a-z0-9_]+/', '_', $machineName); | |
$machineName = preg_replace('/_+/', '_', $machineName); | |
$data = ProductAttributeValue::create([ | |
'attribute' => $machineName, | |
'name' => 'test', | |
]); | |
$data->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment