public function actionAddProduct($id) { $model = $this->getModel($id); if (isset($_POST['ExistingProducts'])) { // get products $ids = $_POST['ExistingProducts']['id']; $quantities = $_POST['ExistingProducts']['quantity']; $products = array(); foreach ($ids as $key => $id) { if ($id != 0) { // remove blanks $products[$key]['id'] = $id; $products[$key]['quantity'] = $quantities[$key]; } } // tie products to quote foreach ($products as $product) { $qp = new QuoteProduct(); $qp->quoteId = $model->id; $qp->productId = $product['id']; $qp->quantity = $product['quantity']; $qp->save(); } if (isset($_POST['recordId'])) { Yii::app()->clientScript->scriptMap['*.js'] = false; $contact = X2Model::model('Contacts')->findByPk($_POST['recordId']); $this->renderPartial('quoteFormWrapper', array('recordId' => $contact->id, 'accountName' => $contact->company), false, true); } } }