Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $now = new \DateTime();
     foreach ($this->data as $priceListData) {
         $priceList = new PriceList();
         $priceList->setName($priceListData['name'])->setDefault($priceListData['default'])->setCurrencies(['USD'])->setCreatedAt($now)->setUpdatedAt($now);
         foreach ($priceListData['customers'] as $customerReference) {
             /** @var Customer $customer */
             $customer = $this->getReference($customerReference);
             $priceList->addCustomer($customer);
         }
         foreach ($priceListData['groups'] as $customerGroupReference) {
             /** @var CustomerGroup $customerGroup */
             $customerGroup = $this->getReference($customerGroupReference);
             $priceList->addCustomerGroup($customerGroup);
         }
         foreach ($priceListData['websites'] as $websiteReference) {
             /** @var Website $website */
             $website = $this->getReference($websiteReference);
             $priceList->addWebsite($website);
         }
         foreach ($priceListData['currencies'] as $currencyCode) {
             $priceList->addCurrencyByCode($currencyCode);
         }
         $manager->persist($priceList);
         $this->setReference($priceListData['reference'], $priceList);
     }
     $manager->flush();
 }
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $locator = $this->container->get('file_locator');
     $filePath = $locator->locate('@OroB2BPricingBundle/Migrations/Data/Demo/ORM/data/price_lists.csv');
     if (is_array($filePath)) {
         $filePath = current($filePath);
     }
     $handler = fopen($filePath, 'r');
     $headers = fgetcsv($handler, 1000, ',');
     while (($data = fgetcsv($handler, 1000, ',')) !== false) {
         $row = array_combine($headers, array_values($data));
         $currencies = array_map('trim', explode(',', $row['currencies']));
         $priceList = new PriceList();
         $priceList->setName($row['name'])->setDefault((bool) $row['default'])->setCurrencies($currencies);
         $manager->persist($priceList);
     }
     fclose($handler);
     $manager->flush();
 }