There is an online store. Built on codeignither. The situation is such that there is a product with 4 different prices. Price for one piece, price for 2 pieces, price for 3 pieces, price for 4 pieces. Adding goods made.

function add_cart(){ $id = $this->input->post('id'); $count = $this->input->post('count'); $cart = array( 'id' => $id, 'qty' => $count, 'price' => $this->input->post('price'), 'name' => $this->input->post('title'), 'images' => $this->input->post('images') ); $product = $this->pages_model->get_product_info($id); if ($cart['qty']==1){ $cart['price'] = $product['price']; } if ($cart['qty']==2){ $cart['price'] = $product['price2']; } if ($cart['qty']==3){ $cart['price'] = $product['price3']; } if ($cart['qty']==4){ $cart['price'] = $product['price4']; } $return['rowID'] = $this->cart->insert($cart); } 

Some pieces of code dropped. The essence is simple, I get the product id and other parameters. Then I check the amount I added, and appropriately assign this price. But how to make it work when updating the count? By Update Working such a function.

 function update_cart(){ for ($i = 1; $i <= $this->cart->total_items(); $i++) { $item = $this->input->post($i); $data = array( 'rowid' => $item['rowid'], 'qty' => $item['qty'] ); $this->cart->update($data); } redirect('pages/cart'); } 

Updates only the count for a given rowid. The price can not be updated ((((What can I do?

  • How did you try to update the price? Why did you decide that you can not upgrade? Tried to transfer the price to the $data variable based on the triggered if , as in the example above? Before the update method is executed, of course. - VenZell
  • Yes, I tried it does not work. - duddeniska
  • Show your attempt - VenZell
  • Indicate in question about which version of CodeIgniter in question. According to the documentation, you can update any property that was inserted. codeigniter3.info/guide/libraries/cart#updating-the-cart - VenZell

1 answer 1

Solved the issue. Just need to do as here. http://blog.thecodingbox.me/codeigniter-cart-class-extended-to-update-price/

And then update already with the price