Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* @file
*
* first fixture experience...
*/
namespace Mirtrik\HelloBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Mirtrik\ProductBundle\Entity\Product;
use Mirtrik\ProductBundle\Entity\Attribute;
use Mirtrik\ProductBundle\Entity\AttributeValue;
use Mirtrik\ProductBundle\Entity\Category;
/**
*
*
* Loading Product Data into db
*/
class LoadProductData implements FixtureInterface
{
/**
* @method inherited
*/
public function load(ObjectManager $manager)
{
// создаем атрибуты
$testAttr = new Attribute();
$testAttr
->setTitle('testAttrTitle')
->setType('testAttrType')
->setFieldName('testAttrFieldName');
// создаем категории
$testCategory = new Category();
$testCategory
->setTitle('testcategoryTitle')
->addAttribute($testAttr);
// создаем продукт
$testProduct = new Product();
$testProduct
->setCategory($testCategory);
// создаем значения
$testValue = new AttributeValue();
$testValue
->setValue('testValue')
->setIsDefault(FALSE)
->setAttribute($testAttr)
->setProduct($testProduct);
// сохраняем в базу
$manager->persist($testAttr);
$manager->persist($testCategory);
$manager->persist($testProduct);
$manager->persist($testValue);
$manager->flush();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.