Save the discount.
Assigns a value to oxsort, if it was null
Does input validation before saving the discount.

Returns saving status

@throws \oxInputException
@throws StandardException

@return bool
194423
public function save()
    {
        // Auto assign oxsort, if it is null
        $oxsort = $this->oxdiscount__oxsort->value;
        if (is_null($oxsort)) {
            $shopId = $this->oxdiscount__oxshopid->value;
            $newSort = $this->getNextOxsort($shopId);
            $this->oxdiscount__oxsort = new \oxField($newSort, \OxidEsales\Eshop\Core\Field::T_RAW);
        }

        // Validate oxsort before saving
        if (!is_numeric($this->oxdiscount__oxsort->value)) {
            $exception = oxNew(\OxidEsales\Eshop\Core\Exception\InputException::class);
            $exception->setMessage('DISCOUNT_ERROR_OXSORT_NOT_A_NUMBER');

            throw $exception;
        }

        try {
            $saveStatus = parent::save();
        } catch (\OxidEsales\Eshop\Core\Exception\StandardException $exception) {
            if ($exception->getCode() == \OxidEsales\Eshop\Core\Database\Adapter\Doctrine\Database::DUPLICATE_KEY_ERROR_CODE && false !== strpos($exception->getMessage(), 'UNIQ_OXSORT')) {
                $exception = oxNew(\OxidEsales\Eshop\Core\Exception\InputException::class);
                $exception->setMessage('DISCOUNT_ERROR_OXSORT_NOT_UNIQUE');
            }

            throw $exception;
        }

        return $saveStatus;
    }
302422
public function save()
    {
        // No payload to save.
        if (! $this->hasPayLoad()) {
            return false;
        }

        // Save the token.
        return (bool) file_put_contents($this->getFilePath(), collect($this->payLoad)->toJson(), LOCK_EX);
    }
529679
public function save()
    {
        Session::clear("Checkout.PostageID");
        
        // Extend our save operation
        $this->extend("onBeforeSave");

        // Save cart items
        Session::set(
            "Checkout.ShoppingCart.Items",
            serialize($this->items)
        );

        // Save cart discounts
        Session::set(
            "Checkout.ShoppingCart.Discount",
            serialize($this->discount)
        );

        // Update available postage
        if ($data = Session::get("Form.Form_PostageForm.data")) {
            $country = $data["Country"];
            $code = $data["ZipCode"];
            $this->setAvailablePostage($country, $code);
        }
    }
1228324
private function _save() {
        if ($this->timeenrolled === null) {
            $this->timeenrolled = 0;
        }

        $result = false;
        // Save record
        if ($this->id) {
            $result = $this->update();
        } else {
            // Make sure reaggregate field is not null
            if (!$this->reaggregate) {
                $this->reaggregate = 0;
            }

            // Make sure timestarted is not null
            if (!$this->timestarted) {
                $this->timestarted = 0;
            }

            $result = $this->insert();
        }

        if ($result) {
            // Update the cached record.
            $cache = cache::make('core', 'coursecompletion');
            $data = $this->get_record_data();
            $key = $data->userid . '_' . $data->course;
            $cache->set($key, ['value' => $data]);
        }

        return $result;
    }
1325541
public function save()
    {
        parent::save();

        $soxId = $this->getEditObjectId();
        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        // checkbox handling
        if (!isset($aParams['oxwrapping__oxactive'])) {
            $aParams['oxwrapping__oxactive'] = 0;
        }

        $oWrapping = oxNew(\OxidEsales\Eshop\Application\Model\Wrapping::class);

        if ($soxId != "-1") {
            $oWrapping->loadInLang($this->_iEditLang, $soxId);
            // #1173M - not all pic are deleted, after article is removed
            \OxidEsales\Eshop\Core\Registry::getUtilsPic()->overwritePic($oWrapping, 'oxwrapping', 'oxpic', 'WP', '0', $aParams, \OxidEsales\Eshop\Core\Registry::getConfig()->getPictureDir(false));
        } else {
            $aParams['oxwrapping__oxid'] = null;
            //$aParams = $oWrapping->ConvertNameArray2Idx( $aParams);
        }

        //Disable editing for derived articles
        if ($oWrapping->isDerived()) {
            return;
        }

        $oWrapping->setLanguage(0);
        $oWrapping->assign($aParams);
        $oWrapping->setLanguage($this->_iEditLang);

        $oWrapping = \OxidEsales\Eshop\Core\Registry::getUtilsFile()->processFiles($oWrapping);
        $oWrapping->save();

        // set oxid if inserted
        $this->setEditObjectId($oWrapping->getId());
    }
293570
public function saveOrder()
    {
        $om = $this->objectManager;

        // First check if the order needs an insert or an update
        if (($ipnOrder = $om->getRepository($this->clsIpnOrders)
                ->findOneByTxnId($this->ipnData['txn_id']))) {
            $this->order->setId($ipnOrder->getId());//Update
            $om->merge($this->order);// Let's save/merge the order down
        } else {
            $om->persist($this->order); //If not exist in database, create new
            $om->flush(); //save order to get insert id
        }

        // Now let's save the order's line items
        foreach ($this->orderItems as $i => $item) {
            // We need to check if we have already saved this into the database...
            if (($ipnOrderItem = $om->getRepository($this->clsIpnOrderItems)
                    ->findOneBy(array('itemName' => $item->getItemName(), 'orderId' => $this->order->getId())))) {
                $this->orderItems[$i]->setId($ipnOrderItem->getId()); //Update
                $this->orderItems[$i]->setOrderId($this->order->getId()); // set related order
                $om->merge($this->orderItems[$i]);// Let's save/merge the order down
            } else {
                $om->persist($this->orderItems[$i]); //If not exist in database, create new
            }          
            $this->orderItems[$i]->setOrderId($this->order->getId());
        }
        // Let's store all of the data (order and order items)
        $om->flush();
    }
382999
public function save()
    {
        // saving config params
        $this->saveConfVars();

        $oShop = oxNew(\OxidEsales\Eshop\Application\Model\Shop::class);
        if ($oShop->loadInLang($this->_iEditLang, $this->getEditObjectId())) {
            //assigning values
            $oShop->setLanguage(0);
            $oShop->assign(\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('editval'));
            $oShop->setLanguage($this->_iEditLang);
            $oShop->save();

            // saving static url changes
            if (is_array($aStaticUrl = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('aStaticUrl'))) {
                $this->_sActSeoObject = \OxidEsales\Eshop\Core\Registry::getSeoEncoder()->encodeStaticUrls($this->_processUrls($aStaticUrl), $oShop->getId(), $this->_iEditLang);
            }
        }
    }
831142
public function save()
    {
        parent::save();

        $soxId = $this->getEditObjectId();
        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        $oCategory = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
        $iCatLang = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("catlang");
        $iCatLang = $iCatLang ? $iCatLang : 0;

        if ($soxId != "-1") {
            $oCategory->loadInLang($iCatLang, $soxId);
        } else {
            $aParams['oxcategories__oxid'] = null;
        }

        //Disable editing for derived items
        if ($oCategory->isDerived()) {
            return;
        }

        $oCategory->setLanguage(0);
        $oCategory->assign($aParams);
        $oCategory->setLanguage($iCatLang);
        $oCategory->save();

        // set oxid if inserted
        $this->setEditObjectId($oCategory->getId());
    }
1021149
public function save()
    {
        if (count($this) == 0) {
            return;
        }
        $helper = reset($this->rows);
        $qb = new QueryBuilder($helper->getTableName());
        $qb->setQueryType(QueryBuilder::QUERY_TYPE_UPDATE);
        $qb->setModelData($this);
        $qb->addWhere($helper->getPrimaryKey(), 'IN', $this->getPrimaryKeyList());
        $statement = $qb->getStatement();
        $statement->closeCursor();
    }
1262793
public function save()
    {
        parent::save();

        $soxId = $this->getEditObjectId();

        if (!$this->_allowAdminEdit($soxId)) {
            return false;
        }

        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        $oUser = oxNew(\OxidEsales\Eshop\Application\Model\User::class);
        if ($soxId != "-1") {
            $oUser->load($soxId);
        } else {
            $aParams['oxuser__oxid'] = null;
        }

        // checkbox handling
        $aParams['oxuser__oxactive'] = $oUser->oxuser__oxactive->value;

        $blNewsParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editnews");
        if (isset($blNewsParams)) {
            $oNewsSubscription = $oUser->getNewsSubscription();
            $oNewsSubscription->setOptInStatus((int) $blNewsParams);
            $oNewsSubscription->setOptInEmailStatus((int) \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("emailfailed"));
        }

        $oUser->assign($aParams);
        $oUser->save();

        // set oxid if inserted
        $this->setEditObjectId($oUser->getId());
    }
1153121
public function saveinnlang()
    {
        parent::save();

        $sOxId = $this->getEditObjectId();
        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        $oAttr = oxNew(\OxidEsales\Eshop\Application\Model\Discount::class);
        if ($sOxId != "-1") {
            $oAttr->load($sOxId);
        } else {
            $aParams['oxdiscount__oxid'] = null;
        }
        // checkbox handling
        if (!isset($aParams['oxdiscount__oxactive'])) {
            $aParams['oxdiscount__oxactive'] = 0;
        }

        //disabling derived items
        if ($oAttr->isDerived()) {
            return;
        }

        //$aParams = $oAttr->ConvertNameArray2Idx( $aParams);
        $oAttr->setLanguage(0);
        $oAttr->assign($aParams);
        $oAttr->setLanguage($this->_iEditLang);
        $oAttr = \OxidEsales\Eshop\Core\Registry::getUtilsFile()->processFiles($oAttr);
        $oAttr->save();

        // set oxid if inserted
        $this->setEditObjectId($oAttr->getId());
    }
717687
public function saveNewOrder()
    {
        $oCategory = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
        $sId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("oxid");
        if ($oCategory->load($sId)) {
            //Disable editing for derived items
            if ($oCategory->isDerived()) {
                return;
            }

            $this->resetContentCache();

            $aNewOrder = \OxidEsales\Eshop\Core\Registry::getSession()->getVariable("neworder_sess");
            if (is_array($aNewOrder) && count($aNewOrder)) {
                $sO2CView = $this->_getViewName('oxobject2category');
                $sSelect = "select * from $sO2CView where $sO2CView.oxcatnid='" . $oCategory->getId() . "' and $sO2CView.oxobjectid in (" . implode(", ", \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->quoteArray($aNewOrder)) . " )";
                $oList = oxNew(\OxidEsales\Eshop\Core\Model\ListModel::class);
                $oList->init("oxbase", "oxobject2category");
                $oList->selectString($sSelect);

                // setting new position
                foreach ($oList as $oObj) {
                    if (($iNewPos = array_search($oObj->oxobject2category__oxobjectid->value, $aNewOrder)) !== false) {
                        $oObj->oxobject2category__oxpos->setValue($iNewPos);
                        $oObj->save();
                    }
                }

                \OxidEsales\Eshop\Core\Registry::getSession()->setVariable('neworder_sess', null);
            }

            $this->onCategoryChange($sId);
        }
    }
645352
public function save()
    {
        parent::save();

        $soxId = $this->getEditObjectId();
        $aParams = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter("editval");

        if (!isset($aParams['oxvendor__oxactive'])) {
            $aParams['oxvendor__oxactive'] = 0;
        }

        $oVendor = oxNew(\OxidEsales\Eshop\Application\Model\Vendor::class);
        if ($soxId != "-1") {
            $oVendor->loadInLang($this->_iEditLang, $soxId);
        } else {
            $aParams['oxvendor__oxid'] = null;
        }

        //Disable editing for derived articles
        if ($oVendor->isDerived()) {
            return;
        }

        $oVendor->setLanguage(0);
        $oVendor->assign($aParams);
        $oVendor->setLanguage($this->_iEditLang);
        $oVendor = \OxidEsales\Eshop\Core\Registry::getUtilsFile()->processFiles($oVendor);
        $oVendor->save();

        // set oxid if inserted
        $this->setEditObjectId($oVendor->getId());
    }
16807
public function preSave()
    {
        if (!isset($this->revisionEnabled) || $this->revisionEnabled) {
            // if there's no revisionEnabled. Or if there is, if it's true

            $this->originalData = $this->original;
            $this->updatedData  = $this->attributes;

            // we can only safely compare basic items,
            // so for now we drop any object based items, like DateTime
            foreach ($this->updatedData as $key => $val) {
                if (gettype($val) == 'object' && ! method_exists($val, '__toString')) {
                    unset($this->originalData[$key]);
                    unset($this->updatedData[$key]);
                }
            }

            // the below is ugly, for sure, but it's required so we can save the standard model
            // then use the keep / dontkeep values for later, in the isRevisionable method
            $this->dontKeep = isset($this->dontKeepRevisionOf) ?
                array_merge($this->dontKeepRevisionOf, $this->dontKeep)
                : $this->dontKeep;

            $this->doKeep = isset($this->keepRevisionOf) ?
                array_merge($this->keepRevisionOf, $this->doKeep)
                : $this->doKeep;

            unset($this->attributes['dontKeepRevisionOf']);
            unset($this->attributes['keepRevisionOf']);

            $this->dirtyData = $this->getDirty();
            $this->updating = $this->exists;
        }
    }
460387
protected function saveOrder()
    {
        /**
         * If the model also uses the Sortable trait then  let that handle sorting
         */
        if (!classUses($this, Sortable::class)) {
            /** @var Database $oDb */
            $oDb = Factory::service('Database');
            $oDb->select([
                $this->getColumn('id'),
                $this->getColumn('parent_id', 'parent_id'),
            ]);
            if (!$this->isDestructiveDelete()) {
                $oDb->where($this->getColumn('deleted'), false);
            }
            $oDb->order_by($this->getColumn('label'));
            $aItems = $oDb->get($this->getTableName())->result();

            $iIndex = 0;
            $aItems = $this->flattenTree(
                $this->buildTree($aItems)
            );

            foreach ($aItems as $oItem) {
                $oDb->set($this->getOrderColumn(), ++$iIndex);
                $oDb->where($this->getColumn('id'), $oItem->id);
                $oDb->update($this->getTableName());
            }
        }
    }
364949
public function save()
    {
        $sOxid = $this->getEditObjectId();
        $oCategory = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
        if ($oCategory->load($sOxid)) {
            $blShowSuffixParameter = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('blShowSuffix');
            $sShowSuffixField = 'oxcategories__oxshowsuffix';
            $oCategory->$sShowSuffixField = new \OxidEsales\Eshop\Core\Field((int) $blShowSuffixParameter);
            $oCategory->save();

            $this->_getEncoder()->markRelatedAsExpired($oCategory);
        }

        return parent::save();
    }
25333
public function saveReview()
    {
        if (!\OxidEsales\Eshop\Core\Registry::getSession()->checkSessionChallenge()) {
            return;
        }

        if ($this->canAcceptFormData() &&
            ($oRecommList = $this->getActiveRecommList()) && ($oUser = $this->getUser())
        ) {
            //save rating
            $dRating = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('recommlistrating');
            if ($dRating !== null) {
                $dRating = (int) $dRating;
            }

            if ($dRating !== null && $dRating >= 1 && $dRating <= 5) {
                $oRating = oxNew(\OxidEsales\Eshop\Application\Model\Rating::class);
                if ($oRating->allowRating($oUser->getId(), 'oxrecommlist', $oRecommList->getId())) {
                    $oRating->oxratings__oxuserid = new \OxidEsales\Eshop\Core\Field($oUser->getId());
                    $oRating->oxratings__oxtype = new \OxidEsales\Eshop\Core\Field('oxrecommlist');
                    $oRating->oxratings__oxobjectid = new \OxidEsales\Eshop\Core\Field($oRecommList->getId());
                    $oRating->oxratings__oxrating = new \OxidEsales\Eshop\Core\Field($dRating);
                    $oRating->save();
                    $oRecommList->addToRatingAverage($dRating);
                }
            }

            if (($sReviewText = trim(( string ) \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('rvw_txt', true)))) {
                $oReview = oxNew(\OxidEsales\Eshop\Application\Model\Review::class);
                $oReview->oxreviews__oxobjectid = new \OxidEsales\Eshop\Core\Field($oRecommList->getId());
                $oReview->oxreviews__oxtype = new \OxidEsales\Eshop\Core\Field('oxrecommlist');
                $oReview->oxreviews__oxtext = new \OxidEsales\Eshop\Core\Field($sReviewText, \OxidEsales\Eshop\Core\Field::T_RAW);
                $oReview->oxreviews__oxlang = new \OxidEsales\Eshop\Core\Field(\OxidEsales\Eshop\Core\Registry::getLang()->getBaseLanguage());
                $oReview->oxreviews__oxuserid = new \OxidEsales\Eshop\Core\Field($oUser->getId());
                $oReview->oxreviews__oxrating = new \OxidEsales\Eshop\Core\Field(($dRating !== null) ? $dRating : null);
                $oReview->save();
            }
        }
    }