Advertisement
verygoodplugins

Untitled

May 30th, 2016
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. <?php
  2.  
  3. // CLASS BASE
  4.  
  5.  
  6. // Adds new order to Infusionsoft
  7. public function add_order($contact_id, $order_label, $payment_method, $products, $line_items) {
  8.  
  9.     wp_fusion()->crm->connect();
  10.     $order_date = date('Ymd\TH:i:s', current_time('timestamp'));
  11.     $infusionsoft_invoice_id = wp_fusion()->crm->app->blankOrder( $contact_id, $order_label, $order_date, 0, 0 );
  12.  
  13.  
  14.     // Create each product if it doesn't exist yet
  15.     foreach($products as $product) {
  16.  
  17.         // $product should have $product['name'], $product['id'], $product['description'], $product['sku'], $product['qty']
  18.  
  19.         $infusionsoft_product_id = $this->add_product($product);
  20.         wp_fusion()->crm->app->addOrderItem($infusionsoft_invoice_id, $infusionsoft_product_id, 4, $product['price'], $product['qty'], $product['name'], $product['description']);
  21.  
  22.     }
  23.  
  24.  
  25.     // Add each line item (not products) to the order
  26.     foreach($line_items as $line_item) {
  27.         wp_fusion()->crm->app->addOrderItem($infusionsoft_invoice_id, 0, $line_item['type'], $line_item['price'], 1, $line_item['title'], $line_item['description']);
  28.     }
  29.  
  30.  
  31.    
  32.     $totals = (float) wp_fusion()->crm->app->amtOwed($infusionsoft_invoice_id);
  33.     wp_fusion()->crm->app->manualPmt($infusionsoft_invoice_id, $totals, $order_date, $payment_method, $order_label, false);
  34.    
  35.     //Add Order Notes              
  36.     $jobid  = wp_fusion()->crm->app->dsLoad("Invoice", $infusionsoft_invoice_id, array("JobId"));
  37.     $jobid  = (int) $jobid['JobId'];
  38.     wp_fusion()->crm->app->dsUpdate("Job", $jobid, array('OrderType' => 'Online'));
  39.  
  40.  
  41.     return $infusionsoft_invoice_id;
  42.  
  43. }
  44.  
  45.  
  46. // Creates new PRODUCT in Infusionsoft if product doesn't exist yet
  47. public function add_product( $product ) {
  48.  
  49.     $infusionsoft_product_id = get_post_meta( $product['id'], 'infusionsoft_product_id', true );
  50.  
  51.     if(!empty($infusionsoft_product_id))
  52.         return $infusionsoft_product_id;
  53.  
  54.  
  55.     // DO code here to create product in Infusionsoft
  56.  
  57.  
  58.  
  59.     update_post_meta( $product['id'], 'infusionsoft_product_id', $infusionsoft_product_id );
  60.  
  61.     return $infusionsoft_product_id;
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement