/** * Do the actual import to our database * @todo rewrite this, so it can be overwritten - maybe add required import to product? * @param bool $debug * @return array|boolean * @throws Exception\MagmiHasNotBeenSetup */ public function import($debug = false) { $this->debugMode = $debug; if ($debug === false) { if (!$this->magmi instanceof \Magmi_ProductImport_DataPump) { throw new Exception\MagmiHasNotBeenSetup(sprintf('Magmi has not been setup yet, use setMagmi(%s, %s, %s. %s)', 'Magmi_ProductImport_DataPump $magmi', 'string $profile', 'string $mode', 'Datapump\\Logger Logger $logger')); } $this->magmi->beginImportSession($this->profile, $this->mode, $this->logger); } $output = array(); if ($this->output instanceof OutputInterface && $debug === false) { $progress = new ProgressHelper(); $this->output->writeln("\nImport progress"); $progress->start($this->output, count($this->products)); } foreach ($this->products as $product) { if ($this->output instanceof OutputInterface && $debug === false) { $progress->advance(); } /** @var ProductAbstract $product */ switch ($product->getRequiredData()->getType()) { case DataAbstract::TYPE_CONFIGURABLE: /** @var Configurable $product */ if (method_exists($product, 'getSimpleProducts')) { foreach ($product->getSimpleProducts() as $simple) { /** @var Simple $simple */ $output[] = $this->inject($simple); } } $output[] = $this->inject($product); break; default: $output[] = $this->inject($product); break; } } if ($debug === false) { $this->magmi->endImportSession(); if ($this->output instanceof OutputInterface && $progress instanceof ProgressHelper) { $progress->finish(); } } else { return $output; } $this->resetProducts(); return true; }
private function import($items, $mode = 'create', $indexes = 'all') { if (count($items) > 0) { $this->fvs->debug(sprintf(" processing %s items", count($items))); $dp = new Magmi_ProductImport_DataPump(); $dp->beginImportSession("babycenter", $mode); foreach ($items as $item) { $dp->ingest($item); } $dp->endImportSession(); $this->fvs->debug(" reindexing"); $this->reindex($indexes); $this->fvs->debug(" processing done"); } }