Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. if ($this->isUploadedFile($this->data)) {
  2.             App::import('Vendor', 'php-excel-reader/excel_reader2');
  3.             $file = new Spreadsheet_Excel_Reader($this->data['file']['tmp_name'], true);
  4.             App::import('Model', 'Product');
  5.             $this->Product = new Product();
  6.             App::import('Model', 'ManufacterProduct');
  7.             $this->ManufacterProduct = new ManufacterProduct();
  8.             foreach ($file->sheets[0]["cells"] as $k => &$row) {
  9.                 if ($k < 5)
  10.                     continue; // skip first 4 rows
  11.                
  12.                     $product['Product']['code'] = $this->filter_number($row[23]); //kod produktu
  13.                     $product['Product']['title'] = utf8_encode($row[25]); //nazov produktu
  14.                     $product['Product']['stav_zasob'] = $this->filter_number($row[36]); //stav skladu
  15.                     $product['Product']['price'] = $this->filter_number($row[49]); //cena
  16.                     $product['Product']['seo_url'] = $this->Product->make_url($product['Product']['title'], $product['Product']['code']); //url adresa
  17.                     if(!isset($id)) { // could be empty
  18.                         $product['Product']['manufacter_product_id'] = $id = $this->ManufacterProduct->field('id', array(
  19.                                 'title' => $row[55]
  20.                             )); //dodavatel
  21.                     }
  22.                     if (!$id) {
  23.                         $product['Product']['manufacter_product_id'] = 1;
  24.                     }
  25.                     $this->Product->create(false);
  26.                     $this->Product->save($product);
  27.                 }
  28.             unlink($this->data['file']['tmp_name']);
  29.         }
  30.         $this->redirect($this->referer());
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement