I really need big help for this. I have a form, and in that form client can choose country, and document type, and there is add to cart button.
So when the client select everything he need, all parametars are send into the session like this (this is in controller):
$quantity = 1; //this is default quantity for all documents
if(isset($_POST['cartBtn'])) {
if(!isset(Yii::app()->session['cart_values'])) {
Yii::app()->session['cart_values'] = array();
}
$sessionCart = Yii::app()->session['cart_values'];
$productInfo = Product::model()->find('id=:id',(array(':id'=>$_POST['documents'])));
$sessionCart[] = array('product_id' => $_POST['documents'], 'document' => $productInfo->name, 'countries'=>$_POST['countries'], 'quantity'=> $quantity, 'price' => $unitCost);
Yii::app()->session['cart_values'] = $sessionCart;
$this->redirect(array($this->id."/cart"));
}
after submiting the form the client is redirected to cart form, here in this form he can update the quantity of documents. Now i have to determinate which column did the client select to update.
I try to do this in controller (under cart action) :
public function actionCart()
{
if(isset($_POST['cartBtnUpdate'])) {
$sessionCart['quantity'] = $_POST['quantity'];
}
$this->render('cart');
}
but when i do this nothing happened the value is 1, i enter 2 or 3 submit the form but value is 1.
Also I would like to delete the field if someone click the check box and submit the form, but i have no clue how to select the all session line to delete it.
Thanks.
Form code in cart view:
<?php
if (is_array(Yii::app()->session['cart_values']))
{
$total = 0;
foreach ( Yii::app()->session['cart_values'] as $value) {
$total += $value['price'];
?>
<tr id="TDcartTable">
<td class="docName">
<?php echo $value['document'] ?>
</td>
<td>
£ <?php echo number_format($value['price'], 2); ?>
</td>
<td>
<?php echo CHtml::textField('quantity', $value['quantity']); ?>
</td>
<td>
£ <?php echo number_format(($value['price'] * $value['quantity']), 2);
?>
</td>
<?php }
}
?>
<td>
</td>
</tr>
<tr>
<td class="column-last" colspan="6">
</td>
</tr>
<tr>
<td class="cart-order-total" colspan="6">
<?php echo CHtml::encode(Yii::t('app', 'Order Total')); ?>: £ <?php echo number_format($total, 2); ?>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" class="button" name="cartBtnUpdate" value="<?php echo CHtml::encode(Yii::t('app', 'Update Your Shopping Cart')); ?>">
</td>
<td colspan="4">
<input type="submit" class="button" name="cartBtnContinue" value="<?php echo CHtml::encode(Yii::t('app', 'Continue')); ?>">
</td>
</tr>