fill the order object with data from the basket
NOTE: this fills the base order only. None of the lists (article, vat, etc) will be added yet.

@param TShopBasket $oBasket
779213
public function LoadFromBasket(TShopBasket &$oBasket)
    {
        $oShop = TdbShop::GetInstance();
        $oPortal = $this->getPortalDomainService()->getActivePortal();
        $oUser = TdbDataExtranetUser::GetInstance();
        $oBillingAdr = $oUser->GetBillingAddress();

        $sAffiliateCode = $oShop->GetAffilateCode();
        if (false === $sAffiliateCode) {
            $sAffiliateCode = '';
        }

        $pkg_shop_affiliate_id = '';
        $oAffiliatePartnerProgram = TdbPkgShopAffiliate::GetActiveInstance();
        if ($oAffiliatePartnerProgram) {
            if (!empty($oAffiliatePartnerProgram->sCode)) {
                $pkg_shop_affiliate_id = $oAffiliatePartnerProgram->id;
            }
        }
        $request = $this->getCurrentRequest();
        $aOrderData = array(
            'shop_id' => $oShop->id,
            'cms_portal_id' => $oPortal->id,
            'ordernumber' => '',
            'order_ident' => $oBasket->sBasketIdentifier,
            'data_extranet_user_id' => $oUser->id,
            'user_email' => $oUser->GetUserEMail(),
            'customer_number' => $oUser->GetCustomerNumber(),
            'vat_id' => $oUser->fieldVatId,
            'adr_billing_company' => $oBillingAdr->fieldCompany,
            'adr_billing_salutation_id' => $oBillingAdr->fieldDataExtranetSalutationId,
            'adr_billing_firstname' => $oBillingAdr->fieldFirstname,
            'adr_billing_lastname' => $oBillingAdr->fieldLastname,
            'adr_billing_street' => $oBillingAdr->fieldStreet,
            'adr_billing_streetnr' => $oBillingAdr->fieldStreetnr,
            'adr_billing_city' => $oBillingAdr->fieldCity,
            'adr_billing_postalcode' => $oBillingAdr->fieldPostalcode,
            'adr_billing_country_id' => $oBillingAdr->fieldDataCountryId,
            'adr_billing_telefon' => $oBillingAdr->fieldTelefon,
            'adr_billing_fax' => $oBillingAdr->fieldFax,
            'adr_shipping_use_billing' => '1',
            'adr_shipping_salutation_id' => '',
            'adr_shipping_company' => '',
            'adr_shipping_firstname' => '',
            'adr_shipping_lastname' => '',
            'adr_shipping_street' => '',
            'adr_shipping_streetnr' => '',
            'adr_shipping_city' => '',
            'adr_shipping_postalcode' => '',
            'adr_shipping_country_id' => '',
            'adr_shipping_telefon' => '',
            'adr_shipping_fax' => '',
            'shop_shipping_group_price' => $oBasket->dCostShipping,
            'shop_payment_method_price' => $oBasket->dCostPaymentMethodSurcharge,
            'value_article' => $oBasket->dCostArticlesTotal,
            'value_total' => $oBasket->dCostTotal,
            'value_wrapping' => $oBasket->dCostWrapping,
            'value_wrapping_card' => $oBasket->dCostWrappingCards,
            'value_vouchers' => $oBasket->dCostVouchers,
            'value_vouchers_not_sponsored' => $oBasket->dCostNoneSponsoredVouchers,
            'value_discounts' => $oBasket->dCostDiscounts,
            'value_vat_total' => $oBasket->dCostVAT,
            'count_articles' => $oBasket->dTotalNumberOfArticles,
            'count_unique_articles' => $oBasket->iTotalNumberOfUniqueArticles,
            'totalweight' => $oBasket->dTotalWeight,
            'totalvolume' => $oBasket->dTotalVolume,
            'affiliate_code' => $sAffiliateCode,
            'pkg_shop_affiliate_id' => $pkg_shop_affiliate_id,
            'cms_language_id' => self::getLanguageService()->getActiveLanguageId(),
            'user_ip' => null === $request ? '' : $request->getClientIp(),
        );
        if (property_exists($oBillingAdr, 'fieldAddressAdditionalInfo')) {
            $aOrderData['adr_billing_additional_info'] = $oBillingAdr->fieldAddressAdditionalInfo;
        }

        $oShippingGroup = $oBasket->GetActiveShippingGroup();
        if ($oShippingGroup) {
            $oShippingVat = $oShippingGroup->GetVat();
            $aOrderData['shop_shipping_group_id'] = $oShippingGroup->id;
            $aOrderData['shop_shipping_group_name'] = $oShippingGroup->fieldName;
            if ($oShippingVat) {
                $aOrderData['shop_shipping_group_vat_percent'] = $oShippingVat->fieldVatPercent;
            }
        }
        $oPayment = $oBasket->GetActivePaymentMethod();
        if ($oPayment) {
            $aOrderData['shop_payment_method_id'] = $oPayment->id;
            $aOrderData['shop_payment_method_name'] = $oPayment->fieldName;
            $oPaymentVat = $oPayment->GetVat();
            if ($oPaymentVat) {
                $aOrderData['shop_payment_method_vat_percent'] = $oPaymentVat->fieldVatPercent;
            }
        }

        if (!$oUser->ShipToBillingAddress()) {
            $oShippingAdr = $oUser->GetShippingAddress();
            $aOrderData['adr_shipping_use_billing'] = '0';
            $aOrderData['adr_shipping_salutation_id'] = $oShippingAdr->fieldDataExtranetSalutationId;
            $aOrderData['adr_shipping_company'] = $oShippingAdr->fieldCompany;
            $aOrderData['adr_shipping_firstname'] = $oShippingAdr->fieldFirstname;
            $aOrderData['adr_shipping_lastname'] = $oShippingAdr->fieldLastname;
            $aOrderData['adr_shipping_street'] = $oShippingAdr->fieldStreet;
            $aOrderData['adr_shipping_streetnr'] = $oShippingAdr->fieldStreetnr;
            $aOrderData['adr_shipping_city'] = $oShippingAdr->fieldCity;
            $aOrderData['adr_shipping_postalcode'] = $oShippingAdr->fieldPostalcode;
            $aOrderData['adr_shipping_country_id'] = $oShippingAdr->fieldDataCountryId;
            $aOrderData['adr_shipping_telefon'] = $oShippingAdr->fieldTelefon;
            $aOrderData['adr_shipping_fax'] = $oShippingAdr->fieldFax;
            if (property_exists($oShippingAdr, 'fieldAddressAdditionalInfo')) {
                $aOrderData['adr_shipping_additional_info'] = $oShippingAdr->fieldAddressAdditionalInfo;
            }
        }
        $this->LoadFromBasketPostProcessData($oBasket, $aOrderData);
        $this->LoadFromRow($aOrderData);
    }
622870
public function postSelectPaymentHook(TdbShop $oShop, TShopBasket $oBasket, TdbDataExtranetUser $oUser, $sMessageConsumer)
    {
        return $this->GetFieldShopPaymentHandler()->PostSelectPaymentHook($sMessageConsumer);
    }
1039195
public function &GetListMatchingVat(TdbShopVat &$oVat)
    {
        $oArticles = new TShopBasketArticleList();
        /** @var $oArticles TShopBasketArticleList */
        $iPointer = $this->getItemPointer();
        $this->GoToStart();
        while ($oItem = &$this->Next()) {
            $oItemVat = $oItem->GetVat();
            if (!is_null($oItemVat) && $oItemVat->id == $oVat->id) {
                $oArticles->AddItem($oItem);
            }
        }

        $this->setItemPointer($iPointer);

        return $oArticles;
    }
902837
protected function &SaveArticle(TShopBasketArticle $oBasketItem)
    {
        $oVat = $oBasketItem->GetVat();
        $oOrderItem = TdbShopOrderItem::GetNewInstance();
        /** @var $oOrderItem TdbShopOrderItem */
        $oManufacturer = TdbShopManufacturer::GetNewInstance();
        $oManufacturer->Load($oBasketItem->fieldShopManufacturerId);
        $aData = array(
            'shop_order_id' => $this->id,
            'basket_item_key' => $oBasketItem->sBasketItemKey,
            'shop_article_id' => $oBasketItem->id,
            'name' => $oBasketItem->fieldName,
            'name_variant_info' => $oBasketItem->fieldNameVariantInfo,
            'articlenumber' => $oBasketItem->fieldArticlenumber,
            'description_short' => $oBasketItem->fieldDescriptionShort,
            'description' => $oBasketItem->fieldDescription,
            'shop_manufacturer_id' => $oBasketItem->fieldShopManufacturerId,
            'shop_manufacturer_name' => $oManufacturer->GetName(),
            'price' => $oBasketItem->fieldPrice,
            'price_reference' => $oBasketItem->fieldPriceReference,
            'vat_percent' => $oVat->fieldVatPercent,
            'size_weight' => $oBasketItem->fieldSizeWeight,
            'size_width' => $oBasketItem->fieldSizeWidth,
            'size_height' => $oBasketItem->fieldSizeHeight,
            'size_length' => $oBasketItem->fieldSizeLength,
            'stock' => $oBasketItem->getAvailableStock(),
            'virtual_article' => $oBasketItem->sqlData['virtual_article'],
            'exclude_from_vouchers' => $oBasketItem->sqlData['exclude_from_vouchers'],
            'subtitle' => $oBasketItem->fieldSubtitle,
            'is_new' => $oBasketItem->sqlData['is_new'],
            'usp' => $oBasketItem->fieldUsp,
            'is_bundle' => $oBasketItem->sqlData['is_bundle'],
            'order_amount' => $oBasketItem->dAmount,
            'order_price' => $oBasketItem->dPrice,
            'order_price_total' => $oBasketItem->dPriceTotal,
            'order_price_after_discounts' => $oBasketItem->dPriceTotalAfterDiscount,
            'order_total_weight' => $oBasketItem->dTotalWeight,
            'order_total_volume' => $oBasketItem->dTotalVolume,
            'download' => $oBasketItem->fieldDownload,
            'price_discounted' => $oBasketItem->dPriceAfterDiscount,
            'exclude_from_discounts' => $oBasketItem->sqlData['exclude_from_discounts'],
            'quantity_in_units' => $oBasketItem->fieldQuantityInUnits,
            'shop_unit_of_measurement_id' => $oBasketItem->fieldShopUnitOfMeasurementId,
            'custom_data' => $oBasketItem->getCustomData(),
        );
        $this->PrepareArticleDataForSave($oBasketItem, $aData);
        $oOrderItem->LoadFromRow($aData);
        $oOrderItem->AllowEditByAll(true);
        $iInsertedOrderArticleId = $oOrderItem->Save();

        //Linking the downloads from BasketItem to OrderItem
        $oDownloadFilesList = $oBasketItem->GetDownloads('download');
        while ($oDownloadFile = $oDownloadFilesList->Next()) {
            $sQuery = "INSERT INTO `shop_order_item_download_cms_document_mlt`
                           SET `source_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($iInsertedOrderArticleId)."',
                               `target_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($oDownloadFile->id)."'";
            MySqlLegacySupport::getInstance()->query($sQuery);
        }

        if ($oBasketItem->fieldIsBundle) {
            // also save bundle articles
            $oBundleArticles = $oBasketItem->GetFieldShopBundleArticleList();
            while ($oBundleArticle = $oBundleArticles->Next()) {
                $this->SaveBundleArticle($oBasketItem, $oOrderItem, $oBundleArticle);
            }
        }

        return $oOrderItem;
    }
174245
public function RemoveInvalidVouchers($sMessangerName, $oBasket = null)
    {
        // since the min value of the basket for which a voucher may work is affected by other vouchers,
        // we need to remove the vouchers first, and then add them one by one back to the basket
        // we suppress the add messages, but keep the negative messages

        if (is_null($oBasket)) {
            $oBasket = TShopBasket::GetInstance();
        }
        $oMessageManager = TCMSMessageManager::GetInstance();

        // get copy of vouchers
        $aVoucherList = $this->_items;
        $this->Destroy();
        $bInvalidVouchersFound = false;
        foreach ($aVoucherList as $iVoucherKey => $oVoucher) {
            /** @var $oVoucher TdbShopVoucher */
            $cVoucherAllowUseCode = $oVoucher->AllowUseOfVoucher();
            if (TdbShopVoucher::ALLOW_USE == $cVoucherAllowUseCode) {
                $this->AddItem($oVoucher);
            } else {
                $bInvalidVouchersFound = true;
                $this->RemoveInvalidVoucherHook($oVoucher, $oBasket);
                // send message that the voucher was removed
                $aMessageData = $oVoucher->GetObjectPropertiesAsArray();
                $aMessageData['iRemoveReasoneCode'] = $cVoucherAllowUseCode;
                $oMessageManager->AddMessage($sMessangerName, 'VOUCHER-ERROR-NO-LONGER-VALID-FOR-BASKET', $aMessageData);
            }
        }

        if ($bInvalidVouchersFound) {
            // recalculate the basket
            $oBasket->RecalculateBasket();
        }
    }
221634
protected function _storeAddresses( MShop_Order_Item_Base_Interface $basket )
	{
		$manager = $this->getSubManager( 'address' );

		foreach( $basket->getAddresses() as $type => $item )
		{
			$item->setBaseId( $basket->getId() );
			$item->setType( $type );
			$manager->saveItem( $item );
		}
	}
108115
protected function _OxpsPaymorrowOxOrder_finalizeOrder_parent( oxBasket $oBasket, $oUser,
                                                                   $blRecalculatingOrder = false )
    {
        return parent::finalizeOrder( $oBasket, $oUser, $blRecalculatingOrder );
    }
1132817
public function SaveArticles(TShopBasketArticleList $oBasketArticleList)
    {
        if (!is_null($this->id)) {
            $oBasketArticleList->GoToStart();
            while ($oBasketItem = $oBasketArticleList->Next()) {
                $this->SaveArticle($oBasketItem);
            }
        }
    }
526375
protected function _preFinalizeOrder(oxBasket &$oBasket, &$oUser, &$blIsAmazonOrder, &$blAuthorizeAsync)
    {
        $blAuthorizeAsync = false;
        $oContainer = $this->_getContainer();
        $oSession = $oContainer->getSession();
        $oUtils = $oContainer->getUtils();
        $oConfig = $oContainer->getConfig();

        $blIsAmazonOrder = $oBasket->getPaymentId() === 'bestitamazon'
            && $oConfig->getRequestParameter('cl') === 'order';

        //Situation when amazonOrderReferenceId was wiped out somehow, do cleanup and redirect
        if ($blIsAmazonOrder === true) {
            $sAmazonOrderReferenceId = (string)$oSession->getVariable('amazonOrderReferenceId');

            if ($sAmazonOrderReferenceId === '') {
                $oUtils->redirect($oConfig->getShopSecureHomeUrl().'cl=user&fnc=cleanAmazonPay', false);
                return false;
            }

            $sBasketHash = $oContainer->getBasketUtil()->getBasketHash($sAmazonOrderReferenceId, $oBasket);
            $sCurrentBasketHash = $oConfig->getRequestParameter('amazonBasketHash');
            $sCurrentBasketHash = $sCurrentBasketHash === null ?
                $oSession->getVariable('sAmazonBasketHash') :
                $sCurrentBasketHash;

            if ($sCurrentBasketHash !== $sBasketHash) {
                $oUtils->redirect($oConfig->getShopSecureHomeUrl().'cl=user&fnc=cleanAmazonPay', false);
                return false;
            }

            //Get Full customer data from Amazon
            $oData = $oContainer->getClient()->getOrderReferenceDetails();
            $sStatus = (string)$oData->GetOrderReferenceDetailsResult
                ->OrderReferenceDetails->OrderReferenceStatus->State;

            if ($sStatus !== 'Open') {
                $oUtils->redirect($oConfig->getShopSecureHomeUrl().'cl=user&fnc=cleanAmazonPay', false);
                return false;
            }

            $blOptimizedFlow = (string)$oConfig->getConfigParam('sAmazonMode')
                === bestitAmazonPay4OxidClient::OPTIMIZED_FLOW;

            //Call Amazon authorize (Dedicated for Sync mode), don't call if ERP mode is enabled
            if ((bool)$oConfig->getConfigParam('blAmazonERP') !== true
                && $this->_callSyncAmazonAuthorize($oBasket, $sAmazonOrderReferenceId, $blOptimizedFlow) === false
            ) {
                if ($blOptimizedFlow === true) {
                    $blAuthorizeAsync = true;
                } else {
                    return false;
                }
            }

            //Manage full user data with user data updates
            $oAmazonData = $oData->GetOrderReferenceDetailsResult->OrderReferenceDetails;
            $oUser = $this->_manageFullUserData($oUser, $oAmazonData);
        }

        return true;
    }
775484
private function validateBasketContentBuyable(TShopBasketArticle $oBasketArticle, $sMessageManager)
    {
        $bValid = true;
        if (false === $oBasketArticle->IsBuyable()) {
            $oMessage = TCMSMessageManager::GetInstance();
            $aErrorCodes = $oBasketArticle->GetSQLWithTablePrefix();
            $oMessage->AddMessage($sMessageManager, 'ERROR-ADD-TO-BASKET-ARTICLE-NOT-BUYABLE', $aErrorCodes);
            if ($this->IsInList($oBasketArticle)) {
                $this->RemoveArticle($oBasketArticle);
            }
            $bValid = false;
        }

        return $bValid;
    }
662523
public function isForBasket($oBasket)
    {
        // initial configuration check
        if ($this->oxdiscount__oxamount->value == 0 && $this->oxdiscount__oxprice->value == 0) {
            return false;
        }

        $oSummary = $oBasket->getBasketSummary();
        // amounts check
        if ($this->oxdiscount__oxamount->value && ($oSummary->iArticleCount < $this->oxdiscount__oxamount->value || $oSummary->iArticleCount > $this->oxdiscount__oxamountto->value)) {
            return false;
            // price check
        } elseif ($this->oxdiscount__oxprice->value) {
            $dRate = $oBasket->getBasketCurrency()->rate;
            if ($oSummary->dArticleDiscountablePrice < $this->oxdiscount__oxprice->value * $dRate || $oSummary->dArticleDiscountablePrice > $this->oxdiscount__oxpriceto->value * $dRate) {
                return false;
            }
        }

        // oxobject2discount configuration check
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $sQ = 'select 1 from oxobject2discount where oxdiscountid = ' . $oDb->quote($this->oxdiscount__oxid->value) . ' and oxtype in ("oxarticles", "oxcategories" ) ';

        return !((bool) $oDb->getOne($sQ));
    }
353144
public function getBasketPrice($dAmount, $aSelList, $oBasket)
    {
        $oUser = $oBasket->getBasketUser();
        $this->setArticleUser($oUser);

        $oBasketPrice = $this->_getPriceObject($oBasket->isCalculationModeNetto());

        // get base price
        $dBasePrice = $this->getBasePrice($dAmount);

        $dBasePrice = $this->_modifySelectListPrice($dBasePrice, $aSelList);
        $dBasePrice = $this->_preparePrice($dBasePrice, $this->getArticleVat(), $oBasket->isCalculationModeNetto());

        // applying select list price

        // setting price
        $oBasketPrice->setPrice($dBasePrice);

        $dVat = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\VatSelector::class)->getBasketItemVat($this, $oBasket);
        $this->_calculatePrice($oBasketPrice, $dVat);

        // returning final price object
        return $oBasketPrice;
    }
1242488
protected function _parentFinalizeOrder(Basket $oBasket, $oUser, $blRecalculatingOrder = false)
    {
        return parent::finalizeOrder($oBasket, $oUser, $blRecalculatingOrder);
    }
976137
public function addOrderArticleToBasket($oOrderArticle)
    {
        // adding only if amount > 0
        if ($oOrderArticle->oxorderarticles__oxamount->value > 0 && !$oOrderArticle->isBundle()) {
            $this->_isForOrderRecalculation = true;
            $sItemId = $oOrderArticle->getId();

            //inserting new
            $this->_aBasketContents[$sItemId] = oxNew(\OxidEsales\Eshop\Application\Model\BasketItem::class);
            $this->_aBasketContents[$sItemId]->initFromOrderArticle($oOrderArticle);
            $this->_aBasketContents[$sItemId]->setWrapping($oOrderArticle->oxorderarticles__oxwrapid->value);
            $this->_aBasketContents[$sItemId]->setBundle($oOrderArticle->isBundle());

            //calling update method
            $this->onUpdate();

            return $this->_aBasketContents[$sItemId];
        } elseif ($oOrderArticle->isBundle()) {
            // deleting bundles, they are handled automatically
            $oOrderArticle->delete();
        }
    }
412985
public function setIsNewBasket()
    {
        $this->_blNewBasket = true;
        $iTime = \OxidEsales\Eshop\Core\Registry::getUtilsDate()->getTime();
        $this->oxuserbaskets__oxupdate = new \OxidEsales\Eshop\Core\Field($iTime);
    }
1121540
protected function LoadFromBasketPostProcessData($oBasket, &$aOrderData)
    {
        // ------------------------------------------------------------------------
        parent::LoadFromBasketPostProcessData($oBasket, $aOrderData);
        if (method_exists($oBasket, 'getUserSelectedNewsletterOptionInOrderStep') && $oBasket->getUserSelectedNewsletterOptionInOrderStep()) {
            $aOrderData['newsletter_signup'] = '1';
        } else {
            $aOrderData['newsletter_signup'] = '0';
        }
    }
917726
public function ArticleAffected(TShopBasketArticle &$oArticle)
    {
        $shopShippingTypeDataAccess = $this->getShopShippingTypeDataAccess();
        $bAffected = false;
        $oArticleShippingType = &$oArticle->GetActingShippingType();
        // if the article is already marked with this shipping type, then we keep it
        if (!is_null($oArticleShippingType) && $oArticleShippingType->id == $this->id) {
            $bAffected = true;
        } elseif (is_null($oArticleShippingType)) {
            // article has no shipping type yet...
            // check article groups
            $bArticleGroupValid = false;
            $aGroupRestriction = $shopShippingTypeDataAccess->getPermittedArticleGroupIds($this->id);
            if (!is_array($aGroupRestriction) || count($aGroupRestriction) < 1) {
                $bArticleGroupValid = true;
            } else {
                $bArticleGroupValid = $oArticle->IsInArticleGroups($aGroupRestriction);
            }

            // check product categories
            $bArticleCategoryValid = false;
            if ($bArticleGroupValid) {
                $aCategoryRestriction = $shopShippingTypeDataAccess->getPermittedCategoryIds($this->id);
                if (!is_array($aCategoryRestriction) || count($aCategoryRestriction) < 1) {
                    $bArticleCategoryValid = true;
                } else {
                    $bArticleCategoryValid = $oArticle->IsInCategory($aCategoryRestriction);
                }
            }

            // check articles
            $bArticleValid = false;
            if ($bArticleGroupValid && $bArticleCategoryValid) {
                $aArticleRestriction = $shopShippingTypeDataAccess->getPermittedArticleIds($this->id);
                if (!is_array($aArticleRestriction) || count($aArticleRestriction) < 1) {
                    $bArticleValid = true;
                } else {
                    if (in_array($oArticle->id, $aArticleRestriction)) {
                        $bArticleValid = true;
                    }
                }
            }

            $bAffected = ($bArticleGroupValid && $bArticleCategoryValid && $bArticleValid);
        }

        return $bAffected;
    }