Пример #1
0
 private function buildProducts()
 {
     // load product options for this campaign
     $campProducts = new CampaignProducts('CampaignProduct');
     $campProducts->load($this->campaign->campaign_id);
     // build order_products
     $orderProducts = new OrderProducts('OrderProduct');
     // does this order already exist? wipe out any existing order products, in case of prior order errors.
     // this will prevent dupe order prods in the DB
     if (!$this->newOrder) {
         $orderProducts->loadByOrderId($this->order->order_id);
         if ($orderProducts->getNumProducts()) {
             $orderProducts->deleteOrderProductsFromDb();
         }
     }
     // in the future, will there be an input array of products?
     // replace POST with DB value?  campaign dependent info?
     $product_ids = array($this->post['product_id']);
     $this->upsell_id = 0;
     foreach ($product_ids as $product_id) {
         // make sure product passed to api is valid for this campaign
         if (!$campProducts->productValid($product_id)) {
             //is there only available product id for the campaign? and one passed over product id?  if so, assign id to the value
             if (count($campProducts->products) == 1 && count($product_ids) == 1) {
                 $product_id = $campProducts->products[0]->product_id;
             } else {
                 // multiple product ids available.  abort
                 $this->apiError('invalid product supplied');
             }
         }
         $orderProducts->add($product_id, $this->order->shipping_id, $this->order->order_id);
         // check for upsells
         if (!$this->upsell_id) {
             $this->upsell_id = $campProducts->hasUpsell($product_id);
         }
     }
     unset($campProducts);
     if (!$orderProducts->save()) {
         $this->apiError('opError ' . $orderProducts->error);
     }
     // grab amounts to return.
     $this->amount_product = $orderProducts->getTotal();
     unset($orderProducts);
     return true;
 }
Пример #2
0
 public function getFirstCampaignProduct()
 {
     // CampaignProducts
     $campProducts = new CampaignProducts('CampaignProduct');
     $campProducts->load($this->campaign_id);
     return $campProducts->products[0]->product_name;
 }
Пример #3
0
 public function getCustomerOkOrder($campID)
 {
     // check campaign product count first
     $campProducts = new CampaignProducts('CampaignProduct');
     $campProducts->load($campID);
     // need to redo this
     /*if(count($campProducts->products) > 1)
     		return 0;	*/
     $sql = "SELECT order_id\n                FROM orders\n                WHERE customer_id = ?i\n\t\t\t\tand campaign_id = ?i\n\t\t\t\tand status = 'ok'\n\t\t\t\tand FIND_IN_SET('test', flags)=0\n\t\t\t\tAND (FIND_IN_SET('pay', `flags`)>0\n\t\t\t\tor FIND_IN_SET('paid', `flags`)>0)";
     $result = self::$_msql->getOne($sql, $this->customer_id, $campID);
     if (empty($result)) {
         return 0;
     }
     return $result;
 }