Returns stock of article in basket, including bundle article

@param string $sArtId        article id
@param string $sExpiredArtId item id of updated article

@return double
549883
public function getArtStockInBasket($sArtId, $sExpiredArtId = null)
    {
        $dArtStock = 0;
        foreach ($this->_aBasketContents as $sItemKey => $oOrderArticle) {
            if ($oOrderArticle && ($sExpiredArtId == null || $sExpiredArtId != $sItemKey)) {
                if ($oOrderArticle->getArticle(true)->getId() == $sArtId) {
                    $dArtStock += $oOrderArticle->getAmount();
                }
            }
        }

        return $dArtStock;
    }
552608
public function setManufacturerArticleCount($aCache, $sMnfId, $sActIdent)
    {
        // if Manufacturer/category name is 'root', skip counting
        if ($sMnfId == 'root') {
            return 0;
        }

        $oArticle = oxNew(\OxidEsales\Eshop\Application\Model\Article::class);
        $sArtTable = $oArticle->getViewName();

        // select each Manufacturer articles count
        //#3485
        $sQ = "select count($sArtTable.oxid) from $sArtTable where $sArtTable.oxparentid = '' and oxmanufacturerid = '$sMnfId' and " . $oArticle->getSqlActiveSnippet();

        $iValue = \OxidEsales\Eshop\Core\DatabaseProvider::getDb()->getOne($sQ);

        $aCache[$sMnfId][$sActIdent] = (int) $iValue;

        $this->_setManufacturerCache($aCache);

        return $aCache[$sMnfId][$sActIdent];
    }
1085010
protected function _getStockLevel( $prodid, $warehouse )
	{
		$manager = MShop_Factory::createManager( $this->_getContext(), 'product/stock' );

		$search = $manager->createSearch( true );
		$expr = array(
			$search->compare( '==', 'product.stock.productid', $prodid ),
			$search->getConditions(),
			$search->compare( '==', 'product.stock.warehouse.code', $warehouse ),
		);
		$search->setConditions( $search->combine( '&&', $expr ) );

		$result = $manager->searchItems( $search );

		if( empty( $result ) )
		{
			$msg = sprintf( 'No stock for product ID "%1$s" and warehouse "%2$s" available', $prodid, $warehouse );
			throw new Controller_Frontend_Basket_Exception( $msg );
		}

		$stocklevel = null;

		foreach( $result as $item )
		{
			if( ( $stock = $item->getStockLevel() ) === null ) {
				return null;
			}

			$stocklevel = max( (int) $stocklevel, $item->getStockLevel() );
		}

		return $stocklevel;
	}
1052206
public function loadTop5Articles($iLimit = null)
    {
        //has module?
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();

        if (!$myConfig->getConfigParam('bl_perfLoadPriceForAddList')) {
            $this->getBaseObject()->disablePriceLoad();
        }

        switch ($myConfig->getConfigParam('iTop5Mode')) {
            case 0:
                // switched off, do nothing
                break;
            case 1:
                // manually entered
                $this->loadActionArticles('oxtop5', $iLimit);
                break;
            case 2:
                $sArticleTable = getViewName('oxarticles');

                //by default limit 5
                $sLimit = ($iLimit > 0) ? "limit " . $iLimit : 'limit 5';

                $sSelect = "select * from $sArticleTable ";
                $sSelect .= "where " . $this->getBaseObject()->getSqlActiveSnippet() . " and $sArticleTable.oxissearch = 1 ";
                $sSelect .= "and $sArticleTable.oxparentid = '' and $sArticleTable.oxsoldamount>0 ";
                $sSelect .= "order by $sArticleTable.oxsoldamount desc $sLimit";

                $this->selectString($sSelect);
                break;
        }
    }
176888
public function loadHistoryArticles($sArtId, $iCnt = 4)
    {
        $aHistoryArticles = $this->getHistoryArticles();
        $aHistoryArticles[] = $sArtId;

        // removing duplicates
        $aHistoryArticles = array_unique($aHistoryArticles);
        if (count($aHistoryArticles) > ($iCnt + 1)) {
            array_shift($aHistoryArticles);
        }

        $this->setHistoryArticles($aHistoryArticles);

        //remove current article and return array
        //asignment =, not ==
        if (($iCurrentArt = array_search($sArtId, $aHistoryArticles)) !== false) {
            unset($aHistoryArticles[$iCurrentArt]);
        }

        $aHistoryArticles = array_values($aHistoryArticles);
        $this->loadIds($aHistoryArticles);
        $this->sortByIds($aHistoryArticles);
    }
952574
public function getPinnedByCategoryId( $categoryId, $config = [] ) {

		$modelClass	= static::$modelClass;
		$modelTable	= $this->getModelTable();

		$config[ 'page' ]	= isset( $config[ 'page' ] ) ? $config[ 'page' ] : false;
		$config[ 'query' ]	= isset( $config[ 'query' ] ) ? $config[ 'query' ] : $modelClass::find();
		$config[ 'limit' ]	= isset( $config[ 'limit' ] ) ? $config[ 'limit' ] : 10;
		$config[ 'active' ]	= isset( $config[ 'active' ] ) ? $config[ 'active' ] : true;

		if( $config[ 'active' ] ) {

			$config[ 'query' ]->joinWith( 'activeCategories' )->andWhere( [ 'modelId' => $categoryId, "$modelTable.pinned" => true ] );
		}
		else {

			$config[ 'query' ]->joinWith( 'categories' )->andWhere( [ 'modelId' => $categoryId, "$modelTable.pinned" => true ] );
		}

		if( $config[ 'page' ] ) {

			$page	= $this->getPublicPage( $config );

			return $page->getModels();
		}

		return $config[ 'query' ]->limit( $config[ 'limit' ] )->all();
	}
227114
public function loadVendorArticles($sVendorId, $oVendor = null)
    {
        $sSelect = $this->_getVendorSelect($sVendorId);
        $this->selectString($sSelect);

        return \OxidEsales\Eshop\Core\Registry::getUtilsCount()->getVendorArticleCount($sVendorId);
    }
795698
public function addData($storeId, array $indexData)
    {
        $inventoryData = $this->getResourceModel()->loadInventoryData($storeId, array_keys($indexData));

        foreach ($inventoryData as $inventoryDataRow) {
            $productId = (int) $inventoryDataRow['product_id'];
            $indexData[$productId]['stock'] = [
                'is_in_stock' => (bool) $inventoryDataRow['stock_status'],
                'qty'         => (int) $inventoryDataRow['qty'],
            ];
        }

        return $indexData;
    }
463328
public function getStockData($minProductId, $maxProductId)
    {
        $this->stockData = [];
        $stockQuery = $this->_resource->getConnection()->select()
            ->from($this->getTable('cataloginventory_stock_item'), ['is_in_stock', 'qty', 'product_id'])
            ->where('product_id >= ?', $minProductId)
            ->where('product_id <= ?', $maxProductId)
            ->where('stock_id = ?', 1);

        $this->iterator->walk(
            (string)$stockQuery,
            [[$this, 'handleStockItem']],
            [],
            $this->_resource->getConnection()
        );

        return $this->stockData;
    }
26874
protected function _getArtStock($dAddAmount = 0, $blAllowNegativeStock = false)
    {
        // We force reading from master to prevent issues with slow replications or open transactions (see ESDEV-3804).
        $masterDb = \OxidEsales\Eshop\Core\DatabaseProvider::getMaster();

        // #1592A. must take real value
        $sQ = 'select oxstock from oxarticles where oxid = ' . $masterDb->quote($this->oxorderarticles__oxartid->value);
        $iStockCount = ( float ) $masterDb->getOne($sQ);

        $iStockCount += $dAddAmount;

        // #1592A. calculating according new stock option
        if (!$blAllowNegativeStock && $iStockCount < 0) {
            $iStockCount = 0;
        }

        return $iStockCount;
    }
88937
public function getStockCount(string $productNumber) : int
    {
        Assert::that($productNumber)->minLength(1, 'The length of $productNumber has to be > 0');
        $product = $this->getDataProduct($productNumber);

        return (int)$product['stockCount'];
    }
674297
public function loadByOrderId($orderId, $quoteId)
    {
        $item = $this->getCollection()
            ->loadByOrderIdAndQuoteId($orderId, $quoteId);

        if ($item) {
            return $item;
        } else {
            return $this->setOrderId($orderId)
                ->setQuoteId($quoteId);
        }
    }
805425
public function SaveNewPreorder($sArticleId = '')
    {
        // ------------------------------------------------------------------------
        $oGlobal = TGlobal::instance();
        $oMsgManager = TCMSMessageManager::GetInstance();
        if ($oGlobal->userDataExists('eMail') && TTools::IsValidEMail($oGlobal->GetuserData('eMail')) && !$oShopArticlePreorder = TdbShopArticlePreorder::LoadFromFields(array('shop_article_id' => $sArticleId, 'preorder_user_email' => $oGlobal->GetuserData('eMail')))) {
            $activePortal = $this->getPortalDomainService()->getActivePortal();
            $aPostData = array('shop_article_id' => $sArticleId, 'preorder_user_email' => $oGlobal->GetuserData('eMail'), 'preorder_date' => date('Y-m-d H:i:s'), 'cms_portal_id' => $activePortal->id);
            $this->LoadFromRow($aPostData);
            $this->AllowEditByAll(true);
            $this->Save();
            $this->AllowEditByAll(false);
            $oMsgManager->AddMessage('mail-preorder-form-eMail', 'SUCCESS-USER-SIGNUP-PREORDER-ARTICLE');

            return true;
        } else {
            if (!TTools::IsValidEMail($oGlobal->GetuserData('eMail'))) {
                $oMsgManager->AddMessage('mail-preorder-form-eMail', 'ERROR-E-MAIL-INVALID-INPUT');

                return false;
            } else {
                if ($oShopArticlePreorder = TdbShopArticlePreorder::LoadFromFields(array('shop_article_id' => $sArticleId, 'preorder_user_email' => $oGlobal->GetuserData('eMail')))) {
                    $oMsgManager->AddMessage('mail-preorder-form-eMail', 'ERROR-USER-SIGNUP-PREORDER-ARTICLE');

                    return false;
                } else {
                    return false;
                }
            }
        }
    }
781742
protected function _getParentProduct($sParentId)
    {
        if ($sParentId && $this->_oParentProd === null) {
            $this->_oParentProd = false;
            $oProduct = oxNew(\OxidEsales\Eshop\Application\Model\Article::class);
            if (($oProduct->load($sParentId))) {
                $this->_processProduct($oProduct);
                $this->_oParentProd = $oProduct;
            }
        }

        return $this->_oParentProd;
    }
578453
public function getByStockItemId($stockItemId)
    {
        $where = Entity::A_STOCK_ITEM_REF . '=' . (int)$stockItemId;
        $result = $this->get($where);
        return $result;
    }
467347
public function getById($stockistId)
    {
        if (!isset($this->instances[$stockistId])) {

            /** @var \Limesharp\Stockists\Api\Data\StockistInterface|\Magento\Framework\Model\AbstractModel $stockist */
            $stockist = $this->stockistInterfaceFactory->create();
            $this->resource->load($stockist, $stockistId);
            
            if (!$stockist->getId()) {
                throw new NoSuchEntityException(__('Requested stockist doesn\'t exist'));

           }
            $this->instances[$stockistId] = $stockist;
        }

        return $this->instances[$stockistId];;
    }
620491
public function updateItemCount($orderId, $itemId, $isAddition, $stepQuantity = 1)
    {
        $remove = false;
        $lastItem = false;
        $orderRepo = $this->em->getRepository('LibrinfoEcommerceBundle:Order');
        $itemRepo = $this->em->getRepository($this->orderItemClass);

        $order = $orderRepo->find($orderId);
        $item = $itemRepo->find($itemId);

        $orderStateMachine = $this->smFactory->get($order, 'sylius_order');

        if (!$orderStateMachine->can(OrderTransitions::TRANSITION_CONFIRM)) {
            return [
                'lastItem' => true,
                'message'  => $this->translator->trans('cannot_edit_order_because_of_state', [], 'SonataCoreBundle'),
            ];
        } else {
            if (!$item->isBulk()) {
                $quantity = ($isAddition ? $item->getQuantity() + $stepQuantity : $item->getQuantity() - $stepQuantity);
            } else {
                $quantity = ($isAddition ? $stepQuantity : 0);
            }

            if ($quantity < 1) {
                if ($order->countItems() < 2) {
                    $lastItem = true;
                } else {
                    $order->removeItem($item);
                    $remove = true;
                }
            } else {
                $this->orderItemQuantityModifier->modify($item, $quantity);
                $item->setQuantity($quantity);
                $item->recalculateUnitsTotal();
            }

            $order->recalculateItemsTotal();
            $this->orderProcessor->process($order);

            $this->em->persist($order);
            $this->em->flush();

            return $this->formatArray($order, $item, $remove, $lastItem);
        }
    }