Ejemplo n.º 1
0
 protected static function _integrateNewOrders($orders)
 {
     $API = QuickBooks_API_Singleton::getInstance();
     $Integrator = QuickBooks_Integrator_Singleton::getInstance();
     // Let's start with new orders
     foreach ($orders as $OrderID) {
         $API->log('Analyzing order #' . $OrderID, QUICKBOOKS_LOG_VERBOSE);
         $Order = $Integrator->getOrder($OrderID);
         if ($Order) {
             // Customer
             $CustomerID = $Order->getCustomerApplicationID();
             if ($ListID = $Order->getCustomerListID()) {
                 // Add it again, just in case!
                 QuickBooks_Callbacks_Integrator_Callbacks::integrateAddCustomer($CustomerID);
             } else {
                 // Try to fetch the customer by name
                 $API->getCustomerByName($Integrator->getCustomerNameForQuery($CustomerID), 'QuickBooks_Callbacks_Integrator_Callbacks::getCustomerByName', $CustomerID);
             }
             // ShipMethod
             /*
             $ShipMethodID = $Order->getShipMethodApplicationID();
             if (
             	(is_numeric($ShipMethodID) and (int) $ShipMethodID) or
             	(!is_numeric($ShipMethodID) and strlen($ShipMethodID)))
             {
             	if ($ListID = $Order->getShipMethodListID())
             	{
             		// xxx Do nothing, already in QuickBooks
             		// Add it again anyway, just in case!
             		$ShipMethod = $Integrator->getShipMethod($ShipMethodID);
             		QuickBooks_Callbacks_Integrator_Callbacks::_integrateShipMethod($ShipMethod, $ShipMethodID);
             	}
             	else if ($this->_integrator_config['lookup_shipmethods'] and $ShipMethodID)
             	{
             		// Try to fetch the shipping method by name
             		$API->getShipMethodByName($Integrator->getShipMethodNameForQuery($ShipMethodID), 'QuickBooks_Callbacks_Integrator_Callbacks::getShipMethodByName', $ShipMethodID);
             	}
             	else if ($ShipMethodID)
             	{
             		$ShipMethod = $Integrator->getShipMethod($ShipMethodID);
             		QuickBooks_Callbacks_Integrator_Callbacks::_integrateShipMethod($ShipMethod, $ShipMethodID);
             	}
             }
             */
             $list = $Integrator->getOrderItems($OrderID);
             foreach ($list as $OrderItem) {
                 //
                 $ProductID = $OrderItem->getItemApplicationID();
                 if (!$ProductID) {
                     continue;
                 }
                 //
                 if ($ListID = $OrderItem->getItemListID()) {
                     // Add it again anyway, just in case
                     $Product = $Integrator->getProduct($ProductID, __FILE__, __LINE__);
                     QuickBooks_Callbacks_Integrator_Callbacks::_integrateProduct($Product, $ProductID);
                 } else {
                     // Queue a request *for each type* of item
                     // Try to fetch the product from QuickBooks
                     $API->getItemByName($Integrator->getProductNameForQuery($ProductID), 'QuickBooks_Callbacks_Integrator_Callbacks::getProductByName', $ProductID);
                 }
             }
             //
             QuickBooks_Callbacks_Integrator_Callbacks::_integrateOrder($Order, $OrderID);
             //
             $Payment = $Integrator->getPayment($OrderID);
             if ($Payment and $Payment->getTotalAmount() > 0) {
                 QuickBooks_Callbacks_Integrator_Callbacks::_integratePayment($Payment, $OrderID);
             }
         }
     }
 }