Ignore:
Timestamp:
2009/09/07 23:48:32 (15 years ago)
Author:
Seasoft
Message:

在庫を減らす処理の改訂

  • 不要な分岐を削減
  • 不明確な値を例外として扱う
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/comu-ver2/data/class/pages/shopping/LC_Page_Shopping_Complete.php

    r18276 r18283  
    646646        $objDb = new SC_Helper_DB_Ex(); 
    647647         
     648        if (!SC_Utils_Ex::sfIsInt($quantity)) { 
     649            $objQuery->rollback(); 
     650            SC_Utils_Ex::sfDispException(); 
     651        } 
     652         
    648653        $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?"; 
    649654        $arrRet = $objQuery->select("stock, stock_unlimited", "dtb_products_class", $where, $arrID); 
    650655 
    651         // 売り切れエラー 
    652         if(($arrRet[0]['stock_unlimited'] != '1' && $arrRet[0]['stock'] < $quantity) || $quantity == 0) { 
     656        if (($arrRet[0]['stock_unlimited'] != '1' && $arrRet[0]['stock'] < $quantity) || $quantity == 0) { 
     657            // 売り切れエラー 
    653658            $objQuery->rollback(); 
    654659            SC_Utils_Ex::sfDispSiteError(SOLD_OUT, "", true); 
    655         // 無制限の場合、在庫はNULL 
    656         } elseif($arrRet[0]['stock_unlimited'] == '1') { 
    657             $sqlval['stock'] = null; 
    658             $objQuery->update("dtb_products_class", $sqlval, $where, $arrID); 
     660        } 
     661         
    659662        // 在庫を減らす 
    660         } else { 
    661             $sqlval['stock'] = ($arrRet[0]['stock'] - $quantity); 
    662             if($sqlval['stock'] == "") { 
    663                 $sqlval['stock'] = '0'; 
    664             } 
    665             $objQuery->update("dtb_products_class", $sqlval, $where, $arrID); 
    666         } 
     663        $arrRawSql = array(); 
     664        $arrRawSql['stock'] = 'stock - ?'; 
     665        $arrRawSqlVal[] = $quantity; 
     666        $objQuery->update('dtb_products_class', array(), $where, $arrID, $arrRawSql, $arrRawSqlVal); 
    667667         
    668668        // 在庫無し商品の非表示対応 
    669669        if (NOSTOCK_HIDDEN === true) { 
    670             // 件数カウントバッチ実行 
    671             $objDb->sfCategory_Count($objQuery); 
     670            // 件数カウントバッチ実行 
     671            $objDb->sfCategory_Count($objQuery); 
    672672        } 
    673673         
Note: See TracChangeset for help on using the changeset viewer.