Example #1
0
 function getavailablebycampaignAction()
 {
     $this->checkLogin();
     AF::setJsonHeaders('json');
     $campaign_id = AF::get($_POST, 'campaign_id', false);
     if (!$campaign_id) {
         Message::echoJsonError(__('incorrect_campaign_id'));
     }
     $modelProduct = new Product();
     $products = $modelProduct->getAvailableByCampaignID($campaign_id);
     $modelShipping = new Shipping();
     $shipping = $modelShipping->getAvailableByCampaignID($campaign_id);
     $modelGateways = new Gateway();
     $gateways = $modelGateways->getAvailableByCampaignID($campaign_id);
     //$campaignModel = new Campaign();
     //$campaignModel->fillFromDbPk($campaign_id);
     //$campaign = $campaignModel->getDataArray();
     //$countryModel = new Country();
     //$countries = $countryModel->getCountries($campaignModel->country_id);
     Message::echoJsonSuccess(array('message' => array('products' => $products, 'shipping' => $shipping, 'gateways' => $gateways)));
     exit;
 }
Example #2
0
 public function createAction()
 {
     $model = new Order();
     $_POST['status'] = 'new';
     $isPayment = AF::get($_POST, 'is_payment');
     if (!$isPayment) {
         $_POST['ps'] = 'pn';
         $_POST['payment_method'] = 'cc_debit';
     }
     /*$rtr = '';
     			foreach($_POST as $k => $v) {
     	$rtr .= " '".$k."' => '".$v."',";	
     }
     Message::echoJsonSuccess($rtr);*/
     // is this also a new customer creation
     if (isset($_POST['newCus']) && $_POST['newCus'] == 1) {
         $cust = new Customer();
         $this->performAjaxValidation($cust);
         //$shipData = (array)json_decode($_POST['shipAddr']);
         //$shipData['address_type'] = 'shipping';
         $this->performAjaxFormFieldsValidation($_POST, explode(',', 'shipping_fname,shipping_lname,shipping_phone,shipping_address1,shipping_city,shipping_state_id,shipping_country_id,shipping_zip'));
         //Message::echoJsonSuccess('made it2');
         if (!$_POST['billingSameAsShipping']) {
             //$billData = (array)json_decode($_POST['billAddr']);
             //$billData['address_type'] = 'billing';
             $this->performAjaxFormFieldsValidation($_POST, explode(',', 'billing_fname,billing_lname,billing_phone,billing_address1,billing_city,billing_state_id,billing_country_id,billing_zip'));
         }
         $orderRules = "campaign_id,gateway_id,shipping_id,amount_product,amount_shipping,payment_total";
     } else {
         $_POST['newCus'] = 0;
         $orderRules = "customer_id,campaign_id,gateway_id,shipping_id,amount_product,amount_shipping,payment_total,address_id,billing_address_id";
         if (isset($_POST['address_id']) && empty($_POST['billing_address_id'])) {
             $_POST['billing_address_id'] = $_POST['address_id'];
         }
         // before billing validation
     }
     // Uncomment the following line if AJAX validation is needed
     $this->performAjaxValidation($model, explode(',', $orderRules));
     if (isset($_POST['model']) && $_POST['model'] == 'Order') {
         $isOrderPay = $this->access->actionAccess('order_is_pay') ? (bool) AF::get($_POST, 'is_payment') : false;
         $_POST['is_payment'] = $isOrderPay ? 1 : 0;
         // JSON success and error commands handled in the WS functions
         $ws = new WS();
         $ws->crmInit($_POST);
         $ws->process();
     }
     $orderID = AF::get($this->params, 'order_id', false);
     $prospectID = AF::get($this->params, 'prospect_id', false);
     $payments = array();
     if ($orderID) {
         $model->fillFromDbPk($orderID);
         // if we use clone model then we cannot grab related fields
         $model->getCopyModel();
         $orderProducts = OrderProducts::getProductsArrayByOrder($model->order_id);
         $payment_methods = ProfileGateways::getMethodsByProfileGateway($model->campaign->profile_id, $model->gateway_id);
         $cPayments = new Payments('Payment');
         $payments = $cPayments->getResultsByCustomerId($model->customer_id, false);
     } elseif ($prospectID) {
         $modelProspect = Prospect::model()->findByPk($prospectID);
         if (!$modelProspect) {
             throw new AFHttpException(0, 'incorrect_id');
         }
         $model->customer_id = $modelProspect->customer_id;
         $model->campaign_id = $modelProspect->campaign_id;
         $model->address_id = $modelProspect->address_id;
         $orderProducts = array();
         $payment_methods = array();
     } else {
         $orderProducts = array();
         $payment_methods = array();
     }
     $productModel = new Product();
     $products = $productModel->getAvailableByCampaignID($model->campaign_id);
     $countryModel = new Country();
     $languages = $countryModel->getLanguages();
     $states = $model->country_id ? State::model()->getStatesByCID($model->country_id) : array();
     //$model->country_ids='de,ir';
     $countries = $countryModel->getCountries();
     $campaigns = Campaign::model()->cache()->findAllInArray();
     $shippingModel = new Shipping();
     $shipping = $shippingModel->getAvailableByCampaignID($model->campaign_id);
     $modelGateways = new Gateway();
     //$modelGateways->getGateways()
     $gateways = $orderID ? $modelGateways->getAvailableByCampaignID($model->campaign_id) : array();
     $methods = Method::model()->cache()->findAllInArray();
     $fields_expyear = array('current_year' => date("Y"), 'last_year' => date("Y") + 12);
     Assets::js('jquery.form');
     Assets::js('jquery.autocomplete');
     Assets::js('as24.bind-1.3.5.min');
     Assets::js('jquery-ui');
     Assets::css('jquery-ui');
     $this->addToPageTitle('Create Order');
     $this->render('create', array('model' => $model, 'products' => $products, 'languages' => $languages, 'campaigns' => $campaigns, 'states' => $states, 'countries' => $countries, 'fields_expyear' => $fields_expyear, 'shipping' => $shipping, 'gateways' => $gateways, 'orderProducts' => $orderProducts, 'payment_methods' => $payment_methods, 'payments' => $payments, 'methods' => $methods));
 }