Welcome Guest, Not a member yet? Register   Sign In
Shopping Cart Class not work well
#1

Hi All,

I am green in CI, and I tried to use 'cart' libraries recently.
I follow the instruction from user guide and I find that record is added into database.
But, it is nothing can retrieve as I use $this->cart->contents().

environment:
+ Apache 2.4.4
+ MySQL 5.5.32 (Community Server)
+ PHP 5.6.3 (VC11 X86 32bit thread safe) + PEAR
+ phpMyAdmin 4.0.4

Anything I missed? Please help.


Thanks
Reply
#2

Have you loaded the library?

$this->load->library('cart');

Reply
#3

Hi Gufnex,

Yes, I load it in autoload.
Further, $this->cart->insert($data); is work as I've seen the data put into the database.
Reply
#4

Hi Rufnex,
I have loaded the library in autoload and $this->cart->insert($data); is work.
I can see the data inserted into database
Reply
#5

Can you show use your code to check if we see an error?

Reply
#6

I would advise you to create your own shopping cart library, the current library may not be available for next CodeIgniter versions as it is a DEPRECATED library (http://www.codeigniter.com/userguide3/li.../cart.html)
Reply
#7

cart_model

public function addItemToCart($pID, $pModel, $pName, $pQty, $pUnitPrice, $pisDiscount, $pisSuggestPrice, $pisShopSpecial, $pSprice, $pAmt)
{
$data = array(
'id' => $pID,
'qty' => $pQty,
'price' => $pUnitPrice,
'name' => $pModel,
'options' => array(
'name' => $pName,
'isDiscount' => $pisDiscount,
'isSuggestPrice' => $pisSuggestPrice,
'isShopSpecial' => $pisShopSpecial,
'sprice' => $pSprice
)
);

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

return array("pID" => $pID,
"pModel" => $pModel,
"pName" => $pName);

}

function getCart()
{
$result = $this->cart->contents();
return $result;
}

cart controller

public function addProduct()
{
$prodID = $this->input->post("prodID");
$pQty = $this->input->post("qty");

//product detail
$productDetail = $this->product_model->getProductDetail($prodID);

$pID = $productDetail['id'];
$pModel = $productDetail['modelno'];
$pName = $productDetail['prodname'];

if($productDetail['isDiscount'] == 1)
$pUnitPrice = $productDetail['dprice'];
else
$pUnitPrice = $productDetail['price'];

$pisSuggestPrice = $productDetail['isSuggestPrice'];
$pisShopSpecial = $productDetail['isShopSpecial'];
$pisDiscount = $productDetail['isDiscount'];
$pSprice = $productDetail['sprice'];
$pAmt = $pQty * $pUnitPrice;

$data['productInfo'] = $this->cart_model->addItemToCart($pID, $pModel, $pName, $pQty, $pUnitPrice, $pisDiscount, $pisSuggestPrice, $pisShopSpecial, $pSprice, $pAmt);

//prepare for category list header
$this->load->view('cart/addProduct',$data);
}

public function index()
{
$data['testcart'] = $this->cart_model->getCart();
$this->load->view('baseView',$data);
}

Honestly, I think this is not just only shopping cart problem, but also "session database" problem.
I can get the $this->session->userdata('logininfo') before I use the "session database".
But I can't now.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB