Example #1
0
 public function createAction()
 {
     if (isset($_POST['ajax']) && isset($_POST['getproducts'])) {
         $productModel = new Product();
         $campaign_id = AF::get($_POST, 'campaign_id', 0);
         $products = $productModel->getCampaignProducts($campaign_id);
         AF::setJsonHeaders('json');
         Message::echoJsonSuccess(array('message' => $products));
     }
     $model = new CampaignProduct();
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model);
     if (isset($_POST['model']) && $_POST['model'] == 'Campprod') {
         $model->fillFromArray($_POST);
         //$model->upsell_id="NULL:sql";
         //$model->user_id_created = $this->user->user_id;
         //$model->user_id_updated = $this->user->user_id;
         //$model->updated = 'NOW():sql';
         //$model->created = 'NOW():sql';
         //$model->model_uset_id = $this->user->user_id;
         if (isset($_POST['ajax'])) {
             if ($model->save()) {
                 $link = AF::link(array('campprod' => 'view'), array('campaign_id' => $model->campaign_id));
                 Message::echoJson('success', array('redirect' => $link));
             } else {
                 Message::echoJsonError(__('campprod_not_created') . ' ' . $model->errors2string);
             }
             die;
         }
         $model->save();
         $this->redirect();
     }
     $this->addToPageTitle('Create Campaign Product');
     $this->render('create', array('model' => $model));
 }