Changeset 22896


Ignore:
Timestamp:
2013/06/25 16:16:58 (11 years ago)
Author:
shutta
Message:

#2280 (SC_CartSession::getCartListの効率化)
TODOの解消。
同一セッション内で2回目呼び出し以降の無駄なDB参照を回避するよう改良。

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_13-dev/data/class/SC_CartSession.php

    r22856 r22896  
    357357 
    358358    /** 
     359     * getCartList用にcartSession情報をセットする 
     360     * 
     361     * @param integer $product_type_id 商品種別ID 
     362     * @param integer $key  
     363     * @return void 
     364     */ 
     365    function setCartSession4getCartList($productTypeId, $key) 
     366    { 
     367        $objProduct = new SC_Product_Ex(); 
     368 
     369        $this->cartSession[$productTypeId][$key]['productsClass'] 
     370            =& $objProduct->getDetailAndProductsClass($this->cartSession[$productTypeId][$key]['id']); 
     371 
     372        $price = $this->cartSession[$productTypeId][$key]['productsClass']['price02']; 
     373        $this->cartSession[$productTypeId][$key]['price'] = $price; 
     374 
     375        $this->cartSession[$productTypeId][$key]['point_rate'] 
     376            = $this->cartSession[$productTypeId][$key]['productsClass']['point_rate']; 
     377 
     378        $quantity = $this->cartSession[$productTypeId][$key]['quantity']; 
     379        $incTax = SC_Helper_TaxRule_Ex::sfCalcIncTax($price, 
     380            $this->cartSession[$productTypeId][$key]['productsClass']['product_id'], 
     381            $this->cartSession[$productTypeId][$key]['id'][0]); 
     382 
     383        $total = $incTax * $quantity; 
     384 
     385        $this->cartSession[$productTypeId][$key]['price_inctax'] = $incTax; 
     386        $this->cartSession[$productTypeId][$key]['total_inctax'] = $total; 
     387    } 
     388 
     389    /** 
    359390     * 商品種別ごとにカート内商品の一覧を取得する. 
    360391     * 
     
    364395    function getCartList($productTypeId) 
    365396    { 
    366         $objProduct = new SC_Product_Ex(); 
    367397        $max = $this->getMax($productTypeId); 
    368398        $arrRet = array(); 
     399 
     400        $const_name = '_CALLED_SC_CARTSESSION_GETCARTLIST_' . $productTypeId; 
     401        if (defined($const_name)) { 
     402            $is_first = true; 
     403        } else { 
     404            define($const_name, true); 
     405            $is_first = false; 
     406        } 
     407 
    369408        for ($i = 0; $i <= $max; $i++) { 
    370409            if (isset($this->cartSession[$productTypeId][$i]['cart_no']) 
    371410                && $this->cartSession[$productTypeId][$i]['cart_no'] != '') { 
    372411                // 商品情報は常に取得 
    373                 // TODO 同一インスタンス内では1回のみ呼ぶようにしたい 
    374                 $this->cartSession[$productTypeId][$i]['productsClass'] 
    375                     =& $objProduct->getDetailAndProductsClass($this->cartSession[$productTypeId][$i]['id']); 
    376  
    377                 $price = $this->cartSession[$productTypeId][$i]['productsClass']['price02']; 
    378                 $this->cartSession[$productTypeId][$i]['price'] = $price; 
    379  
    380                 $this->cartSession[$productTypeId][$i]['point_rate'] 
    381                     = $this->cartSession[$productTypeId][$i]['productsClass']['point_rate']; 
    382  
    383                 $quantity = $this->cartSession[$productTypeId][$i]['quantity']; 
    384                 $incTax = SC_Helper_TaxRule_Ex::sfCalcIncTax($price, 
    385                     $this->cartSession[$productTypeId][$i]['productsClass']['product_id'], 
    386                     $this->cartSession[$productTypeId][$i]['id'][0]); 
    387  
    388                 $total = $incTax * $quantity; 
    389  
    390                 $this->cartSession[$productTypeId][$i]['price_inctax'] = $incTax; 
    391                 $this->cartSession[$productTypeId][$i]['total_inctax'] = $total; 
     412 
     413                // 同一セッション内では初回のみDB参照するようにしている 
     414                if (!$is_first) { 
     415                    $this->setCartSession4getCartList($productTypeId, $i); 
     416                } 
    392417 
    393418                $arrRet[] = $this->cartSession[$productTypeId][$i]; 
Note: See TracChangeset for help on using the changeset viewer.