Adds order articles back to virtual basket. Needed for recalculating order.

@param \OxidEsales\Eshop\Application\Model\Basket $oBasket        basket object
@param array                                      $aOrderArticles order articles
338524
protected function _addOrderArticlesToBasket($oBasket, $aOrderArticles)
    {
        // if no order articles, return empty basket
        if (count($aOrderArticles) > 0) {
            //adding order articles to basket
            foreach ($aOrderArticles as $oOrderArticle) {
                $oBasket->addOrderArticleToBasket($oOrderArticle);
            }
        }
    }
942630
public function addArticle()
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();

        $aArticles = $this->_getActionIds('oxarticles.oxid');
        $sCategoryID = $myConfig->getRequestParameter('synchoxid');
        $sShopID = $myConfig->getShopId();

        \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->startTransaction();
        try {
            $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
            $sArticleTable = $this->_getViewName('oxarticles');

            // adding
            if (\OxidEsales\Eshop\Core\Registry::getConfig()->getRequestParameter('all')) {
                $aArticles = $this->_getAll($this->_addFilter("select $sArticleTable.oxid " . $this->_getQuery()));
            }

            if (is_array($aArticles)) {
                $sO2CView = $this->_getViewName('oxobject2category');

                $oNew = oxNew(\OxidEsales\Eshop\Application\Model\Object2Category::class);
                $sProdIds = "";
                foreach ($aArticles as $sAdd) {
                    // check, if it's already in, then don't add it again
                    $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid= "
                               . $database->quote($sCategoryID) . " and oxobject2category.oxobjectid = " . $database->quote($sAdd) . "";
                    // We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804).
                    if ($database->getOne($sSelect, false, false)) {
                        continue;
                    }

                    $oNew->oxobject2category__oxid = new \OxidEsales\Eshop\Core\Field($oNew->setId(md5($sAdd . $sCategoryID . $sShopID)));
                    $oNew->oxobject2category__oxobjectid = new \OxidEsales\Eshop\Core\Field($sAdd);
                    $oNew->oxobject2category__oxcatnid = new \OxidEsales\Eshop\Core\Field($sCategoryID);
                    $oNew->oxobject2category__oxtime = new \OxidEsales\Eshop\Core\Field(time());

                    $oNew->save();

                    if ($sProdIds) {
                        $sProdIds .= ",";
                    }
                    $sProdIds .= $database->quote($sAdd);
                }

                // updating oxtime values
                $this->_updateOxTime($sProdIds);

                $this->resetArtSeoUrl($aArticles);
                $this->resetCounter("catArticle", $sCategoryID);
            }
        } catch (Exception $exception) {
            \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->rollbackTransaction();
            throw $exception;
        }

        \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->commitTransaction();
    }
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;
    }
1295267
public function reserveBasket(\OxidEsales\Eshop\Application\Model\Basket $oBasket)
    {
        if (!$this->isAdmin()) {
            $this->_reserveArticles($this->_basketDifference($oBasket));
        }
    }
1269030
protected function LoadFromBasketPostProcessData($oBasket, &$aOrderData)
    {
        parent::LoadFromBasketPostProcessData($oBasket, $aOrderData);
        $aOrderData['pkg_shop_currency_id'] = TdbPkgShopCurrency::GetActiveCurrencyId();
    }
636963
public function getBasketArticles()
    {
        $aBasketArticles = [];
        /** @var \oxBasketItem $oBasketItem */
        foreach ($this->_aBasketContents as $sItemKey => $oBasketItem) {
            try {
                $oProduct = $oBasketItem->getArticle(true);

                if (\OxidEsales\Eshop\Core\Registry::getConfig()->getConfigParam('bl_perfLoadSelectLists')) {
                    // marking chosen select list
                    $aSelList = $oBasketItem->getSelList();
                    if (is_array($aSelList) && ($aSelectlist = $oProduct->getSelectLists($sItemKey))) {
                        reset($aSelList);
                        foreach ($aSelList as $conkey => $iSel) {
                            $aSelectlist[$conkey][$iSel]->selected = 1;
                        }
                        $oProduct->setSelectlist($aSelectlist);
                    }
                }
            } catch (\OxidEsales\Eshop\Core\Exception\NoArticleException $oEx) {
                \OxidEsales\Eshop\Core\Registry::getUtilsView()->addErrorToDisplay($oEx);
                $this->removeItem($sItemKey);
                $this->calculateBasket(true);
                continue;
            } catch (\OxidEsales\Eshop\Core\Exception\ArticleInputException $oEx) {
                \OxidEsales\Eshop\Core\Registry::getUtilsView()->addErrorToDisplay($oEx);
                $this->removeItem($sItemKey);
                $this->calculateBasket(true);
                continue;
            }

            $aBasketArticles[$sItemKey] = $oProduct;
        }

        return $aBasketArticles;
    }
330211
public function getArticleDiscounts($oArticle, $oUser = null)
    {
        $aList = [];
        $aDiscList = $this->_getList($oUser)->getArray();
        foreach ($aDiscList as $oDiscount) {
            if ($oDiscount->isForArticle($oArticle)) {
                $aList[$oDiscount->getId()] = $oDiscount;
            }
        }

        return $aList;
    }
710406
public function loadOrderArticles($aOrders)
    {
        if (!count($aOrders)) {
            $this->clear();

            return;
        }

        foreach ($aOrders as $iKey => $oOrder) {
            $aOrdersIds[] = $oOrder->getId();
        }

        $oBaseObject = $this->getBaseObject();
        $sArticleTable = $oBaseObject->getViewName();
        $sArticleFields = $oBaseObject->getSelectFields();
        $sArticleFields = str_replace("`$sArticleTable`.`oxid`", "`oxorderarticles`.`oxartid` AS `oxid`", $sArticleFields);

        $sSelect = "SELECT $sArticleFields FROM oxorderarticles ";
        $sSelect .= "left join $sArticleTable on oxorderarticles.oxartid = $sArticleTable.oxid ";
        $sSelect .= "WHERE oxorderarticles.oxorderid IN ( '" . implode("','", $aOrdersIds) . "' ) ";
        $sSelect .= "order by $sArticleTable.oxid ";

        $this->selectString($sSelect);

        // not active or not available products must not have button "tobasket"
        $sNow = date('Y-m-d H:i:s');
        foreach ($this as $oArticle) {
            if (!$oArticle->oxarticles__oxactive->value &&
                ($oArticle->oxarticles__oxactivefrom->value > $sNow ||
                 $oArticle->oxarticles__oxactiveto->value < $sNow
                )
            ) {
                $oArticle->setBuyableState(false);
            }
        }
    }
843133
protected function getArticleList(TdbShopOrder $oOrder, IMapperCacheTriggerRestricted $oCacheTriggerManager, $bCachingEnabled)
    {
        $aArticleList = array();
        $oOrderItemList = &$oOrder->GetFieldShopOrderItemList();
        while ($oOrderItem = &$oOrderItemList->Next()) {
            if ($bCachingEnabled) {
                $oCacheTriggerManager->addTrigger($oOrderItem->table, $oOrderItem->id);
            }
            $aArticleList[] = $this->getArticle($oOrderItem, $oCacheTriggerManager, $bCachingEnabled);
        }

        return $aArticleList;
    }
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;
    }
437153
public function AllowVoucherForArticle(TShopBasketArticle $oArticle)
    {
        $bMayBeUsed = true;

        $oVoucherDef = &$this->GetFieldShopVoucherSeries();

        if ($oArticle->fieldExcludeFromVouchers && empty($oVoucherDef->fieldShopVoucherSeriesSponsorId)) {
            $bMayBeUsed = false;
        }

        // check article restrictions
        if ($bMayBeUsed) {
            $aArticleRestrictons = $oVoucherDef->GetMLTIdList('shop_article_mlt');
            if (count($aArticleRestrictons) > 0 && !in_array($oArticle->id, $aArticleRestrictons)) {
                $bMayBeUsed = false;
            }
        }

        // check manufacturer restrictions
        if ($bMayBeUsed) {
            $aManufacturerRestrictons = $oVoucherDef->GetMLTIdList('shop_manufacturer_mlt');
            if (count($aManufacturerRestrictons) > 0 && !in_array($oArticle->fieldShopManufacturerId, $aManufacturerRestrictons)) {
                $bMayBeUsed = false;
            }
        }

        // check category restrictions
        if ($bMayBeUsed) {
            $aCategoryRestrictons = $oVoucherDef->GetMLTIdList('shop_category_mlt');
            if (count($aCategoryRestrictons) > 0) {
                if (!$oArticle->IsInCategory($aCategoryRestrictons)) {
                    $bMayBeUsed = false;
                }
            }
        }

        // check product group restrictions
        if ($bMayBeUsed) {
            $aArticleGroupRestrictons = $oVoucherDef->GetMLTIdList('shop_article_group_mlt');
            if (count($aArticleGroupRestrictons) > 0) {
                $aGroups = $oArticle->GetMLTIdList('shop_article_group_mlt');
                $aMatches = array_intersect($aGroups, $aArticleGroupRestrictons);
                if (0 == count($aMatches)) {
                    $bMayBeUsed = false;
                }
            }
        }

        return $bMayBeUsed;
    }
1225510
protected function PostUpdateItemHook($oUpdatedItem)
    {
        reset($this->aObservers);
        foreach (array_keys($this->aObservers) as $sObserverName) {
            $this->aObservers[$sObserverName]->OnBasketItemUpdateEvent($oUpdatedItem);
        }
    }
1132817
public function SaveArticles(TShopBasketArticleList $oBasketArticleList)
    {
        if (!is_null($this->id)) {
            $oBasketArticleList->GoToStart();
            while ($oBasketItem = $oBasketArticleList->Next()) {
                $this->SaveArticle($oBasketItem);
            }
        }
    }
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;
    }
692810
private function addSortFields(Fieldset $fieldset)
    {
        $sortFieldsOptions = [
            ['value' => '_first', 'label' => __("First")],
            ['value' => '_last',  'label' => __("Last")],
        ];

        $fieldset->addField(
            'sort_order_asc_missing',
            'select',
            [
                'name'   => 'sort_order_asc_missing',
                'label'  => __('Sort products without value when sorting ASC'),
                'values' => $sortFieldsOptions,
                'note'   => __('How the products which are missing values for this attribute should be treated when using it to sort.'),
            ],
            'used_for_sortby'
        );

        $fieldset->addField(
            'sort_order_desc_missing',
            'select',
            [
                'name'   => 'sort_order_desc_missing',
                'label'  => __('Sort products without value when sorting DESC'),
                'values' => $sortFieldsOptions,
                'note'   => __('How the products which are missing values for this attribute should be treated when using it to sort.'),
            ],
            'sort_order_asc_missing'
        );

        return $this;
    }
698861
public function addArticle($articleId)
    {
        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $sQ = "select max(oxsort) from oxactions2article where oxactionid = " . $oDb->quote($this->getId()) . " and oxshopid = '" . $this->getShopId() . "'";
        $iSort = ((int) $oDb->getOne($sQ)) + 1;

        $oNewGroup = oxNew(\OxidEsales\Eshop\Core\Model\BaseModel::class);
        $oNewGroup->init('oxactions2article');
        $oNewGroup->oxactions2article__oxshopid = new \OxidEsales\Eshop\Core\Field($this->getShopId());
        $oNewGroup->oxactions2article__oxactionid = new \OxidEsales\Eshop\Core\Field($this->getId());
        $oNewGroup->oxactions2article__oxartid = new \OxidEsales\Eshop\Core\Field($articleId);
        $oNewGroup->oxactions2article__oxsort = new \OxidEsales\Eshop\Core\Field($iSort);
        $oNewGroup->save();
    }
1122337
protected function _getItemBundles($oBasketItem, $aBundles = [])
    {
        if ($oBasketItem->isBundle()) {
            return [];
        }

        // does this object still exists ?
        if ($oArticle = $oBasketItem->getArticle()) {
            $aDiscounts = \OxidEsales\Eshop\Core\Registry::get(\OxidEsales\Eshop\Application\Model\DiscountList::class)->getBasketItemBundleDiscounts($oArticle, $this, $this->getBasketUser());

            foreach ($aDiscounts as $oDiscount) {
                $iAmnt = $oDiscount->getBundleAmount($oBasketItem->getAmount());
                if ($iAmnt) {
                    //init array element
                    if (!isset($aBundles[$oDiscount->oxdiscount__oxitmartid->value])) {
                        $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = 0;
                    }

                    if ($oDiscount->oxdiscount__oxitmmultiple->value) {
                        $aBundles[$oDiscount->oxdiscount__oxitmartid->value] += $iAmnt;
                    } else {
                        $aBundles[$oDiscount->oxdiscount__oxitmartid->value] = $iAmnt;
                    }
                }
            }
        }

        return $aBundles;
    }