public function addAction() { $form = $this->getServiceLocator()->get('Admin\\Form\\ProductForm'); $request = $this->getRequest(); if ($request->isPost()) { $product = new Product(); $form->setInputFilter($product->getInputFilter()); $data = $request->getPost()->toArray(); $data['price'] = str_replace('.', '', $data['price']); $form->setData($data); if ($form->isValid()) { $fileService = $this->getServiceLocator()->get('Admin\\Service\\FileService'); $fileService->setDestination($this->config['component']['product']['image_path']); $fileService->setSize($this->config['file_characteristics']['image']['size']); $fileService->setExtension($this->config['file_characteristics']['image']['extension']); $image1 = $fileService->copy($this->params()->fromFiles('image1')); $image2 = $fileService->copy($this->params()->fromFiles('image2')); $image3 = $fileService->copy($this->params()->fromFiles('image3')); $image4 = $fileService->copy($this->params()->fromFiles('image4')); $image5 = $fileService->copy($this->params()->fromFiles('image5')); $image6 = $fileService->copy($this->params()->fromFiles('image6')); $fileService->setDestination($this->config['component']['product']['file_path']); $fileService->setSize($this->config['file_characteristics']['file']['size']); $fileService->setExtension($this->config['file_characteristics']['file']['extension']); $specificationFile = $fileService->copy($this->params()->fromFiles('specification_file')); $manualFile = $fileService->copy($this->params()->fromFiles('manual_file')); $fileService->setDestination($this->config['component']['product']['video_path']); $fileService->setSize($this->config['file_characteristics']['video']['size']); $fileService->setExtension($this->config['file_characteristics']['video']['extension']); $video = $fileService->copy($this->params()->fromFiles('video')); $data['specification_file'] = $specificationFile ? $specificationFile : ""; $data['manual_file'] = $manualFile ? $manualFile : ""; $data['image1'] = $image1 ? $image1 : ""; $data['image2'] = $image2 ? $image2 : ""; $data['image3'] = $image3 ? $image3 : ""; $data['image4'] = $image4 ? $image4 : ""; $data['image5'] = $image5 ? $image5 : ""; $data['image6'] = $image6 ? $image6 : ""; $measures = $data['measures']; $apps = $data['apps']; $product->exchangeArray($data); $productId = $this->getProductTable()->save($product); $productMeasuresTable = $this->getProductMeasureTable(); $productMeasuresTable->save($productId, $measures); $productAppTable = $this->getProductAppTable(); $productAppTable->save($productId, $apps); return $this->redirect()->toRoute('admin/product'); } else { $select = $form->get("measures")->setValue($data['measures']); } } return array('form' => $form, 'config' => $this->config); }
public function save(Product $product) { $data = array('upc_bar_code' => $product->getUpcBarCode(), 'model' => $product->getModel(), 'brand' => $product->getBrand(), 'category' => $product->getCategory(), 'part_no' => $product->getPartNo(), 'price' => $product->getPrice(), 'iva' => $product->getIva(), 'qty_low' => $product->getQtyLow(), 'qty_buy' => $product->getQtyBuy(), 'description' => $product->getDescription(), 'specification_file' => $product->getSpecificationFile(), 'image1' => $product->getImage1(), 'image2' => $product->getImage2(), 'image3' => $product->getImage3(), 'image4' => $product->getImage4(), 'image5' => $product->getImage5(), 'image6' => $product->getImage6(), 'manual_file' => $product->getManualFile(), 'video' => $product->getVideo(), 'status' => $product->getStatus(), 'register_date' => date("Y-m-d H:i:s", time()), 'update_date' => date("Y-m-d H:i:s", time())); $id = (int) $product->getId(); $params = array(); $params['table'] = $this->tableGateway->getTableName(); $params['operation'] = 1; $params['data'] = json_encode($data); if ($id == 0) { $this->tableGateway->insert($data); $id = $this->tableGateway->getLastInsertValue(); if ($id) { $params['id'] = $id; $this->featureSet->getEventManager()->trigger("log.save", $this, $params); return $id; } else { return false; } } else { if ($this->get($id)) { $params['id'] = $id; $params['operation'] = 2; $this->featureSet->getEventManager()->trigger("log.save", $this, $params); $this->tableGateway->update($data, array('id' => $id)); return $id; } else { return false; } } }