<?php


namespace WellCommerce\Bundle\DelivererBundle\DataFixtures\ORM;

use Doctrine\Common\Persistence\ObjectManager;
use WellCommerce\Bundle\CoreBundle\DataFixtures\AbstractDataFixture;
use WellCommerce\Bundle\DelivererBundle\Entity\Deliverer;

/**
 * Class LoadDelivererData
 *
 * @author  Adam Piotrowski <adam@wellcommerce.org>
 */
class LoadDelivererData extends AbstractDataFixture
{
    /**
     * {@inheritDoc}
     */
    public function load(ObjectManager $manager)
    {
        if (!$this->isEnabled()) {
            return;
        }
        
        $fakerGenerator = $this->getFakerGenerator();
        $deliverer      = new Deliverer();
        $name           = $fakerGenerator->company;
        foreach ($this->getLocales() as $locale) {
            $deliverer->translate($locale->getCode())->setName($name);
        }
        
        $deliverer->mergeNewTranslations();
        $manager->persist($deliverer);
        $manager->flush();
        
        $this->setReference('deliverer', $deliverer);
    }
}
