/** * Validate the form */ protected function validateForm() { if ($this->frm->isSubmitted()) { $this->frm->cleanupFields(); // validation $fields = $this->frm->getFields(); // required fields $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(); if ($this->frm->isCorrect()) { // build the item $item['language'] = BL::getWorkingLanguage(); $item['price'] = $fields['price']->getValue(); $item['summary'] = $fields['summary_nl']->getValue(); $item['text'] = $fields['text_nl']->getValue(); $item['allow_comments'] = $fields['allow_comments']->getChecked() ? 'Y' : 'N'; $item['num_comments'] = 0; $item['sequence'] = BackendCatalogModel::getMaximumSequence() + 1; $item['category_id'] = $fields['category_id']->getValue(); $item['brand_id'] = $fields['brand_id']->getValue(); $item['meta_id'] = $this->meta->save(); $item['ballcolor'] = $fields['ballcolor']->getValue(); $item['frontpage'] = $fields['frontpage']->getChecked(); $item['contact'] = $fields['contact']->getChecked(); // insert it $item['id'] = BackendCatalogModel::insert($item); //--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['text'] = $this->frm->getField('text_' . $language)->getValue(); $itemLanguage['summary'] = $this->frm->getField('summary_' . $language)->getValue(); $itemLanguage['url'] = BackendCatalogModel::getURLLanguage($this->frm->getField('title_' . $language)->getValue(), null, $language); $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue(); BackendCatalogModel::insertLanguage($itemLanguage); } $specificationArray = array(); // loop trough specifications and insert values foreach ($this->specifications as $specification) { // build the specification $specificationArray['product_id'] = $item['id']; $specificationArray['specification_id'] = $specification['id']; foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) { $field = 'specification' . $specification['id'] . '_' . $language; // check if there is an value if ($fields[$field]->getValue() != null) { $specificationArray['value'] = $fields[$field]->getValue(); $specificationArray['language'] = $language; // insert specification with product id and value BackendCatalogModel::insertSpecificationValue($specificationArray); } } } // save the tags BackendTagsModel::saveTags($item['id'], $fields['tags']->getValue(), $this->URL->getModule()); // save the related products BackendCatalogModel::saveRelatedProducts($item['id'], $this->frm->getField('related_products')->getValue()); // 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())); // trigger event BackendModel::triggerEvent($this->getModule(), 'after_add', $item); // redirect page $this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']); } } }