Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if ($this->isUploadedFile($this->data)) {
- App::import('Vendor', 'php-excel-reader/excel_reader2');
- $file = new Spreadsheet_Excel_Reader($this->data['file']['tmp_name'], true);
- App::import('Model', 'Product');
- $this->Product = new Product();
- App::import('Model', 'ManufacterProduct');
- $this->ManufacterProduct = new ManufacterProduct();
- foreach ($file->sheets[0]["cells"] as $k => &$row) {
- if ($k < 5)
- continue; // skip first 4 rows
- $product['Product']['code'] = $this->filter_number($row[23]); //kod produktu
- $product['Product']['title'] = utf8_encode($row[25]); //nazov produktu
- $product['Product']['stav_zasob'] = $this->filter_number($row[36]); //stav skladu
- $product['Product']['price'] = $this->filter_number($row[49]); //cena
- $product['Product']['seo_url'] = $this->Product->make_url($product['Product']['title'], $product['Product']['code']); //url adresa
- if(!isset($id)) { // could be empty
- $product['Product']['manufacter_product_id'] = $id = $this->ManufacterProduct->field('id', array(
- 'title' => $row[55]
- )); //dodavatel
- }
- if (!$id) {
- $product['Product']['manufacter_product_id'] = 1;
- }
- $this->Product->create(false);
- $this->Product->save($product);
- }
- unlink($this->data['file']['tmp_name']);
- }
- $this->redirect($this->referer());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement