我在一个电子商务网站上工作,当用户第一次将产品添加到购物篮时,我收到以下错误,
遇到 PHP 错误
严重性:通知
消息:未定义的索引:orderDetails
文件名:库/MY_Cart.php
行号:59 遇到 PHP 错误
严重性:警告
消息:无法修改标头信息 - 标头已发送(输出开始于 /var/www/vhosts/akulaliving.com/httpdocs/CI-1.7.3/libraries/Exceptions.php:166)
文件名:库/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;
}