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?
priceto the$datavariable based on the triggeredif, as in the example above? Before theupdatemethod is executed, of course. - VenZell