Stock/Helper/AbstractAvailabilityHelper.php
public function getAvailability(StockSubjectInterface $subject, bool $root = true, bool $short = false)
    {
        $minQty = $aQty = $rQty = 0;
        $maxQty = INF;
        $minMsg = $maxMsg = $aMsg = $rMsg = null;

        $formatter = $this->getFormatter();

        if ($root && $subject->isQuoteOnly()) {
            $maxQty = 0;
            $oMsg = $maxMsg = $this->translate('quote_only', [], $short);
        } else {
            // Minimum quantity/message
            if (0 < $minQty = $subject->getMinimumOrderQuantity()) {
                $minMsg = $this->translate('min_quantity', [
                    '%min%' => $formatter->number($minQty),
                ], $short);
            }

            // Available quantity/message
            if ($subject->getStockMode() === StockSubjectModes::MODE_DISABLED) {
                $aQty = INF;
                $aMsg = $this->translate('available', [], $short);
            } elseif (0 < $aQty = $subject->getAvailableStock()) {
                $maxQty = $aQty;
                $aMsg = $this->translate('in_stock', [
                    '%qty%' => $formatter->number($aQty),
                ], $short);
            } else {
                $maxQty = 0;
            }

            // Resupply quantity/message
            if ((0 < $qty = $subject->getVirtualStock()) && (null !== $eda = $subject->getEstimatedDateOfArrival())) {
                $today = new \DateTime();
                $today->setTime(23, 59, 59);
                if ($today < $eda && 0 < $rQty = $qty - $aQty) {
                    $rMsg = $this->translate('pre_order', [
                        '%eda%' => $formatter->date($eda),
                        '%qty%' => $formatter->number($qty),
                    ], $short);
                    $maxQty = $qty;
                }
            }

            // Overflow message
            if ($root && $subject->isEndOfLife()) {
                $oMsg = $this->translate('end_of_life', [], $short);
            } elseif (
                $subject->getStockMode() === StockSubjectModes::MODE_JUST_IN_TIME &&
                0 < $days = $subject->getReplenishmentTime()
            ) {
                $maxQty = INF;
                $oMsg = $this->translate('replenishment', [
                    '%days%' => $days,
                ], $short);
            } else {
                $oMsg = $this->translate('out_of_stock', [], $short);
            }

            if (0 < $maxQty && $maxQty !== INF) {
                $maxMsg = $this->translate('max_quantity', [
                    '%max%' => $formatter->number($maxQty),
                ], $short);
            } elseif (0 == $maxQty) {
                $maxMsg = $oMsg;
            }
        }

        return new Availability($oMsg, $minQty, $minMsg, $maxQty, $maxMsg, $aQty, $aMsg, $rQty, $rMsg);
    }
public function getAvailability(StockSubjectInterface $subject, bool $root = true, bool $short = false)
    {
        $minQty = $aQty = $rQty = 0;
        $maxQty = INF;
        $minMsg = $maxMsg = $aMsg = $rMsg = null;

        $formatter = $this->getFormatter();

        if ($root && $subject->isQuoteOnly()) {
            $maxQty = 0;
            $oMsg = $maxMsg = $this->translate('quote_only', [], $short);
        } else {
            // Minimum quantity/message
            if (0 < $minQty = $subject->getMinimumOrderQuantity()) {
                $minMsg = $this->translate('min_quantity', [
                    '%min%' => $formatter->number($minQty),
                ], $short);
            }

            // Available quantity/message
            if ($subject->getStockMode() === StockSubjectModes::MODE_DISABLED) {
                $aQty = INF;
                $aMsg = $this->translate('available', [], $short);
            } elseif (0 < $aQty = $subject->getAvailableStock()) {
                $maxQty = $aQty;
                $aMsg = $this->translate('in_stock', [
                    '%qty%' => $formatter->number($aQty),
                ], $short);
            } else {
                $maxQty = 0;
            }

            // Resupply quantity/message
            if ((0 < $qty = $subject->getVirtualStock()) && (null !== $eda = $subject->getEstimatedDateOfArrival())) {
                $today = new \DateTime();
                $today->setTime(23, 59, 59);
                if ($today < $eda && 0 < $rQty = $qty - $aQty) {
                    $rMsg = $this->translate('pre_order', [
                        '%eda%' => $formatter->date($eda),
                        '%qty%' => $formatter->number($qty),
                    ], $short);
                    $maxQty = $qty;
                }
            }

            // Overflow message
            if ($root && $subject->isEndOfLife()) {
                $oMsg = $this->translate('end_of_life', [], $short);
            } elseif (
                $subject->getStockMode() === StockSubjectModes::MODE_JUST_IN_TIME &&
                0 < $days = $subject->getReplenishmentTime()
            ) {
                $maxQty = INF;
                $oMsg = $this->translate('replenishment', [
                    '%days%' => $days,
                ], $short);
            } else {
                $oMsg = $this->translate('out_of_stock', [], $short);
            }

            if (0 < $maxQty && $maxQty !== INF) {
                $maxMsg = $this->translate('max_quantity', [
                    '%max%' => $formatter->number($maxQty),
                ], $short);
            } elseif (0 == $maxQty) {
                $maxMsg = $oMsg;
            }
        }

        return new Availability($oMsg, $minQty, $minMsg, $maxQty, $maxMsg, $aQty, $aMsg, $rQty, $rMsg);
    }
Returns the subject availability for the given quantity.

@param StockSubjectInterface $subject
@param bool                  $root
@param bool                  $short

@return Availability