/**
  * @return Product
  */
 public function setDataToObject()
 {
     $this->object->setSku($this->getFormattedData('sku', 'string'));
     $this->object->setName($this->getFormattedData('name', 'string'));
     $this->object->setPicture($this->getFormattedData('picture', 'string'));
     $this->object->setUrl($this->getFormattedData('url', 'string'));
     $this->object->setManufacturer($this->getFormattedData('manufacturer', 'string'));
     $this->object->setCategory($this->getFormattedData('category', 'string'));
     $this->object->setCategoryOuterId($this->getFormattedData('categoryOuterId', 'string'));
     $this->object->setIsDescription($this->getFormattedData('isDescription', 'integer'));
     $this->object->setStatus($this->getFormattedData('status', 'integer'));
     $this->object->setAvailableDate($this->getFormattedData('availableDate', 'date'));
     $this->object->setProductCreateDate($this->getFormattedData('productCreateDate', 'date'));
     parent::setDataToObject();
 }
示例#2
0
 /**
  * @Route("/import", name="massimport")
  */
 public function massImportAction(Request $request)
 {
     $form = $this->createFormBuilder(null, array('action' => $this->generateUrl('massimport')))->add('file', 'file')->getForm();
     if ($request->getMethod() === 'POST') {
         $request = $this->getRequest();
         $form->bind($request);
         // It always gets overwritten
         $form['file']->getData()->move('/tmp', 'example.tmp');
         $lines = explode(PHP_EOL, file_get_contents('/tmp/example.tmp'));
         // since we don't care about first line or last line
         array_shift($lines);
         array_pop($lines);
         foreach ($lines as $line) {
             $data = explode("\t", $line);
             $product = new Product();
             $product->setTitle($data[0]);
             $product->setDescription($this->sanitize($data[1]));
             $product->setPrice($data[2]);
             // I'm not dealing with timezones as I'd need another field for it to work with doctrine and I didn't notice until the end of the exam
             $product->setInitDate(new \DateTime($data[3]));
             $product->setExpiryDate(new \DateTime($data[4]));
             $product->setMerchantAddress($data[5]);
             $product->setMerchantName($this->sanitize($data[6]));
             // I'm currently just enabling all of them
             $product->setStatus(1);
             $this->saveProduct($product);
         }
     }
     return $this->render('default/success.html.twig');
 }