/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); // $fields['title']->isFilled(BL::err('FieldIsRequired')); // $fields['summary']->isFilled(BL::err('FieldIsRequired')); $fields['category_id']->isFilled(BL::err('FieldIsRequired')); if ($fields['category_id']->getValue() == 'no_category') { $fields['category_id']->addError(BL::err('FieldIsRequired')); } // validate meta $this->meta->validate(); //--Validate Media $this->media->validate(); if ($this->frm->isCorrect()) { $item['id'] = $this->id; $item['language'] = BL::getWorkingLanguage(); $item['price'] = $fields['price']->getValue(); $item['category_id'] = $this->frm->getField('category_id')->getValue(); $item['brand_id'] = $fields['brand_id']->getValue(); $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N'; $item['frontpage'] = $this->frm->getField('frontpage')->getChecked(); $item['contact'] = $this->frm->getField('contact')->getChecked(); $item['meta_id'] = $this->meta->save(); $item['ballcolor'] = $fields['ballcolor']->getValue(); BackendCatalogModel::update($item); $item['id'] = $this->id; //--Add the languages foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) { $itemLanguage = array(); $itemLanguage['id'] = $item['id']; $itemLanguage['language'] = $language; $itemLanguage['title'] = $this->frm->getField('title_' . $language)->getValue(); $itemLanguage['summary'] = $this->frm->getField('summary_' . $language)->getValue(); $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue(); $itemLanguage['url'] = BackendCatalogModel::getURLLanguage($this->frm->getField('title_' . $language)->getValue(), $item['id'], $language); $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue(); BackendCatalogModel::updateLanguage($itemLanguage, $language); } $specificationArray = array(); // loop trough specifications and insert values foreach ($this->specifications as $specification) { foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) { $field = 'specification' . $specification['id'] . '_' . $language; $specificationArray['value'] = $fields[$field]->getValue(); $specificationArray['language'] = $language; $specificationArray['product_id'] = $item['id']; $specificationArray['specification_id'] = $specification['id']; // when specification value already exists. update value if (BackendCatalogModel::existsSpecificationValue($item['id'], $specification['id'], $language) != false) { // update specification with product id and value BackendCatalogModel::updateSpecificationValue($specification['id'], $item['id'], $language, $specificationArray); } else { // when specification value doesnt exists, insert new value BackendCatalogModel::insertSpecificationValue($specificationArray); } } } // save the tags BackendTagsModel::saveTags($item['id'], $fields['tags']->getValue(), $this->URL->getModule()); // add search index BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $this->frm->getField('title_nl')->getValue(), 'summary' => $this->frm->getField('summary_nl')->getValue(), 'text' => $this->frm->getField('text_nl')->getValue())); // save related projects BackendCatalogModel::saveRelatedProducts($item['id'], $this->frm->getField('related_products')->getValue(), $this->relatedProducts); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_edit', $item); $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']); } } }