protected function _initializeInputFilter() { $joinedRow = new ProductJoinedRow(); $pFilter = $joinedRow->getJoinedRow('Product')->getInputFilter(); $pdFilter = $joinedRow->getJoinedRow('ProductDescription')->getInputFilter(); $inputFilter = new InputFilter(); $factory = new InputFactory(); /*** product table's columns ***/ $inputFilter->add($pFilter->get('product_id')); $inputFilter->add($pFilter->get('product_name')); $inputFilter->add($pFilter->get('store_price')); $inputFilter->add($pFilter->get('market_price')); /*** product_description table's columns ***/ $inputFilter->add($pdFilter->get('description_id')); $inputFilter->add($pdFilter->get('description')); $this->filter = $inputFilter; }
/** * Save joined row * * @param ProductJoinedRow $productJoinedRow * @return void */ public function saveProductJoinedRow(ProductJoinedRow $productJoinedRow) { // Save Product $product = new Product(); $productTable = new ProductTable($this->adapter); $product->exchangeArray($productTable->filterByColumns($productJoinedRow->toArray())); $productTable->saveProduct($product); if ($productId = $productTable->getLastInsertValue()) { // Add product $productJoinedRow->product_id = $productId; } // Save ProductDescription $productDescription = new ProductDescription(); $productDescriptionTable = new ProductDescriptionTable($this->adapter); $productDescription->exchangeArray($productDescriptionTable->filterByColumns($productJoinedRow->toArray())); $productDescriptionTable->saveProductDescription($productDescription); }
public function addAction() { $productJoinedRow = new ProductJoinedRow(); $form = new ProductForm(); //$form->bind($joinedProduct); if ($this->request->isPost()) { $data = array_merge($this->request->getPost()->toArray(), array('created_date' => time(), 'updated_date' => time())); $productJoinedRow->exchangeArray($data); $this->getProductJoinedTable()->saveProductJoined($productJoinedRow); return $this->redirect()->toRoute('catalog-admin-product'); // $form->setInputFilter($inputFilter) // ->setData($data); // if ($form->isValid()) { // $this->getProductTable()->saveProduct($product); // return $this->redirect()->toRoute('catalog-admin-product'); // } } $viewModel = $this->getViewModel(); $viewModel->setVariables(array('form' => $form)); return $viewModel; }