public function discount_add() { $inputData = array("type" => "discount"); $mode = (string) getRequest('param0'); if ($mode == "do") { $data = getArrayKey(getRequest('data'), 'new'); //Create new dicsount $discountName = getRequest('name'); $discountTypeId = getArrayKey($data, 'discount_type_id'); try { $discount = discount::add($discountName, $discountTypeId); //Apply modificator $modificatorId = getArrayKey($data, 'discount_modificator_id'); try { $modificatorTypeObject = $this->expectObject($modificatorId, true, true); } catch (publicAdminException $e) { if ($discount) { $discount->delete(); } $this->errorNewMessage(getLabel('error-modificator-required')); $this->errorPanic(); } $modificatorObject = discountModificator::create($discount, $modificatorTypeObject); $discount->setDiscountModificator($modificatorObject); //Apply rules $rulesId = getArrayKey($data, 'discount_rules_id'); foreach ($rulesId as $ruleId) { $ruleTypeObject = $this->expectObject($ruleId, true, true); $ruleObject = discountRule::create($discount, $ruleTypeObject); if ($ruleObject instanceof discountRule == false) { $discount->delete(); throw new publicAdminException("discountRule #{$ruleId} \"{$ruleTypeObject->name}\" class not found"); } $discount->appendDiscountRule($ruleObject); } $discount->commit(); } catch (valueRequiredException $e) { $this->errorNewMessage($e->getMessage()); $this->errorPanic(); } $this->chooseRedirect($this->pre_lang . "/admin/emarket/discount_edit/" . $discount->getId() . "/"); } $this->setDataType("form"); $this->setActionType("create"); $data = $this->prepareData($inputData, "object"); $this->setData($data); return $this->doData(); }