Adds new products to basket/order

@param \OxidEsales\Eshop\Application\Model\Basket $oBasket   basket to add articles
@param array                                      $aArticles article array
354943
protected function _addArticlesToBasket($oBasket, $aArticles)
    {
        // if no order articles
        if (count($aArticles) > 0) {
            //adding order articles to basket
            foreach ($aArticles as $oArticle) {
                $aSel = isset($oArticle->oxorderarticles__oxselvariant) ? $oArticle->oxorderarticles__oxselvariant->value : null;
                $aPersParam = isset($oArticle->oxorderarticles__oxpersparam) ? $oArticle->getPersParams() : null;
                $oBasket->addToBasket(
                    $oArticle->oxorderarticles__oxartid->value,
                    $oArticle->oxorderarticles__oxamount->value,
                    $aSel,
                    $aPersParam
                );
            }
        }
    }
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();
        }
    }
1189930
public function addRules(array $rules, $ruleset = null)
    {
        if ($ruleset) {
            $newRules = array_merge($this->getRuleset($ruleset), $rules);
            $this->setRuleset($newRules, $ruleset);
        } else {
            $newRules = array_merge($this->getRules(), $rules);
            $this->setRules($newRules);
        }
    }
1085743
protected function _setOrderArticles($aArticleList)
    {
        // reset articles list
        $this->_oArticles = oxNew(\OxidEsales\Eshop\Core\Model\ListModel::class);
        $iCurrLang = $this->getOrderLanguage();

        // add all the products we have on basket to the order
        foreach ($aArticleList as $oContent) {
            //$oContent->oProduct = $oContent->getArticle();
            // #M773 Do not use article lazy loading on order save
            $oProduct = $oContent->getArticle(true, null, true);

            // copy only if object is oxarticle type
            if ($oProduct->isOrderArticle()) {
                $oOrderArticle = $oProduct;
            } else {
                // if order language does not match product language article must be reloaded in order language
                if ($iCurrLang != $oProduct->getLanguage()) {
                    $oProduct->loadInLang($iCurrLang, $oProduct->getProductId());
                }

                // set chosen select list
                $sSelList = '';
                if (count($aChosenSelList = $oContent->getChosenSelList())) {
                    foreach ($aChosenSelList as $oItem) {
                        if ($sSelList) {
                            $sSelList .= ", ";
                        }
                        $sSelList .= "{$oItem->name} : {$oItem->value}";
                    }
                    if ($sSelList !== '' && $oContent->getVarSelect() !== '') {
                        $sSelList .= ' ||';
                    }
                }

                $oOrderArticle = oxNew(\OxidEsales\Eshop\Application\Model\OrderArticle::class);
                $oOrderArticle->setIsNewOrderItem(true);
                $oOrderArticle->copyThis($oProduct);
                $oOrderArticle->setId();

                $oOrderArticle->oxorderarticles__oxartnum = clone $oProduct->oxarticles__oxartnum;
                $oOrderArticle->oxorderarticles__oxselvariant = new \OxidEsales\Eshop\Core\Field(trim($sSelList . ' ' . $oContent->getVarSelect()), \OxidEsales\Eshop\Core\Field::T_RAW);
                $oOrderArticle->oxorderarticles__oxshortdesc = new \OxidEsales\Eshop\Core\Field($oProduct->oxarticles__oxshortdesc->getRawValue(), \OxidEsales\Eshop\Core\Field::T_RAW);
                // #M974: duplicated entries for the name of variants in orders
                $oOrderArticle->oxorderarticles__oxtitle = new \OxidEsales\Eshop\Core\Field(trim($oProduct->oxarticles__oxtitle->getRawValue()), \OxidEsales\Eshop\Core\Field::T_RAW);

                // copying persistent parameters ...
                if (!is_array($aPersParams = $oProduct->getPersParams())) {
                    $aPersParams = $oContent->getPersParams();
                }
                if (is_array($aPersParams) && count($aPersParams)) {
                    $oOrderArticle->oxorderarticles__oxpersparam = new \OxidEsales\Eshop\Core\Field(serialize($aPersParams), \OxidEsales\Eshop\Core\Field::T_RAW);
                }
            }

            // ids, titles, numbers ...
            $oOrderArticle->oxorderarticles__oxorderid = new \OxidEsales\Eshop\Core\Field($this->getId());
            $oOrderArticle->oxorderarticles__oxartid = new \OxidEsales\Eshop\Core\Field($oContent->getProductId());
            $oOrderArticle->oxorderarticles__oxamount = new \OxidEsales\Eshop\Core\Field($oContent->getAmount());

            // prices
            $oPrice = $oContent->getPrice();
            $oOrderArticle->oxorderarticles__oxnetprice = new \OxidEsales\Eshop\Core\Field($oPrice->getNettoPrice(), \OxidEsales\Eshop\Core\Field::T_RAW);
            $oOrderArticle->oxorderarticles__oxvatprice = new \OxidEsales\Eshop\Core\Field($oPrice->getVatValue(), \OxidEsales\Eshop\Core\Field::T_RAW);
            $oOrderArticle->oxorderarticles__oxbrutprice = new \OxidEsales\Eshop\Core\Field($oPrice->getBruttoPrice(), \OxidEsales\Eshop\Core\Field::T_RAW);
            $oOrderArticle->oxorderarticles__oxvat = new \OxidEsales\Eshop\Core\Field($oPrice->getVat(), \OxidEsales\Eshop\Core\Field::T_RAW);

            $oUnitPrice = $oContent->getUnitPrice();
            $oOrderArticle->oxorderarticles__oxnprice = new \OxidEsales\Eshop\Core\Field($oUnitPrice->getNettoPrice(), \OxidEsales\Eshop\Core\Field::T_RAW);
            $oOrderArticle->oxorderarticles__oxbprice = new \OxidEsales\Eshop\Core\Field($oUnitPrice->getBruttoPrice(), \OxidEsales\Eshop\Core\Field::T_RAW);

            // wrap id
            $oOrderArticle->oxorderarticles__oxwrapid = new \OxidEsales\Eshop\Core\Field($oContent->getWrappingId(), \OxidEsales\Eshop\Core\Field::T_RAW);

            // items shop id
            $oOrderArticle->oxorderarticles__oxordershopid = new \OxidEsales\Eshop\Core\Field($oContent->getShopId(), \OxidEsales\Eshop\Core\Field::T_RAW);

            // bundle?
            $oOrderArticle->oxorderarticles__oxisbundle = new \OxidEsales\Eshop\Core\Field($oContent->isBundle());

            // add information for eMail
            //P
            //TODO: check if this assign is needed at all
            $oOrderArticle->oProduct = $oProduct;

            $oOrderArticle->setArticle($oProduct);

            // simulation order article list
            $this->_oArticles->offsetSet($oOrderArticle->getId(), $oOrderArticle);
        }
    }
880005
public function addArtToSel()
    {
        $aAddArticle = $this->_getActionIds('oxarticles.oxid');
        $soxId = \OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('synchoxid');

        if (\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('all')) {
            $sArtTable = $this->_getViewName('oxarticles');
            $aAddArticle = $this->_getAll(parent::_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
        }

        if ($soxId && $soxId != "-1" && is_array($aAddArticle)) {
            // We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804 and ESDEV-3822).
            $database = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster();
            foreach ($aAddArticle as $sAdd) {
                $oNewGroup = oxNew(\OxidEsales\Eshop\Core\Model\BaseModel::class);
                $oNewGroup->init("oxobject2selectlist");
                $oNewGroup->oxobject2selectlist__oxobjectid = new \OxidEsales\Eshop\Core\Field($sAdd);
                $oNewGroup->oxobject2selectlist__oxselnid = new \OxidEsales\Eshop\Core\Field($soxId);
                $oNewGroup->oxobject2selectlist__oxsort = new \OxidEsales\Eshop\Core\Field(( int ) $database->getOne("select max(oxsort) + 1 from oxobject2selectlist where oxobjectid =  " . $database->quote($sAdd) . " "));
                $oNewGroup->save();

                $this->onArticleAddToSelectionList($sAdd);
            }
        }
    }
1335562
public function GetShippingCostsForBasketArticleListAndCountry($oBasketArticleList, $sDataCountryId)
    {
        /** @var Request $request */
        $request = \ChameleonSystem\CoreBundle\ServiceLocator::get('request_stack')->getCurrentRequest();

        $oBasketArticleList->GoToStart();

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

        $oTmpBasket = new TShopBasket();
        $request->getSession()->set(TShopBasket::SESSION_KEY_NAME, $oTmpBasket);

        $oTmpUser = TdbDataExtranetUser::GetNewInstance();

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

        $oTmpUser->setFakedShippingAddressForUser($oTmpShippingAddress);

        $oTmpUser->fieldDataCountryId = $sDataCountryId;
        $oTmpUser->sqlData['data_country_id'] = $sDataCountryId;
        $oTmpUser->sqlData['lastname'] = 'Dummy';
        $oTmpUser->sqlData['city'] = 'Dummy';

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

        while ($oBasketArticle = $oBasketArticleList->Next()) {
            $oTmpBasket->AddItem($oBasketArticle);
        }

        $oTmpBasket->SetActiveShippingGroup($this);

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

        $dShippingCosts = $oTmpBasket->dCostShipping;

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

        return $dShippingCosts;
    }
462126
private function addProductOne(Basket $basket)
    {
        $one = $this->products->one();

        $basket->add($one->sku, $one->name, $one->price, function ($product) use ($one) {
            $product->category($one->category);
        });

        return $basket;
    }
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;
    }
768320
public function createMessage(array $aMailData, array $aOpts, array $aRecs, array $aAttachments = [])
    {
        $oMessage = new Mail\Message();
        $oMessage->setEncoding('UTF-8');

        $this
            ->setFrom($oMessage, $aOpts)
            ->setTo($oMessage, $aRecs)
            ->addBcc($oMessage)
            ->setSubject($oMessage, $aMailData['subject'])
            ->setBody($oMessage, $aAttachments, $aMailData['html'], $aMailData['plain']);

        return $oMessage;
    }
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));
    }
861630
public function setOrderReferenceDetails($oBasket = null, array $aRequestParameters = array())
    {
        //Set default params
        $aRequestParameters['amazon_order_reference_id'] = $this->getSession()->getVariable('amazonOrderReferenceId');

        if ($oBasket !== null) {
            $oActiveShop = $this->getConfig()->getActiveShop();
            $sShopName = $oActiveShop->getFieldData('oxname');
            $sOxidVersion = $oActiveShop->getFieldData('oxversion');
            $sModuleVersion = bestitAmazonPay4Oxid_init::getCurrentVersion();

            $aRequestParameters = array_merge(
                $aRequestParameters,
                array(
                    'amount' => $oBasket->getPrice()->getBruttoPrice(),
                    'currency_code' => $oBasket->getBasketCurrency()->name,
                    'platform_id' => 'A26EQAZK19E0U2',
                    'store_name' => $sShopName,
                    'custom_information' => "created by best it, OXID eShop v{$sOxidVersion}, v{$sModuleVersion}"
                )
            );
        }

        $this->_addSandboxSimulationParams('setOrderReferenceDetails', $aRequestParameters);

        return $this->_convertResponse($this->_getAmazonClient()->setOrderReferenceDetails($aRequestParameters));
    }
865220
public function AddArticle($sArticleId, $dAmount = 1, $sComment = null)
    {
        $dNewAmount = 0;
        $aItemData = array();
        $oItem = TdbPkgShopWishlistArticle::GetNewInstance();
        /** @var $oItem TdbPkgShopWishlistArticle */
        if ($oItem->LoadFromFields(array('pkg_shop_wishlist_id' => $this->id, 'shop_article_id' => $sArticleId))) {
            $aItemData = $oItem->sqlData;
            $aItemData['amount'] += $dAmount;
        } else {
            $aItemData['pkg_shop_wishlist_id'] = $this->id;
            $aItemData['shop_article_id'] = $sArticleId;
            $aItemData['amount'] = $dAmount;
            $aItemData['datecreated'] = date('Y-m-d H:i:s');
        }
        if (!is_null($sComment)) {
            $aItemData['comment'] = $oItem->LoadFromRow($aItemData);
        }
        $oItem->LoadFromRow($aItemData);
        $oItem->AllowEditByAll(true);
        $oItem->Save();
        $dNewAmount = $aItemData['amount'];

        return $dNewAmount;
    }
557803
public function AddArticleIdToNoticeList($iArticleId, $iAmount = 1)
    {
        $dNewAmountOnList = 0;

        if (is_null($this->aNoticeList)) {
            $this->GetNoticeListArticles();
        }
        // check if the item being pushed is already in the end of the queue
        $iMaxQueueLength = 1000;

        $queNotEmpty = (count($this->aNoticeList) > 0);

        if (array_key_exists($iArticleId, $this->aNoticeList)) {
            // we do not allow placing an article more than once on the notice list
            $dNewAmountOnList = false;
        } else {
            $oNoticeListItem = TdbShopUserNoticeList::GetNewInstance();
            /** @var $oNoticeListItem TdbShopUserNoticeList */
            $aData = array('shop_article_id' => $iArticleId, 'date_added' => date('Y-m-d H:i:s'), 'data_extranet_user_id' => $this->id, 'amount' => $iAmount);
            $oNoticeListItem->LoadFromRow($aData);
            if (!is_null($this->id) && $this->IsLoggedIn()) {
                $oNoticeListItem->Save();
            }
            $this->aNoticeList[$oNoticeListItem->fieldShopArticleId] = $oNoticeListItem->sqlData;
        }

        if (false !== $dNewAmountOnList) {
            // remove item if amount drops to zero
            if ($this->aNoticeList[$iArticleId]['amount'] <= 0) {
                unset($this->aNoticeList[$iArticleId]);
            } else {
                $dNewAmountOnList = $this->aNoticeList[$iArticleId]['amount'];
            }

            // if the list is full, remove last item
            if (count($this->aNoticeList) > $iMaxQueueLength) {
                array_pop($this->aNoticeList);
            }

            // save list to cookie for users not signed in
            if (!$this->IsLoggedIn()) {
                $this->CommitNoticeListToCookie();
            }
        }

        return $dNewAmountOnList;
    }
359414
protected function addAddCart()
    {
        if (!$this->isError()) {
            $id = $this->cart->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
371468
public function getBasketArticles()
    {
        if ($this->_oBasketArtList === null) {
            $this->_oBasketArtList = false;
            if ($oBasket = $this->getBasket()) {
                $this->_oBasketArtList = $oBasket->getBasketArticles();
            }
        }

        return $this->_oBasketArtList;
    }
408354
public function addOrders(array $orders): void
    {
        foreach ($orders as $column => $order) {
            $this->addOrder($column, $order);
        }
    }
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);
            }
        }
    }