public function saveProduct(Product $product) { $productId = (int) $product->getProductId(); // print_r($product);die; $data_product = array('provider_id' => $product->getProvider_id(), 'model' => $product->getModel(), 'sku' => $product->getSku(), 'isbn' => $product->getIsbn(), 'price' => $product->getPrice(), 'minimum' => $product->getMinimum(), 'date_available' => date("Y-m-d H:i:s"), 'date_added' => date("Y-m-d H:i:s")); $data_product_description = array('name' => $product->getProductDescription()->getName(), 'description' => $product->getProductDescription()->getDescription(), 'meta_description' => $product->getProductDescription()->getMeta_description(), 'meta_keyword' => $product->getProductDescription()->getMeta_keyword(), 'meta_tittle' => $product->getProductDescription()->getMeta_tittle()); $data_product_categories = $product->getProductCategories(); $data_product_image = $product->getProductImage(); $data_product_urlAlias = array('type' => $product->getUrlAlias()->type, 'keyword' => $product->getUrlAlias()->keyword); if ($productId == 0) { // insert Product Table $sProduct = $this->tableGateway->insert($data_product); if ($sProduct) { $productId = $this->tableGateway->getLastInsertValue(); // Insert Product Description $sDescription = $this->saveProductDescription($productId, $data_product_description); // Insert Images $sImage = $this->saveProductImage($productId, $data_product_image); // insert Url Alias $sUrlAlias = $this->saveUrlAlias($productId, $data_product_urlAlias); // insert Categories $sUrlAlias = $this->saveProductCategories($productId, $data_product_categories); return $productId; } else { throw new \Exception('Form id does not exist'); } } else { if ($this->getById($productId)) { $data_product['date_modified'] = date("Y-m-d H:i:s"); //print_r($data_product);die; $this->tableGateway->update($data_product, array('product_id' => $productId)); // update Product Description $sDescription = $this->saveProductDescription($productId, $data_product_description, 1); // update Images ( AJAX ) //$sImage = $this->saveProductImage($productId, $data_product_image); // update Url Alias $sUrlAlias = $this->saveUrlAlias($productId, $data_product_urlAlias, 1); // update Categories $sUrlAlias = $this->saveProductCategories($productId, $data_product_categories, 1); return $productId; } else { throw new \Exception('Form id does not exist'); } } }