Returns array of discounts that can be applied for whole basket

@param \OxidEsales\Eshop\Application\Model\Basket $oBasket basket
@param \OxidEsales\Eshop\Application\Model\User   $oUser   user object (optional)

@return array
499257
public function getBasketDiscounts($oBasket, $oUser = null)
    {
        $aList = [];
        $aDiscList = $this->_getList($oUser)->getArray();
        /** @var \OxidEsales\Eshop\Application\Model\Discount $oDiscount */
        foreach ($aDiscList as $oDiscount) {
            if ($oDiscount->isForBasket($oBasket)) {
                $aList[$oDiscount->getId()] = $oDiscount;
            }
        }

        return $aList;
    }
416664
protected function _validateBasket(\OxidEsales\Eshop\Application\Model\Basket $oBasket)
    {
        $aCurrContent = $oBasket->getContents();
        if (empty($aCurrContent)) {
            return;
        }

        $iCurrLang = \OxidEsales\Eshop\Core\Registry::getLang()->getBaseLanguage();
        foreach ($aCurrContent as $oContent) {
            if ($oContent->getLanguageId() != $iCurrLang) {
                $oContent->setLanguageId($iCurrLang);
            }
        }
    }
432194
public function products(Basket $basket)
    {
        $products = [];

        foreach ($basket->products() as $product) {
            $products[] = [
                'sku'            => $product->sku,
                'name'           => $product->name,
                'price'          => $product->price,
                'rate'           => $product->rate,
                'quantity'       => $product->quantity,
                'freebie'        => $product->freebie,
                'taxable'        => $product->taxable,
                'delivery'       => $product->delivery,
                'coupons'        => $product->coupons,
                'tags'           => $product->tags,
                'discount'       => $product->discount,
                'attributes'     => $product->attributes,
                'category'       => $product->category,
                'total_value'    => $this->reconciler->value($product),
                'total_discount' => $this->reconciler->discount($product),
                'total_delivery' => $this->reconciler->delivery($product),
                'total_tax'      => $this->reconciler->tax($product),
                'subtotal'       => $this->reconciler->subtotal($product),
                'total'          => $this->reconciler->total($product)
            ];
        }

        return $products;
    }
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;
    }
1148864
protected function _getOrderBasketItems($oDiscount = null)
    {
        if (is_null($oDiscount)) {
            $oDiscount = $this->_getSerieDiscount();
        }

        $oOrder = oxNew(\OxidEsales\Eshop\Application\Model\Order::class);
        $oOrder->load($this->oxvouchers__oxorderid->value);

        $aItems = [];
        $iCount = 0;

        foreach ($oOrder->getOrderArticles(true) as $oOrderArticle) {
            if (!$oOrderArticle->skipDiscounts() && $oDiscount->isForBasketItem($oOrderArticle)) {
                $aItems[$iCount] = [
                    'oxid'     => $oOrderArticle->getProductId(),
                    'price'    => $oOrderArticle->oxorderarticles__oxbprice->value,
                    'discount' => $oDiscount->getAbsValue($oOrderArticle->oxorderarticles__oxbprice->value),
                    'amount'   => $oOrderArticle->oxorderarticles__oxamount->value,
                ];
                $iCount++;
            }
        }

        return $aItems;
    }
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);
    }
1105217
protected function _isAvailableInOtherOrder($oUser)
    {
        $oSeries = $this->getSerie();
        if (!$oSeries->oxvoucherseries__oxallowuseanother->value) {
            $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
            $sSelect = 'select count(*) from ' . $this->getViewName() . ' where oxuserid = ' . $oDb->quote($oUser->oxuser__oxid->value) . ' and ';
            $sSelect .= 'oxvoucherserieid = ' . $oDb->quote($this->oxvouchers__oxvoucherserieid->value) . ' and ';
            $sSelect .= '((oxorderid is not NULL and oxorderid != "") or (oxdateused is not NULL and oxdateused != 0)) ';

            if ($oDb->getOne($sSelect)) {
                $oEx = oxNew(\OxidEsales\Eshop\Core\Exception\VoucherException::class);
                $oEx->setMessage('ERROR_MESSAGE_VOUCHER_NOTALLOWEDSAMESERIES');
                $oEx->setVoucherNr($this->oxvouchers__oxvouchernr->value);
                throw $oEx;
            }
        }

        return true;
    }
1298205
protected function _getArticleBundles($oBasketItem)
    {
        $aBundles = [];

        if ($oBasketItem->isBundle()) {
            return $aBundles;
        }

        $oArticle = $oBasketItem->getArticle(true);
        if ($oArticle && $oArticle->oxarticles__oxbundleid->value) {
            $aBundles[$oArticle->oxarticles__oxbundleid->value] = 1;
        }

        return $aBundles;
    }
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();
        }
    }
189564
protected function _addUserProfileData( array $aData, oxUser $oUser )
    {
        // Common user profile fields
        $aData['customer_id']           = self::toUtf( $oUser->getCustomerPaymorrowCustomerNumber() );
        $aData['customer_group']        = self::toUtf( $oUser->getUserGroupNames(), 255 );
        $aData['customer_title']        = self::toUtf( $oUser->getUserPaymorrowSalutation() );
        $aData['customer_gender']       = self::toUtf( $oUser->getUserPaymorrowGender() );
        $aData['customer_firstName']    = self::toUtf( $oUser->getUserPaymorrowFirstName() );
        $aData['customer_lastName']     = self::toUtf( $oUser->getUserPaymorrowLastName() );
        $aData['customer_phoneNumber']  = self::toUtf( $oUser->getUserPaymorrowPhone() );
        $aData['customer_mobileNumber'] = self::toUtf( $oUser->getUserPaymorrowMobilePhone() );
        $aData['customer_email']        = self::toUtf( $oUser->getUserPaymorrowEmail() );
        $aData['customer_dateOfBirth']  = self::toUtf( $oUser->getUserPaymorrowDateOfBirth() );

        // Billing address fields
        $aData['customer_billingAddress_street']     = self::toUtf( $oUser->getUserPaymorrowStreet() );
        $aData['customer_billingAddress_houseNo']    = self::toUtf( $oUser->getUserPaymorrowStreetNumber() );
        $aData['customer_billingAddress_postalCode'] = self::toUtf( $oUser->getUserPaymorrowZipCode() );
        $aData['customer_billingAddress_city']       = self::toUtf( $oUser->getUserPaymorrowCity() );
        $aData['customer_billingAddress_country']    = self::toUtf( $oUser->getUserPaymorrowCountry() );

        return $aData;
    }
563519
public function GetBasketSumForVoucher(TdbShopVoucher &$oVoucher)
    {
        // get the sum of all products (if the voucher is not sponsored, we exclude products with "ExcludeFromVouchers")
        $iCurrentPosition = $this->getItemPointer();
        $this->GoToStart();
        $oVoucherDef = &$oVoucher->GetFieldShopVoucherSeries();
        $dProductValue = 0;
        while ($oItem = &$this->Next()) {
            $bIncludeProduct = $oVoucher->AllowVoucherForArticle($oItem);
            if ($bIncludeProduct) {
                $dProductValue = $dProductValue + $oItem->dPriceTotalAfterDiscountWithoutVouchers;
            }
        }
        $this->setItemPointer($iCurrentPosition);

        return $dProductValue;
    }
199843
public function GetValidShippingTypesForBasketArticleListAndCountry($oBasketArticleList, $sDataCountryId)
    {
        $oValidShippingTypes = new TIterator();
        /** @var $oValidShippingTypes TIterator* */
        $oShippingTypes = $this->GetFieldShopShippingTypeList('position');
        while ($oShippingType = $oShippingTypes->Next()) {
            $bIsValid = $oShippingType->IsActive();
            $bIsValid = $bIsValid && $oShippingType->isValidForCurrentPortal();
            $bIsValid = $bIsValid && $oShippingType->IsValidForCurrentUser(false);
            $bIsValid = $bIsValid && $oShippingType->IsValidForCountry($sDataCountryId);
            if ($bIsValid) {
                $oAffectedArticles = $oBasketArticleList->GetArticlesAffectedByShippingType($oShippingType);
                $bIsValid = ($oAffectedArticles->Length() > 0);
            }
            if ($bIsValid) {
                $oValidShippingTypes->AddItem($oShippingType);
            }
        }

        return $oValidShippingTypes;
    }
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;
    }
183
public function getBaseBasketPriceForPaymentCostCalc($oBasket)
    {
        $dBasketPrice = 0;
        $iRules = $this->oxpayments__oxaddsumrules->value;

        // products brutto price
        if (!$iRules || ($iRules & self::PAYMENT_ADDSUMRULE_ALLGOODS)) {
            $dBasketPrice += $oBasket->getProductsPrice()->getSum($oBasket->isCalculationModeNetto());
        }

        // discounts
        if ((!$iRules || ($iRules & self::PAYMENT_ADDSUMRULE_DISCOUNTS)) &&
            ($oCosts = $oBasket->getTotalDiscount())
        ) {
            $dBasketPrice -= $oCosts->getPrice();
        }

        // vouchers
        if (!$iRules || ($iRules & self::PAYMENT_ADDSUMRULE_VOUCHERS)) {
            $dBasketPrice -= $oBasket->getVoucherDiscValue();
        }

        // delivery
        if ((!$iRules || ($iRules & self::PAYMENT_ADDSUMRULE_SHIPCOSTS)) &&
            ($oCosts = $oBasket->getCosts('oxdelivery'))
        ) {
            if ($oBasket->isCalculationModeNetto()) {
                $dBasketPrice += $oCosts->getNettoPrice();
            } else {
                $dBasketPrice += $oCosts->getBruttoPrice();
            }
        }

        // wrapping
        if (($iRules & self::PAYMENT_ADDSUMRULE_GIFTS) &&
            ($oCosts = $oBasket->getCosts('oxwrapping'))
        ) {
            if ($oBasket->isCalculationModeNetto()) {
                $dBasketPrice += $oCosts->getNettoPrice();
            } else {
                $dBasketPrice += $oCosts->getBruttoPrice();
            }
        }

        // gift card
        if (($iRules & self::PAYMENT_ADDSUMRULE_GIFTS) &&
            ($oCosts = $oBasket->getCosts('oxgiftcard'))
        ) {
            if ($oBasket->isCalculationModeNetto()) {
                $dBasketPrice += $oCosts->getNettoPrice();
            } else {
                $dBasketPrice += $oCosts->getBruttoPrice();
            }
        }

        return $dBasketPrice;
    }
763089
protected function GetBasketStatistics($oBasket)
    {
        $sBasketstatistics = '';
        $sBasketstatistics .= "------------------------------------\r\n\r\n";
        $sBasketstatistics .= TGlobal::Translate('chameleon_system_shop.cron_send_basket_stats.basket_content')."\r\n";
        $sBasketstatistics .= "------------------------------------\r\n";
        $oArticleList = $oBasket->GetBasketContents();
        $oArticleList->GoToStart();
        while ($oArticle = $oArticleList->Next()) {
            $sBasketstatistics .= TGlobal::Translate(
                    'chameleon_system_shop.cron_send_basket_stats.basket_content_line',
                    array(
                        '%amount%' => '',
                        '%name%' => '',
                        '%price%' => '',
                        '%totalPrice%' => '',
                    )
                )."\r\n";
        }
        $sBasketstatistics .= TGlobal::Translate('chameleon_system_shop.cron_send_basket_stats.basket_content_total', array('%basketTotal%' => $oBasket->dCostArticlesTotal))."\r\n";
        $this->sTotalMoneyCanceled = $this->sTotalMoneyCanceled + $oBasket->dCostArticlesTotal;
        $sBasketstatistics .= "------------------------------------\r\n";

        return $sBasketstatistics;
    }
108115
protected function _OxpsPaymorrowOxOrder_finalizeOrder_parent( oxBasket $oBasket, $oUser,
                                                                   $blRecalculatingOrder = false )
    {
        return parent::finalizeOrder( $oBasket, $oUser, $blRecalculatingOrder );
    }
1323519
protected function _manageFullUserData($oUser, $oAmazonData)
    {
        $oContainer = $this->_getContainer();
        $oSession = $oContainer->getSession();
        $oConfig = $oContainer->getConfig();

        //Parse data from Amazon for OXID
        $aParsedData = $oContainer->getAddressUtil()->parseAmazonAddress(
            $oAmazonData->Destination->PhysicalDestination
        );

        $aDefaultMap = array(
            'oxcompany' => $aParsedData['CompanyName'],
            'oxfname' => $aParsedData['FirstName'],
            'oxlname' => $aParsedData['LastName'],
            'oxcity' => $aParsedData['City'],
            'oxstateid' => $aParsedData['StateOrRegion'],
            'oxcountryid' => $aParsedData['CountryId'],
            'oxzip' => $aParsedData['PostalCode'],
            'oxfon' => $aParsedData['Phone'],
            'oxstreet' => $aParsedData['Street'],
            'oxstreetnr' => $aParsedData['StreetNr'],
            'oxaddinfo' => $aParsedData['AddInfo']
        );

        //Getting Email
        $sEmail = $oAmazonData->Buyer->Email;

        // If we find user account in OXID with same email that we got from Amazon then add new shipping address
        $oDatabase = $oContainer->getDatabase();

        $sQuery = "SELECT OXID
            FROM oxuser
            WHERE OXUSERNAME = {$oDatabase->quote($sEmail)}
            AND OXSHOPID = {$oDatabase->quote($oConfig->getShopId())}";

        $sUserWithSuchEmailOxid = (string)$oDatabase->getOne($sQuery);

        if ($sUserWithSuchEmailOxid !== '') {
            //Load existing user from oxid
            $oUser->load($sUserWithSuchEmailOxid);

            /** @var oxAddress $oDelAddress */
            $oDelAddress = $oContainer->getObjectFactory()->createOxidObject('oxAddress');

            //Maybe we have already shipping address added for this user ? If yes then use it
            /**
             * @var oxAddress[] $aUserAddresses
             */
            $aUserAddresses = $oUser->getUserAddresses();

            foreach ($aUserAddresses as $oAddress) {
                if ((string)$oAddress->getFieldData('oxfname') === (string)$aParsedData['FirstName']
                    && (string)$oAddress->getFieldData('oxlname') === (string)$aParsedData['LastName']
                    && (string)$oAddress->getFieldData('oxstreet') === (string)$aParsedData['Street']
                    && (string)$oAddress->getFieldData('oxstreetnr') === (string)$aParsedData['StreetNr']
                ) {
                    $oDelAddress->load($oAddress->getId());
                    break;
                }
            }

            $oDelAddress->assign(array_merge($aDefaultMap, array('oxuserid' => $sUserWithSuchEmailOxid)));
            $sDeliveryAddressId = $oDelAddress->save();

            $oSession->setVariable('blshowshipaddress', 1);
            $oSession->setVariable('deladrid', $sDeliveryAddressId);
        } else {
            // If the user is new and not found in OXID update data from Amazon
            $oUser->assign(array_merge($aDefaultMap, array('oxusername' => $sEmail)));
            $oUser->save();

            $sDeliveryAddressId = (string) $oSession->getVariable('deladrid');

            // Set Amazon address as shipping
            if ($sDeliveryAddressId !== '') {
                /** @var oxAddress $oDelAddress */
                $oDelAddress = $oContainer->getObjectFactory()->createOxidObject('oxAddress');
                $oDelAddress->load($sDeliveryAddressId);
                $oDelAddress->assign($aDefaultMap);
                $oDelAddress->save();
            }
        }

        return $oUser;
    }