Commit 3aa91326 by halweg

fix

parent a4d666a8
...@@ -14,6 +14,7 @@ use Magento\Framework\Exception\NoSuchEntityException; ...@@ -14,6 +14,7 @@ use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\File\Csv; use Magento\Framework\File\Csv;
use Magento\Framework\ObjectManager\ObjectManager; use Magento\Framework\ObjectManager\ObjectManager;
use Magento\Setup\Exception; use Magento\Setup\Exception;
use Magento\Store\Model\App\Emulation;
use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
...@@ -166,12 +167,12 @@ class ReviewsImporter extends Command ...@@ -166,12 +167,12 @@ class ReviewsImporter extends Command
return; return;
} }
$storeId = $input->getOption('store_id'); $store_id = $input->getOption('store_id');
if (!$storeId) { if (!$store_id) {
$output->writeln($this->errorWrapper("store_id没填")); $output->writeln($this->errorWrapper("store_id没填"));
return; return;
} }
$this->storeId = $storeId; $this->storeId = $store_id;
$this->importCsvFile($path); $this->importCsvFile($path);
} catch (\Exception $e) { } catch (\Exception $e) {
$output->writeln($this->errorWrapper($e->getMessage())); $output->writeln($this->errorWrapper($e->getMessage()));
...@@ -192,6 +193,7 @@ class ReviewsImporter extends Command ...@@ -192,6 +193,7 @@ class ReviewsImporter extends Command
private function insertDB($data) private function insertDB($data)
{ {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$reviewFactory = $objectManager->get("Magento\Review\Model\ReviewFactory"); $reviewFactory = $objectManager->get("Magento\Review\Model\ReviewFactory");
$ratingFactory = $objectManager->get("Magento\Review\Model\RatingFactory"); $ratingFactory = $objectManager->get("Magento\Review\Model\RatingFactory");
...@@ -319,21 +321,15 @@ class ReviewsImporter extends Command ...@@ -319,21 +321,15 @@ class ReviewsImporter extends Command
$review['size_fits'] = trim($row[6]); $review['size_fits'] = trim($row[6]);
$review['date'] = trim($row[7]); $review['date'] = trim($row[7]);
if (empty(trim($review["sku"])) if (empty(trim($review["sku"]))
|| empty(trim($review["detail"]) || empty(trim($review["detail"]))
|| empty(trim($review['nickname'])) || empty(trim($review['nickname']))
|| empty($review['date']) || empty($review['date'])
|| empty($review['title']) || empty($review['title']
) || empty($review['size_fits'])
|| empty($review['ratings'])
)
) { ) {
throw new \Exception("表格数据有空: {$row["name"]}"); throw new \Exception("表格数据有空!");
}
if (!is_integer($review['size_fits'])) {
$review['size_fits'] = 3;
}
if (!is_integer($review['ratings'])) {
$review['ratings'] = 5;
} }
$data[] = $review; $data[] = $review;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment