source/Application/Model/Article.php
public function reduceStock($dAmount, $blAllowNegativeStock = false)
    {
        $this->actionType = ACTION_UPDATE_STOCK;
        $this->beforeUpdate();

        $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $query = 'select oxstock from oxarticles where oxid = ' . $database->quote($this->getId()) . ' FOR UPDATE ';
        $actualStock = $database->getOne($query);

        $iStockCount = $actualStock - $dAmount;
        if (!$blAllowNegativeStock && ($iStockCount < 0)) {
            $dAmount += $iStockCount;
            $iStockCount = 0;
        }
        $this->oxarticles__oxstock = new \OxidEsales\Eshop\Core\Field($iStockCount);

        $query = 'update oxarticles set oxarticles.oxstock = ' . $database->quote($iStockCount) .
                 ' where oxarticles.oxid = ' . $database->quote($this->getId());
        $database->execute($query);
        $this->onChange(ACTION_UPDATE_STOCK);

        return $dAmount;
    }
public function reduceStock($dAmount, $blAllowNegativeStock = false)
    {
        $this->actionType = ACTION_UPDATE_STOCK;
        $this->beforeUpdate();

        $database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        $query = 'select oxstock from oxarticles where oxid = ' . $database->quote($this->getId()) . ' FOR UPDATE ';
        $actualStock = $database->getOne($query);

        $iStockCount = $actualStock - $dAmount;
        if (!$blAllowNegativeStock && ($iStockCount < 0)) {
            $dAmount += $iStockCount;
            $iStockCount = 0;
        }
        $this->oxarticles__oxstock = new \OxidEsales\Eshop\Core\Field($iStockCount);

        $query = 'update oxarticles set oxarticles.oxstock = ' . $database->quote($iStockCount) .
                 ' where oxarticles.oxid = ' . $database->quote($this->getId());
        $database->execute($query);
        $this->onChange(ACTION_UPDATE_STOCK);

        return $dAmount;
    }
public function reduceStock ( $ dAmount , $ blAllowNegativeStock = false ) { $ this -> actionType = ACTION_UPDATE_STOCK ; $ this -> beforeUpdate ( ) ; $ database = \ OxidEsales \ Eshop \ Core \ DatabaseProvider :: getDb ( ) ; $ query = 'select oxstock from oxarticles where oxid = ' . $ database -> quote ( $ this -> getId ( ) ) . ' FOR UPDATE ' ; $ actualStock = $ database -> getOne ( $ query ) ; $ iStockCount = $ actualStock - $ dAmount ; if ( ! $ blAllowNegativeStock && ( $ iStockCount < 0 ) ) { $ dAmount += $ iStockCount ; $ iStockCount = 0 ; } $ this -> oxarticles__oxstock = new \ OxidEsales \ Eshop \ Core \ Field ( $ iStockCount ) ; $ query = 'update oxarticles set oxarticles.oxstock = ' . $ database -> quote ( $ iStockCount ) . ' where oxarticles.oxid = ' . $ database -> quote ( $ this -> getId ( ) ) ; $ database -> execute ( $ query ) ; $ this -> onChange ( ACTION_UPDATE_STOCK ) ; return $ dAmount ; }
Reduce article stock. return the affected amount

@param float $dAmount              amount to reduce
@param bool  $blAllowNegativeStock are negative stocks allowed?

@return float
Reduce article stock . return the affected amount