コード例 #1
0
 public function actionUpdateImage($id, $item_number_flag = '0')
 {
     if ($item_number_flag == '0') {
         $model = $this->loadModel($id);
     } else {
         $model = Item::model()->find('item_number=:item_number', array(':item_number' => $id));
     }
     $price_tiers = PriceTier::model()->getListPriceTierUpdate($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (Yii::app()->user->checkAccess('item.update')) {
         if (isset($_POST['Item'])) {
             $old_price = $model->unit_price;
             $model->attributes = $_POST['Item'];
             //$qty = isset($_POST['Item']['quantity']) ? $_POST['Item']['quantity'] : 0;
             //$model->quantity = $qty;  //A buggy was not noticed every update reset item to zero EM EUY
             $publisher_name = $_POST['Item']['publisher_id'];
             $category_name = $_POST['Item']['category_id'];
             $author_name = $_POST['Item']['author_id'];
             $publisher_id = Publisher::model()->savePublisher($publisher_name);
             if ($publisher_id !== null) {
                 $model->publisher_id = $publisher_id;
             }
             $author_id = Author::model()->saveAuthor($author_name);
             if ($author_id !== null) {
                 $model->author_id = $author_id;
             }
             $category_id = Category::model()->saveCategory($category_name);
             if ($category_id !== null) {
                 $model->category_id = $category_id;
             }
             if ($model->validate()) {
                 $transaction = Yii::app()->db->beginTransaction();
                 try {
                     if ($model->save()) {
                         if (isset($_POST['Item']['count_interval'])) {
                             Item::model()->saveItemCounSchedule($model->id);
                         }
                         ItemPriceTier::model()->saveItemPriceTier($model->id, $price_tiers);
                         // Product Price (retail price) history
                         ItemPrice::model()->saveItemPrice($model->id, $model->unit_price, $old_price);
                         $this->addImages($model);
                         $transaction->commit();
                         Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, 'Item Id : <strong>' . $model->name . '</strong> have been saved successfully!');
                         $this->redirect(array('admin'));
                     }
                 } catch (Exception $e) {
                     $transaction->rollback();
                     //print_r($e);
                     Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_WARNING, 'Oop something wrong : <strong>' . $e);
                 }
             }
         }
     } else {
         //throw new CHttpException(403, 'You are not authorized to perform this action');
         $this->redirect(array('site/ErrorException', 'err_no' => 403));
     }
     $this->render('update_image', array('model' => $model, 'price_tiers' => $price_tiers));
 }
コード例 #2
0
 protected function findItemPriceTier($item_id, $price_tier_id)
 {
     $item_price_tier = ItemPriceTier::model()->find('item_id=:item_id AND price_tier_id=:price_tier_id', array(':item_id' => (int) $item_id, ':price_tier_id' => (int) $price_tier_id));
     if (!$item_price_tier) {
         $item_price_tier = new ItemPriceTier();
     }
     return $item_price_tier;
 }