Using Ajax To Add Products To A List

I have an order form and I would like to add multiple products to an itemized list before it’s submitting. It’s pulling the product list from the product model.

OrderForm:


<div id="list"></div>

 	

    <div class="row">

		<?php echo $form->labelEx(Service::model(),'product_id'); ?>

		<?php echo $form->dropDownList(Product::model(),'product_id',CHtml::listData(Product::model()->findAll(), 'product_id', 'name')); ?>

		<?php echo $form->error(Product::model(),'product_id'); ?>

	</div>

    

	<?php echo CHtml::ajaxButton ("Add Product",CController::createUrl('order/UpdateAjax&id=' . $product_id),array('update' => '#list')); ?>

OrderController:


public function actionUpdateAjax($id)

    {

        // do something with the selected product id

    }

I know it’s very incomplete, but a little direction would be very helpful. This seems like something that would need to be commonly done in commerce situations. Perhaps I didn’t use the right vernacular when searching for a tutorial. Anyways, you’re help would be greatly appreciated!

here is my opinion:

1 declare a session to remember the added product IDs.

2 use a CActiveDataProvider to provide all the added product model for the ajax view.

3 the criteria of the dataProvider may be like this: SELECT * FROM tbl_product WHERE product_id IN ($_SESSION[array_of_id]);

4 render a view without layout (renderParticial) to gererate the HTML code for div#list. the dataProvider will be use as a data source here.

Take a good look at this:

For create a tabular form (all products detail toghether) tabular input manager js+tabular input

For insert the product in a dialog: dialog

They are both quite difficoult, but your task is absolutely not easy. Trust this articles.

Thanks for the tips. I’ll look over them tonight. I know it’s not going to be easy, but I’d like to make it as painless as possible… if that’s possible haha.

EDIT:

I actually went with a variation of linuor’s thinking. The data isn’t sensitive and I want to keep it even if the user accidentally closes the page. So far it’s working fairly well!