Example #1
0
 /**
  * Return customer data in xml format.
  *
  * @param Mage_Sales_Model_Quote $quote
  * @return string Xml data
  */
 public function getCustomerXml($quote)
 {
     $_xml = null;
     $checkoutMethod = Mage::getSingleton('checkout/type_onepage')->getCheckoutMethod();
     if ($checkoutMethod) {
         $customer = new Varien_Object();
         switch ($checkoutMethod) {
             case 'register':
             case 'guest':
                 $customer->setMiddlename($quote->getBillingAddress()->getMiddlename());
                 $customer->setPreviousCustomer('0');
                 break;
             case 'customer':
                 //Load customer by Id
                 $customer = $quote->getCustomer();
                 $customer->setPreviousCustomer('1');
                 break;
             default:
                 $customer = $quote->getCustomer();
                 $customer->setPreviousCustomer('0');
                 break;
         }
         $customer->setWorkPhone($quote->getBillingAddress()->getFax());
         $customer->setMobilePhone($quote->getBillingAddress()->getTelephone());
         $xml = new Ebizmarts_Simplexml_Element('<customer />');
         if ($customer->getMiddlename()) {
             $xml->addChild('customerMiddleInitial', substr($customer->getMiddlename(), 0, 1));
         }
         if ($customer->getDob()) {
             $_dob = substr($customer->getDob(), 0, strpos($customer->getDob(), ' '));
             if ($_dob != "0000-00-00") {
                 $xml->addChildCData('customerBirth', $_dob);
                 //YYYY-MM-DD
             }
         }
         if ($customer->getWorkPhone()) {
             $xml->addChildCData('customerWorkPhone', substr(str_pad($customer->getWorkPhone(), 11, '0', STR_PAD_RIGHT), 0, 19));
         }
         if ($customer->getMobilePhone()) {
             $xml->addChildCData('customerMobilePhone', substr(str_pad($customer->getMobilePhone(), 11, '0', STR_PAD_RIGHT), 0, 19));
         }
         $xml->addChild('previousCust', $customer->getPreviousCustomer());
         if ($customer->getId()) {
             $xml->addChild('customerId', $customer->getId());
         }
         //$xml->addChild('timeOnFile', 10);
         $_xml = str_replace("\n", "", trim($xml->asXml()));
     }
     return $_xml;
 }