protected function tearDown()
 {
     //        /*delete all productOrders*/
     ProductOrders::model()->deleteAll();
     /*delete all products*/
     Product::model()->deleteAll();
     /*delete all orders*/
     Orders::model()->deleteAll();
     parent::tearDown();
 }
 public function tearDown()
 {
     /*delete all productOrders*/
     ProductOrders::model()->deleteAll();
     /*delete all products*/
     Product::model()->deleteAll();
     /*delete all orders*/
     Orders::model()->deleteAll();
     /*delete all customers*/
     Customer::model()->deleteAll();
 }
 /**
  *
  * @param Orders $orders
  * @param array $productList
  * @return array
  */
 private function saveProductOrders(Orders $orders, $productList = array())
 {
     $productOrders = array();
     /*iterate products*/
     foreach ($productList as $currentProduct) {
         /**
          * @var Product $productModel
          */
         $newProductOrder = new ProductOrders();
         $newProductOrder->order_id = $orders->id;
         $productModel = Product::model()->findByAttributes(array("name" => $currentProduct['product_name']));
         $newProductOrder->product_id = $productModel->id;
         $newProductOrder->quantity = intval($currentProduct['quantity']);
         if ($newProductOrder->save()) {
             /*decrease quantity of product*/
             $productModel->quantity -= intval($currentProduct['quantity']);
             $productModel->save();
         } else {
             throw new CHttpException(500, CHtml::errorSummary($newProductOrder));
         }
         /*add to collection */
         $productOrders[] = $newProductOrder;
     }
     return $productOrders;
 }