How to pass form input value to the model ?
hi guys
i have developed an ecommerce site when we are adding product to the cart now its adding as 1 qty since i don't have qty input
and this is my add to cart function in shop model
public function add($item,$id) {
$storedItem =['qty' => 0, 'price' => $item->price, 'item' => $item];
if($this->items) {
if(array_key_exists($id,$this->items)) {
$storedItem = $this->items[$id];
}
}
$storedItem['qty']++;
$storedItem['price'] = $item->price * $storedItem['qty'];
$this->items[$id] = $storedItem;
$this->totalQty++;
$this->totalPrice += $item->price;
}
i would like to pass qty value to this model from view
any help ?
Just add a quantity parameter to your add method and change $storedItem['qty']++; to $storedItem['qty'] += $qty;
I'm assuming you have some sort of form that adds the item to the cart when submitted by calling that add method on the cart.
You can just add a quantity field to the form and pass it along with the other parameters when you call the add method.
and how to make dynamic value of quantity to parameter when we have a quantity box.
Please or to participate in this conversation.