CodeIgniter Forums
Adding an item to the Cart always returns 2 (qty items) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forum-6.html)
+--- Forum: Issues (https://forum.codeigniter.com/forum-19.html)
+--- Thread: Adding an item to the Cart always returns 2 (qty items) (/thread-64981.html)



Adding an item to the Cart always returns 2 (qty items) - thanhthangnet - 04-16-2016

Hello everybody, as the title,

I use the library cart
And when I added 1 product on the code below:
PHP Code:
$data = array(
 
       'id'      => 'sku_123ABC',
 
       'qty'     => 1,
 
       'price'   => 39.95,
 
       'name'    => 'T-Shirt',
 
       'options' => array('Size' => 'L''Color' => 'Red')
);

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


The result is a multiple of 2 qty as follows:

PHP Code:
Array
(
 
   [0256a32c98ce49afbe2a4eb8c96c5884] => Array
 
       (
 
           [id] => sku_123ABC
            
[qty] => 2
            
[price] => 39.95
            
[name] => T-Shirt
            
[options] => Array
 
               (
 
                   [Size] => L
                    
[Color] => Red
                
)

 
           [rowid] => 0256a32c98ce49afbe2a4eb8c96c5884
            
[subtotal] => 79.9
        
)




Similarly QTY will add 2 as 4,6,8 ... when I add 1 ITEM into cart


RE: Adding an item to the Cart always returns 2 (qty items) - PaulD - 04-17-2016

Hi,

I had something like this once, a long time ago, and it turned out to be that the page was being loaded twice, because (I think) it was a malformed href causing the page to reload.

Sorry if that is a bit vague, as I don't really recall the cause in any detail, but I do remember being suprised to find the page was loading twice, due to a browser interpretation of the html.

So it sounds to me like your page is double loading, causing two items to be added rather than one.

Hope that helps in some way,

Best wishes,

Paul.

PS If I remember right, it was an empty image src in the html


RE: Adding an item to the Cart always returns 2 (qty items) - thanhthangnet - 04-17-2016

Hi,
@PaulD: Thanks for your comments as it helped me to have more confidence

Cause of the fault is not Codeigniter library.
The reason is that I insert 2 times the products in my ajax request.
Library cart works well


RE: Adding an item to the Cart always returns 2 (qty items) - PaulD - 04-17-2016

Well, if it helps at all, CI "works well" in virtually all cases (except the very, very rare bug that gets reported by other people, I have never found one myself).

In fact, I am pretty sure that 100% of the time problems and weird behavior has always turned out to be something I am doing, rather than something CI is doing.

Hope you enjoy CI as much as I have.

Best wishes,

Paul.