A
A
Alexander Stepanov2019-02-27 08:49:32
Yii
Alexander Stepanov, 2019-02-27 08:49:32

How to set up excel import to import products with pictures?

I screwed up the excel import/export extension, tweaked it a little and it worked, but all the products are without pictures, and this is not a gut when there are a lot of products. And it's not comme il faut at all ...
The extension was installed by uranum/yii2-excel-exchange
Action:

public function actionImportExcel()
    {
        $inputFile = 'uploads/export.xlsx';
        try{
            $inputFileType = \PHPExcel_IOFactory::identify($inputFile);
            $objReader = \PHPExcel_IOFactory::createReader($inputFileType);
            $objPHPExcel = $objReader->load($inputFile);
        } catch (\DomainException $e) {
            die('Error');
        }

        $sheet = $objPHPExcel->getSheet(0);
        $highestRow = $sheet->getHighestRow();
        $highestColumn = $sheet->getHighestColumn();

        for($row=1; $row <= $highestRow; $row++)
        {
            $rowData = $sheet->rangeToArray('A'.$row.':'.$highestColumn.$row,NULL,TRUE,FALSE);

            if($row==1)
            {
                continue;
            }

            $product = new Product();
            $product->brand_id = $rowData[0][0];
            $product->category_id  = $rowData[0][1];
            $product->code  = $rowData[0][2];
            $product->name  = $rowData[0][3];
            $product->description  = $rowData[0][4];
            $product->price_new  = $rowData[0][5];
            $product->price_min  = $rowData[0][6];
            $product->price_roll  = $rowData[0][7];
            $product->meta = new Meta($rowData[0][8],
                                    $rowData[0][9],
                                    $rowData[0][10]
                                );
            $product->status  = $rowData[0][11];
            $product->quantity  = $rowData[0][12];
            $product->min_long  = $rowData[0][13];
            $product->roll_long  = $rowData[0][14];
            $product->created_at = time();
            $product->save();

            print_r($product->getErrors());
        }
        return $this->render('index');
    }

As you can see from the code, meta tags are loaded through a separate model. I tried this Makar with photos, but... The files need a form with enctype=multipart\formdata, but I don’t understand how to get it from the import file ..
Maybe there are better extensions?
Yes, I would like to understand the code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Frolov, 2019-03-24
@Cobalt666

Well, how are the comrades doing?
I also struggle with pictures, though not through this module.
this module is not all the more

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question