Skip to content

Instantly share code, notes, and snippets.

@denyadzi
Created September 9, 2013 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save denyadzi/6493774 to your computer and use it in GitHub Desktop.
Save denyadzi/6493774 to your computer and use it in GitHub Desktop.
<?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