Example #1
0
 public function beforeDelete()
 {
     // if there are orders for this campaign, do not allow deletion
     if ($this->getCountOrders()) {
         return false;
     }
     // No orders are present for this camp.  delete any and all associated camp values
     // upsell products
     $campUpsells = new Upsells('Upsell');
     $campUpsells->loadUpsellsByCampaignId($this->campaign_id);
     $campUpsells->deleteUpsellsFromDb();
     unset($campUpsells);
     // camp products
     $campProducts = new CampaignProducts('CampaignProduct');
     $campProducts->load($this->campaign_id);
     $campProducts->deleteCampaignProductsFromDb();
     unset($campProducts);
     // camp shipping
     $campShip = new CampaignShippings('CampaignShipping');
     $campShip->load($this->campaign_id);
     $campShip->deleteCampaignShippingsFromDb();
     unset($campShip);
     // attach
     $campAttach = new CampaignAttachs('CampaignAttach');
     $campAttach->load($this->campaign_id);
     $campAttach->deleteCampaignAttachsFromDb();
     unset($campAttach);
     // combo
     $campCombos = new CCombos('CCombo');
     $campCombos->load($this->campaign_id);
     $campCombos->deleteCampaignCombosFromDb();
     unset($campCombos);
     // emails
     $campEmail = new CampaignEmails('CampaignEmail');
     $campEmail->load($this->campaign_id);
     $campEmail->deleteCampaignEmailsFromDb();
     unset($campEmail);
     // pixels
     $campPixels = new Pixels('Pixel');
     $campPixels->load($this->campaign_id);
     $campPixels->deleteCampaignPixelsFromDb();
     unset($campPixels);
     // pixel rates
     $sql = "DELETE FROM pixel_rates WHERE campaign_id = ?i";
     self::$_msql->query($sql, $this->campaign_id);
     /*$campPixelRates = new PixelRates('PixelRate');
     		$campPixelRates->load($this->campaign_id);
     		$campPixelRates->deleteCampaignPixelRatesFromDb();
     		unset($campPixelRates);*/
     return TRUE;
 }
Example #2
0
 private function buildOrder()
 {
     if (in_array($this->wsType, array('o', 'l', 'x1'))) {
         // 2Step and LC and CRM
         $this->order = new Order();
         $arr = $this->wsType != 'x1' ? $this->prospect->getDataArray() : array('customer_id' => $this->customer->customer_id, 'address_id' => $this->shippingAddress->address_id, 'campaign_id' => $this->campaign->campaign_id);
         $this->order->fillFromArray($arr);
         unset($arr);
         // check to see if there is already an order created for this prospect, in case error occurred previously
         // if so, don't load all the order info from the DB.  set the PK and use the info passed over from the webpage
         //if($this->order->orderExists($this->campaign->campaign_id, $this->customer->customer_id,$this->shippingAddress->address_id))
         //$this->newOrder = false;
         // BlueSnap Pending Order Check
         // Has an order already been submitted to the gateway and is pending final approval?  If so, redirect to the thankyou page
         if ($this->order->orderPendingAttemptExists($this->campaign->campaign_id, $this->customer->customer_id)) {
             $this->thankYou(true);
         }
         // SALVAGE UPSELL ORDER CHECK
         // check to see if there is already an order created
         // if so, don't load all the order info from the DB.  set the PK and use the info passed over from the webpage
         if ($this->campaign->hasUpsells() && $this->order->orderSalvageExists($this->campaign->campaign_id, $this->customer->customer_id, $this->shippingAddress->address_id)) {
             $this->newOrder = false;
         }
         if ($this->intervalCheck) {
             $checkTime = $this->prospect->created;
         }
     } else {
         if (in_array($this->wsType, array('c'))) {
             // 1Click and Charity Attach
             if ($this->campaign->attach) {
                 $this->order->parent_id = $this->order->order_id;
             }
             $this->order->getCopyModel();
             //cloneModel
             $checkTime = $this->order->updated;
             $this->order->campaign_id = $this->campaign->campaign_id;
             $this->order->flags = '';
             // check to see if there is already an order created for this prospect, in case error occurred previously
             //if($this->order->orderExists($this->campaign->campaign_id, $this->order->customer_id, $this->order->address_id))
             //$this->newOrder = false;
             if ($this->newOrder) {
                 $this->order->click_id = $this->click->click_id;
             }
         }
     }
     if ($this->intervalCheck) {
         // is this request still valid?  set to one day timespan
         $this->checkInterval($checkTime);
     }
     unset($checkTime);
     $this->order->created = $this->order->updated = 'NOW():sql';
     //date("Y-m-d H:i:s");
     // set gateway to invalid number so we can save the order record.  gateway will be calculated once we have built the payment record
     // IGNORE FOR ATTACHMENT/CHARITY CAMPS
     if (!$this->campaign->attach) {
         $this->order->gateway_id = 9000;
     }
     // demo gateway
     if (isset($this->post['gateway_id'])) {
         $this->order->gateway_id = $this->post['gateway_id'];
     }
     // if no ps, set to null
     if (!isset($this->post['ps'])) {
         $this->post['ps'] = null;
     }
     // Is this a test order, based on the customer firstname / lastname
     /*if (strtolower($this->customer->fname) == 'test' && strtolower($this->customer->lname) == 'test') {
     			$this->order->addFlags('test');
     		}*/
     // SHIPPING
     // load shipping options for this campaign
     $campShip = new CampaignShippings('CampaignShipping');
     $campShip->load($this->campaign->campaign_id);
     // make sure passed over shipping option is valid
     if (!$campShip->shippingValid($this->post['shipping_id'])) {
         //is there only available ship id for the campaign?  if so, assign shipping id to the value
         if (count($campShip->shipping) == 1) {
             $this->post['shipping_id'] = $campShip->shipping[0]->shipping_id;
         } else {
             // multiple shipping ids available.  abort?
             $this->apiError('invalid shipping option');
         }
     }
     // Set order shipping values
     $this->order->shipping_id = $this->post['shipping_id'];
     // is this a CRM order with a manually entered shipping amount?
     $this->order->amount_shipping = $this->wsType == 'x1' && isset($this->post['amount_shipping']) && $this->post['amount_shipping'] && $this->post['amount_shipping'] != $campShip->selectedShipping($this->order->shipping_id)->amount_initial ? $this->post['amount_shipping'] : $campShip->selectedShipping($this->order->shipping_id)->amount_initial;
     unset($campShip);
     $this->order->status = 'new';
     // some IPs are converted to negative numbers, so we must use sprintf to getit positive so we can store in the db
     $this->order->ip = sprintf('%u', ip2long($this->post['user_ip']));
     // billing same as shipping?  Only applies to Order 2Step and LC
     if (in_array($this->wsType, array('o', 'l'))) {
         if (isset($this->post['billingSameAsShipping']) && $this->post['billingSameAsShipping'] == 'no') {
             $this->buildAddress('billing');
             $this->order->billing_address_id = $this->billingAddress->address_id;
         } else {
             $this->order->billing_address_id = $this->order->address_id;
         }
     } else {
         if ($this->wsType == 'x1') {
             $this->order->billing_address_id = $this->billingAddress->address_id;
         }
     }
     // set payment fields to 0 so we can save the model.  fill these values later.  payment_total is only populated after the payment has been sent
     $this->order->amount_product = '0';
     $this->order->payment_total = '0';
     $this->order->amount_refunded = '0';
     $this->order->pixel_fired = '0';
     // BUILD PAYMENT - only applies to Order and LC
     if (in_array($this->wsType, array('o', 'l'))) {
         $this->buildPayment();
         $this->order->payment_id = $this->payment->payment_id;
         //fb($this->payment);
     }
     // is this a real payment profile? does this request require payment?  only CRM orders have the option of no payment
     if ($this->campaign->profile_id && $this->isPayment) {
         $this->order->payment_id = $this->payment->payment_id;
         // Grab Current gateway.  will be checked again before payment is submitted
         $gid = isset($this->post['gateway_id']) ? $this->post['gateway_id'] : 0;
         if ($this->wsType == 'c') {
             $gid = ProfileGateways::getAttachedGatewayByPrn($this->post['ship_with'], $this->campaign->campaign_id);
         }
         if (!$gid) {
             $gid = ProfileGateways::getCurrentGatewayByIds($this->campaign->profile_id, $this->payment->method_id, $this->post['ps']);
         }
         if (!$gid) {
             $gid = 5;
         }
         // THIS SHOULD NEVER HAPPEN.  set to DEFAULT gateway_id so at least the card can be charged.  Do we want to error out here?
         $this->order->gateway_id = $gid;
         unset($gid);
         // check for test cc
         //if (stripos($this->payment->method->method_ref,'cc_') !== false && $this->payment->cc_number == Config::get()->payments->pacnet['testCC']) {
         if (stripos($this->payment->method->method_ref, 'cc_') !== false && ($this->payment->num4 == strlen(Config::get()->payments->pacnet['testCC']) && $this->payment->num2 == substr(Config::get()->payments->pacnet['testCC'], 0, 6) && $this->payment->num3 == substr(Config::get()->payments->pacnet['testCC'], strlen(Config::get()->payments->pacnet['testCC']) - 4, 4))) {
             $this->order->addFlags('test');
             $this->test = true;
         }
     } else {
         if (!$this->campaign->profile_id) {
             // DRY RUN GATEWAY - set test
             $this->order->addFlags('test');
             $this->test = true;
         }
     }
     // save order
     if (!$this->order->save()) {
         fb($this->order->getErrors());
         $this->apiError('order error - ' . $this->order->geterrors2string());
     }
     // BUILD Order Products
     // includes amount product and shipping override in case this is a manual CRM order with custom amounts
     $this->buildProducts();
     $this->order->amount_product = $this->wsType == 'x1' && isset($this->post['amount_product']) && $this->post['amount_product'] && $this->post['amount_product'] != $this->amount_product ? $this->post['amount_product'] : $this->amount_product;
     // save again
     $this->order->updated = 'NOW():sql';
     //date("Y-m-d H:i:s");
     if (!$this->order->save()) {
         $this->apiError('error saving order');
     }
     // is this NOT a CRM order
     if ($this->wsType != 'x1') {
         // are there upsells?  or do we process payment?  upsells are disabled for Sofort, Giro and Paypal GC orders
         //UPSELLS
         if ($this->upsell_id && $this->isPayment && PaymentMethod::allowUpsell($this->payment->method_id)) {
             // set flag for salveage cron
             $this->order->addFlags('salvage');
             $this->order->save();
             $this->upsellDirect();
         } else {
             // No Upsells, Process Payment
             $this->webPayment();
         }
     }
 }