public function addProduct() { $sess = Yii::app()->user->getState('order_product'); if (isset($_POST['OrderProduct']['id'])) { $product = Product::model()->findByPk($_POST['OrderProduct']['id']); $orderproduct = new OrderProduct(); $orderproduct->order_id = 0; $orderproduct->product_id = $product->id; $orderproduct->name = $product->getName(); $orderproduct->model = $product->model; $orderproduct->quantity = $_POST['OrderProduct']['quantity']; $orderproduct->price = $product->price; $orderproduct->total = $orderproduct->quantity * $product->price; $orderproduct->tax = 0; if ($this->addProductOption($product->id)) { $orderproduct->order_options = $this->_orderoption; $orderoptions = $this->_orderoption; if (!empty($sess)) { $addnew = false; foreach ($sess as $i => $cart) { $match = $match2 = false; $diff = $orderproduct->compare($cart); if ($diff) { $sess[$i]->quantity += $_POST['OrderProduct']['quantity']; $addnew = true; break; } } if ($addnew) { $sess[] = $orderproduct; } } else { $sess = array($orderproduct); } Yii::app()->user->setState('order_product', $sess); Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, Yii::t('info', 'Please fill out all required fields for product options')); $this->renderPartial('_form_order', array('orderproduct' => $sess), false, true); Yii::app()->end(); } else { Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, Yii::t('info', 'Please fill out all required fields for product options')); } } if (empty($sess)) { $sess = array(); } $norderopt = array(); if (isset($_POST['OrderProduct']['id'])) { $norderopt = $this->loadProductOption(isset($_POST['OrderProduct']['id'])); } $this->renderPartial('_form_order', array('orderproduct' => $sess, 'orderoption' => $norderopt), false, true); }