1

私はeコマースサイトで作業していますが、ユーザーが初めてバスケットに商品を追加すると、次のエラーが発生します。

PHPエラーが発生しました

重大度:通知

メッセージ:未定義のインデックス:orderDetails

ファイル名:libraries / MY_Cart.php

行番号:59PHPエラーが発生しました

重大度:警告

メッセージ:ヘッダー情報を変更できません-ヘッダーは既に送信されています(出力は/var/www/vhosts/akulaliving.com/httpdocs/CI-1.7.3/libraries/Exceptions.php:166で開始されています)

ファイル名:libraries / Session.php

行番号:662

は、次のコードでバスケットに商品を追加します。

if ($this->input->post('btnAddToBag'))
        {

            $derivativeId = $this->input->post('selDerivative-1');
            $quantity = $this->input->post('selQuantity');
            $derivative = $this->Product_model->GetProducts(array('pdId' => $derivativeId), 'small');

            // Add item to shopping bag.
            $attributes = $this->Product_model->GetProductDerivatives(array('pdId' => $derivativeId));
            $this->Checkout_model->AddProduct($derivative, $attributes, $quantity);
            $this->data['message'] = 'Item added to Shopping Bag.';

            // Update Delivery Price
            $this->Checkout_model->updateDelivery(49);

            //get the bag details
            $this->data['items'] = $this->Checkout_model->GetProducts();        
        }

呼び出されるモデル関数はこれです、

function AddProduct($derivative, $attributes, $quantity)
{
    $data = array(
       'id'         => $derivative->pdId,
       'qty'        => $quantity,
       'price'      => ($derivative->productSavingType == 'none' ? $derivative->productPrice : $derivative->productSavingPrice),
       'name'       => $derivative->productTitle,
       'attributes' => $attributes['attributeValues'],
       'refNo'      => $derivative->pdRefNo,
       'productId'  => $derivative->productId,
       'set'        => $derivative->productIsSet,
       'hasImage'   => $derivative->hasImage,
       'imageUrl'   => $derivative->imageUrl,
       'imageAlt'   => $derivative->imageAlt,
       'stockLevel' => $derivative->pdStockLevel,
       'leadTime'   => $derivative->pdLeadTime
    );

    $data['nonDiscountedPrice'] = $data['price'];
    if ($derivative->productSavingType == 'end-of-season')
    {
        $data['nonDiscountedPrice'] = $derivative->productPrice;
    }

    $this->cart->insert($data);
}

エラーが不平を言っているコードは次のとおりです、

function _insert($items=array())
{
    if (isset($items['options']) AND count($items['options']) > 0)
    {
        $rowid = md5($items['id'].implode('', $items['options']));
    }
    else
    {
        $rowid = md5($items['id']);
    }

    if (isset($this->_cart_contents[$rowid]))
    {
        if (!isset($items['qty']))
        {
            return FALSE;
        }

        // Already Exists, we need to update the total for this item
        $new_qty = $items['qty'];
        $items['qty'] = $items['qty'] + $this->_cart_contents[$rowid]['qty'];

        $items['rowid'] = $rowid;

        if ($this->_update($items))
        {
            return TRUE;
        }
        return FALSE;
    }

    // Doesn't exist, we need to insert this item.
    if (parent::_insert($items))
    {
        // Update our total.
        if (isset($this->_cart_contents[$rowid]))
        {
            $this->real_total_items += $this->_cart_contents[$rowid]['qty'];
            if ($this->_cart_contents['orderDetails']['discount'] > 0)
            {
                $this->_cart_contents[$rowid]['price'] = $this->_cart_contents[$rowid]['nonDiscountedPrice'];
                $this->_save_cart();
            }
        }
        return TRUE;
    }
    return FALSE;
}
4

5 に答える 5

1

Joomla?$this->_cart_contents['orderDetails']これは、使用される前に定義されていない通知です。事前に定義するか、通知をオフにすると、消えるはずです。

于 2011-04-28T12:55:48.890 に答える
1

PHPがNOTICEを出力し、セッションヘッダーがすでにエラーを送信していることは間違いありません。

error_reportingphp.iniでその行を見つけて、これに変更します

error_reporting = E_ALL & ~E_NOTICE

apacheインスタンスを再起動し、問題が解決するかどうかを確認します。

于 2011-04-28T12:56:34.010 に答える
0

E_NOTICEのPHPエラーを表示するようにサーバー構成を設定している可能性があります(これは開発では正常です)。E_NOTICEが生成されるため(MY_Cart.php)、これは最初にブラウザーにエコーされます。また、すでにブラウザの出力があるため、「ヘッダー情報を変更できません」(libraries / Session.php)という警告が表示されます。おそらく、header()関数などを実行しているためです。

これを解決するには、E_NOTICEの原因を修正するか(「orderDetails」キーのissetチェックを忘れましたか?) 、コードの先頭にerror_reporting(E_ALL&〜E_NOTICE) を設定してE_NOTICEを非表示にします。

于 2011-04-28T13:03:40.820 に答える
0

これを使用する前に、変数のデフォルト値を定義する必要があります

この警告を解決します。

于 2011-04-28T13:08:10.747 に答える
0
if (**$this->_cart_contents['orderDetails']['discount'] > 0**)
        {
            $this->_cart_contents[$rowid]['price'] = $this->_cart_contents[$rowid]['nonDiscountedPrice'];
            $this->_save_cart();
        }

:: _ cart_contents ['orderDetails']変数が存在しないため、CIは通知メッセージをスローします。

php.iniのエラー設定を変更したくない場合は、以下のように変更して試してみてください。

if (isset($this->_cart_contents['orderDetails']['discount'])&& ($this->_cart_contents['orderDetails']['discount']>0))
于 2011-04-28T13:10:22.293 に答える