Saves the vouchers passed to the order to the shop_voucher_use table
Note: this will only work if the order has an id.
Also Note: existing voucher uses will NOT be removed.

@param TShopBasketVoucherList $oBasketVoucherList
961859
public function SaveVouchers(TShopBasketVoucherList $oBasketVoucherList)
    {
        if (!is_null($this->id) && !is_null($oBasketVoucherList) && $oBasketVoucherList->Length() > 0) {
            $oBasketVoucherList->GoToStart();
            while ($oVoucherItemUsed = $oBasketVoucherList->Next()) {
                $oVoucherItemUsed->CommitVoucherUseForCurrentUser($this->id);
            }
        }
    }
622136
protected function CheckBasketVoucherAvailable($sMessageConsumer)
    {
        $bBasketVoucherAvailable = true;
        $oVoucherList = $this->GetVoucherList();
        $oMessageManager = TCMSMessageManager::GetInstance();
        if ($oVoucherList) {
            if ($oVoucherList->Length() > 0) {
                $oVoucherList->GoToStart();
                while ($oBasketVoucher = $oVoucherList->Next()) {
                    $sVoucherCode = $oBasketVoucher->fieldCode;
                    $sBasketVoucherKey = $oBasketVoucher->sBasketVoucherKey;
                    $sBasketVoucherSeriesId = $oBasketVoucher->fieldShopVoucherSeriesId;
                    $oVoucher = TdbShopVoucher::GetNewInstance();
                    $bVoucherLoaded = $oVoucher->Load($oBasketVoucher->id);
                    if (($bVoucherLoaded && $oVoucher->fieldIsUsedUp) || !$bVoucherLoaded) {
                        $oNextAvailableVoucher = $this->GetNextAvailableVoucher($sVoucherCode, $sBasketVoucherSeriesId, $sMessageConsumer);

                        /**
                         * next voucher with same code is available, so auto add that one.
                         * as we do not want to inform the customer that this happened,
                         * we create a temporary message consumer for RemoveVoucher and AddVoucher messages and clear them afterwards.
                         */
                        if (!is_null($oNextAvailableVoucher)) {
                            $this->RemoveVoucher($sBasketVoucherKey, $sMessageConsumer.'-TO-BE-REMOVED');
                            $this->AddVoucher($oNextAvailableVoucher, $sMessageConsumer.'-TO-BE-REMOVED');
                            $oMessageManager->ClearMessages($sMessageConsumer.'-TO-BE-REMOVED');
                        } else {
                            $this->RemoveVoucher($sBasketVoucherKey, $sMessageConsumer);
                            $bBasketVoucherAvailable = false;
                            $this->bMarkAsRecalculationNeeded = true;
                            $oMsgManager = TCMSMessageManager::GetInstance();
                            $oMsgManager->AddMessage($sMessageConsumer, 'ERROR-ORDER-REQUEST-VOUCHER-NOT-LONGER-AVAILABLE', array('sVoucherCode' => $sVoucherCode));
                        }
                    }
                }
            }
        }

        return $bBasketVoucherAvailable;
    }
1151879
protected function getVatList(TdbShopOrder $oOrder, IMapperCacheTriggerRestricted $oCacheTriggerManager, $bCachingEnabled)
    {
        $aVat = array();

        $oVatList = &$oOrder->GetFieldShopOrderVatList();
        $oVatList->GoToStart();
        if (0 < $oVatList->Length()) {
            while ($oVat = &$oVatList->Next()) {
                $dVatValue = $oVat->fieldValue;
                if (0 == $dVatValue) {
                    continue;
                }
                if ($bCachingEnabled) {
                    $oCacheTriggerManager->addTrigger($oVat->table, $oVat->id);
                }
                $aVatTmp = array('sName' => $oVat->fieldName, 'iPercent' => $oVat->fieldVatPercent, 'sPercent' => $oVat->fieldVatPercentFormated, 'dValue' => $dVatValue, 'sValue' => TCMSLocal::GetActive()->FormatNumber($dVatValue, 2));
                $aVat[] = $aVatTmp;
            }
            $oVatList->GoToStart();
        }

        return $aVat;
    }
895610
protected function getActiveOrder(TdbShopOrderList $oOrderList)
    {
        $sActiveOrderParameter = $this->GetActiveOrderRequest();
        if (false !== $sActiveOrderParameter) {
            $oOrderList->AddFilterString("`shop_order`.`ordernumber` = '".$sActiveOrderParameter."'");
            $oOrderList->GoToStart();

            if (0 < $oOrderList->Length()) {
                return $oOrderList->Current();
            }
        }

        return null;
    }
1312317
public function getVoucherList()
    {
        $oVoucherList = oxNew(\OxidEsales\Eshop\Application\Model\VoucherList::class);
        $sSelect = 'select * from oxvouchers where oxvoucherserieid = ' . \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->quote($this->getId());
        $oVoucherList->selectString($sSelect);

        return $oVoucherList;
    }
889855
protected function _storeServices( MShop_Order_Item_Base_Interface $basket )
	{
		$manager = $this->getSubManager( 'service' );
		$attrManager = $manager->getSubManager( 'attribute' );

		foreach( $basket->getServices() as $type => $item )
		{
			$item->setBaseId( $basket->getId() );
			$item->setType( $type );
			$manager->saveItem( $item );

			foreach( $item->getAttributes() as $attribute )
			{
				$attribute->setServiceId( $item->getId() );
				$attrManager->saveItem( $attribute );
			}
		}
	}
1160
public function validatePayment($oBasket)
    {
        $paymentId = $oBasket->getPaymentId();

        if (!$this->isValidPaymentId($paymentId) || !$this->isValidPayment($oBasket)) {
            return self::ORDER_STATE_INVALIDPAYMENT;
        }
    }
427707
public function AddVoucher(TdbShopVoucher &$oVoucher, $sMessageHandler)
    {
        $bVoucherAdded = false;
        $oMessageManager = TCMSMessageManager::GetInstance();

        $oVoucherSeries = $oVoucher->GetFieldShopVoucherSeries();
        $aMessageData = $oVoucherSeries->GetObjectPropertiesAsArray();
        $aVoucherData = $oVoucher->GetObjectPropertiesAsArray();
        $aMessageData = array_merge($aMessageData, $aVoucherData);

        $cAllowUseOfVoucherResult = $oVoucher->AllowUseOfVoucher();
        if (TdbShopVoucher::ALLOW_USE != $cAllowUseOfVoucherResult) {
            if (TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_GROUP_MISSING_LOGIN == $cAllowUseOfVoucherResult ||
               TdbShopVoucher::USE_ERROR_NOT_VALID_FOR_CUSTOMER_MISSING_LOGIN == $cAllowUseOfVoucherResult) {
                $oExtranet = TdbDataExtranet::GetInstance();
                if (!is_null($oExtranet)) {
                    $aMessageData['sLinkLoginStart'] = '<a href="'.$oExtranet->GetLinkLoginPage().'">';
                    $aMessageData['sLinkLoginEnd'] = '</a>';
                }
            }
            $oMessageManager->AddMessage($sMessageHandler, 'VOUCHER-ERROR-'.$cAllowUseOfVoucherResult, $aMessageData);
        } else {
            $this->GetActiveVouchers()->AddItem($oVoucher);
            $oMessageManager->AddMessage($sMessageHandler, 'VOUCHER-ADDED', $aMessageData);
            $bVoucherAdded = true;
            $this->SetBasketRecalculationFlag();
        }

        return $bVoucherAdded;
    }
126214
public function store( MShop_Order_Item_Base_Interface $basket )
	{
		$this->saveItem( $basket );

		$this->_storeProducts( $basket );
		$this->_storeCoupons( $basket );
		$this->_storeAddresses( $basket );
		$this->_storeServices( $basket );
	}
176332
protected function _basketDifference(\OxidEsales\Eshop\Application\Model\Basket $oBasket)
    {
        $aDiff = $this->_getReservedItems();
        // refreshing history
        foreach ($oBasket->getContents() as $oItem) {
            $sProdId = $oItem->getProductId();
            if (!isset($aDiff[$sProdId])) {
                $aDiff[$sProdId] = -$oItem->getAmount();
            } else {
                $aDiff[$sProdId] -= $oItem->getAmount();
            }
        }

        return $aDiff;
    }
353751
public function exportVouchers($iStart)
    {
        $iExported = false;

        if ($oSerie = $this->_getVoucherSerie()) {
            $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);

            $sSelect = "select oxvouchernr from oxvouchers where oxvoucherserieid = " . $oDb->quote($oSerie->getId());
            $rs = $oDb->selectLimit($sSelect, $this->iExportPerTick, $iStart);

            if (!$rs->EOF) {
                $iExported = 0;

                // writing header text
                if ($iStart == 0) {
                    $this->write(\OxidEsales\Eshop\Core\Registry::getLang()->translateString("VOUCHERSERIE_MAIN_VOUCHERSTATISTICS", \OxidEsales\Eshop\Core\Registry::getLang()->getTplLanguage(), true));
                }
            }

            // writing vouchers..
            while (!$rs->EOF) {
                $this->write(current($rs->fields));
                $iExported++;
                $rs->fetchRow();
            }
        }

        return $iExported;
    }
498216
protected function _setValues(& $aPaymentList, $oBasket = null)
    {
        if (is_array($aPaymentList)) {
            foreach ($aPaymentList as $oPayment) {
                $oPayment->calculate($oBasket);
                $oPayment->aDynValues = $oPayment->getDynValues();
                if ($oPayment->oxpayments__oxchecked->value) {
                    $this->_sCheckedId = $oPayment->getId();
                }
            }
        }
    }
307764
public static function getAvailableShippingGroupsForBasketArticleListAndCountry($oBasketArticleList, $sDataCountryId)
    {
        $oBasketArticleList->GoToStart();

        $oOldBasket = clone TShopBasket::GetInstance();
        $oOldUser = clone TdbDataExtranetUser::GetInstance();

        $oTmpBasket = new TShopBasket();
        /** @var Request $request */
        $request = \ChameleonSystem\CoreBundle\ServiceLocator::get('request_stack')->getCurrentRequest();
        $request->getSession()->set(TShopBasket::SESSION_KEY_NAME, $oTmpBasket);

        $oTmpUser = TdbDataExtranetUser::GetNewInstance();
        $oTmpUser->sqlData['data_country_id'] = $sDataCountryId;
        $oTmpUser->sqlData['city'] = 'Dummy';
        $oTmpUser->sqlData['lastname'] = 'Dummy';
        $oTmpShippingAddress = TdbDataExtranetUserAddress::GetNewInstance();
        $oTmpShippingAddress->fieldDataCountryId = $sDataCountryId;
        $oTmpShippingAddress->sqlData['data_country_id'] = $sDataCountryId;
        $oTmpUser->setFakedShippingAddressForUser($oTmpShippingAddress);

        $request->getSession()->set(TdbDataExtranetUser::SESSION_KEY_NAME, $oTmpUser);

        while ($oBasketArticle = $oBasketArticleList->Next()) {
            $oNewBasketArticle = new TShopBasketArticle();
            $oNewBasketArticle->Load($oBasketArticle->id);
            $oNewBasketArticle->dAmount = $oBasketArticle->dAmount;
            $oTmpBasket->AddItem($oNewBasketArticle);
        }

        $oTmpBasket->RecalculateBasket();
        $oTmpBasket->ResetAllShippingMarkers();

        $oList = $oTmpBasket->GetAvailableShippingGroups();

        $request->getSession()->set(TShopBasket::SESSION_KEY_NAME, $oOldBasket);
        $request->getSession()->set(TdbDataExtranetUser::SESSION_KEY_NAME, $oOldUser);

        return $oList;
    }
1359635
protected function _save()
    {
        if ($this->isSaveToDataBaseEnabled()) {
            if ($oUser = $this->getBasketUser()) {
                //first delete all contents
                //#2039
                $oSavedBasket = $oUser->getBasket('savedbasket');
                $oSavedBasket->delete();

                //then save
                /** @var \oxBasketItem $oBasketItem */
                foreach ($this->_aBasketContents as $oBasketItem) {
                    // discount or bundled products will be added automatically if available
                    if (!$oBasketItem->isBundle() && !$oBasketItem->isDiscountArticle()) {
                        $oSavedBasket->addItemToBasket($oBasketItem->getProductId(), $oBasketItem->getAmount(), $oBasketItem->getSelList(), true, $oBasketItem->getPersParams());
                    }
                }
            }
        }
    }
308635
protected function _validateBasket($oBasket)
    {
        $aCurrentContent = $oBasket->getContents();
        $iCurrLang = $this->getLanguage()->getBaseLanguage();

        /** @var oxBasketItem $oContent */
        foreach ($aCurrentContent as $oContent) {
            if ($oContent->getLanguageId() !== $iCurrLang) {
                $oContent->setLanguageId($iCurrLang);
            }
        }
    }
91375
protected function &GetBasketArticles()
    {
        if (is_null($this->oBasketArticles)) {
            $this->oBasketArticles = new TShopBasketArticleList();
        }
        // attach basket as observer - but on first call only
        $this->oBasketArticles->ObserverRegister('oBasketInstance', $this);

        return $this->oBasketArticles;
    }
1156100
public function ArticleListValidForShippingType(TShopBasketArticleList &$oArticleList)
    {
        $bIsValid = true;
        $dArticleValue = $oArticleList->dProductPrice;
        $dNumberOfArticles = $oArticleList->dNumberOfItems;
        $dArticleWeight = $oArticleList->dTotalWeight;
        $dArticleVolume = $oArticleList->dTotalVolume;

        if ($this->fieldValueBasedOnEntireBasket) {
            $oBasket = TShopBasket::GetInstance();
            $dArticleValue = $oBasket->dCostArticlesTotalAfterDiscounts;
        }
        if ($this->fieldApplyToAllProducts) {
            $oBasket = TShopBasket::GetInstance();
            $dNumberOfArticles = $oBasket->dTotalNumberOfArticles;
            $dArticleWeight = $oBasket->dTotalWeight;
            $dArticleVolume = $oBasket->dTotalVolume;
        }

        $bValueOk = ($this->fieldRestrictToValueFrom <= $dArticleValue && (0 == $this->fieldRestrictToValueTo || $this->fieldRestrictToValueTo >= $dArticleValue));

        $bNumberOfArticlesOk = ($this->fieldRestrictToArticlesFrom <= $dNumberOfArticles && (0 == $this->fieldRestrictToArticlesTo || $this->fieldRestrictToArticlesTo >= $dNumberOfArticles));

        $bArticleWeightOk = ($this->fieldRestrictToWeightFrom <= $dArticleWeight && (0 == $this->fieldRestrictToWeightTo || $this->fieldRestrictToWeightTo >= $dArticleWeight));

        $bArticleVolumeOk = ($this->fieldRestrictToVolumeFrom <= $dArticleVolume && (0 == $this->fieldRestrictToVolumeTo || $this->fieldRestrictToVolumeTo >= $dArticleVolume));

        $bIsValid = ($bValueOk && $bNumberOfArticlesOk && $bArticleWeightOk && $bArticleVolumeOk);

        return $bIsValid;
    }