/**
  * @param Bronto_Api_Contact_Row $contact
  * @param bool                   $persistOnly
  *
  * @return Bronto_Api_Contact_Row
  */
 public function saveContact(Bronto_Api_Contact_Row $contact, $persistOnly = false)
 {
     if ($persistOnly) {
         $contact->persist();
     } else {
         try {
             if ($contact->id) {
                 $this->writeDebug("Updating existing Contact: ({$contact->email})...");
             } else {
                 $this->writeDebug("Saving new Contact: ({$contact->email})...");
             }
             $contact->save(false);
         } catch (Exception $e) {
             $this->writeError($e);
         }
     }
     $this->writeVerboseDebug('===== CONTACT SAVE =====', 'bronto_common_api.log');
     $this->writeVerboseDebug(var_export($contact->getApi()->getLastRequest(), true), 'bronto_common_api.log');
     $this->writeVerboseDebug(var_export($contact->getApi()->getLastResponse(), true), 'bronto_common_api.log');
     return $contact;
 }
 /**
  * @covers Bronto_Api_Contact_Row::save
  * @depends testDeleteContactAfterRead
  */
 public function testSaveContactAfterDeleteCaughtException(Bronto_Api_Contact_Row $contact)
 {
     $contact->status = 'transactional';
     try {
         $contact->save();
     } catch (Bronto_Api_Row_Exception $e) {
         //
     }
     $this->assertEquals(1, count($contact->getData()));
     $this->assertTrue($contact->isReadOnly());
     $this->assertFalse($contact->hasError(), 'Contact has error: ' . $contact->getErrorMessage());
     $this->assertFalse($contact->isNew());
 }
Example #3
0
 /**
  * Cycle through attributes and validate against Bronto Field type
  *
  * @param Bronto_Api_Contact_Row $brontoContact
  * @param                        $source
  * @param                        $attributes
  * @param Mage_Core_Model_Store  $store
  * @param string                 $type 'customer' or 'address'
  *
  * @return Bronto_Api_Contact_Row
  */
 protected function _processAttributes(Bronto_Api_Contact_Row $brontoContact, $source, $attributes, Mage_Core_Model_Store $store, $type = 'customer')
 {
     $helper = Mage::helper('bronto_customer');
     // For each Customer attribute
     foreach ($attributes as $attribute) {
         if ('' == $attribute->getFrontendLabel()) {
             continue;
         }
         $_attributeCode = $attribute->getAttributeCode();
         // Get Attribute Field
         switch ($type) {
             case 'billing_address':
             case 'address':
                 $_fieldName = $helper->getPrefixedAttributeField($_attributeCode, $type, 'store', $store->getId());
                 // Backward compatibility for country name and codes
                 if (array_key_exists($_attributeCode, $this->_expandedfields)) {
                     list($method, $label, $field) = $this->_expandedfields[$_attributeCode];
                     $_attributeValue = strtolower($source->{$method}());
                     $_brontoField = $helper->getPrefixedAttributeField($field, $type, 'store', $store->getId());
                     if (!$this->_skippableProcessValue($_brontoField, $_attributeValue)) {
                         $brontoContact->setField($_brontoField, $_attributeValue);
                     }
                 }
                 break;
             default:
                 $_fieldName = Mage::helper('bronto_customer')->getCustomerAttributeField($_attributeCode, 'store', $store->getId());
                 break;
         }
         // Get Customer Attribute Value
         $_attributeValue = $this->_getReadableValue($attribute, $source->getData($_attributeCode));
         // Skip un-mapped or empty attributes
         if ($this->_skippableProcessValue($_fieldName, $_attributeValue)) {
             continue;
         }
         $brontoContact->setField($_fieldName, $_attributeValue);
     }
     return $brontoContact;
 }
 /**
  * Cycle through attributes and validate against Bronto Field type
  *
  * @param Bronto_Api_Contact_Row $brontoContact
  * @param                        $source
  * @param                        $attributes
  * @param Mage_Core_Model_Store  $store
  * @param string                 $type 'customer' or 'address'
  *
  * @return Bronto_Api_Contact_Row
  */
 protected function _processAttributes(Bronto_Api_Contact_Row $brontoContact, $source, $attributes, Mage_Core_Model_Store $store, $type = 'customer')
 {
     // For each Customer attribute
     foreach ($attributes as $attribute) {
         if ('' == $attribute->getFrontendLabel()) {
             continue;
         }
         $_attributeCode = $attribute->getAttributeCode();
         // Get Attribute Field
         switch ($type) {
             case 'address':
                 $_fieldName = Mage::helper('bronto_customer')->getAddressAttributeField($_attributeCode, 'store', $store->getId());
                 break;
             default:
                 $_fieldName = Mage::helper('bronto_customer')->getCustomerAttributeField($_attributeCode, 'store', $store->getId());
                 break;
         }
         // Get Customer Attribute Value
         $_attributeValue = $this->_getReadableValue($attribute, $source->getData($_attributeCode));
         // Skip un-mapped or empty attributes
         if (empty($_fieldName) || '_none_' == $_fieldName || !$_attributeValue || '' == $_attributeValue) {
             continue;
         }
         // Store Bronto Key => Magento field label for errors
         if (!array_key_exists($_fieldName, $this->_fieldMap)) {
             $this->_fieldMap[$_fieldName] = $attribute->getFrontendLabel();
         }
         $brontoContact->setField($_fieldName, $_attributeValue);
     }
     return $brontoContact;
 }
Example #5
0
 /**
  * @param Bronto_Api_Contact_Row $contact
  * @param bool                   $persistOnly
  *
  * @return Bronto_Api_Contact_Row
  */
 public function saveContact(Bronto_Api_Contact_Row $contact, $persistOnly = false)
 {
     if ($persistOnly) {
         $contact->persist();
     } else {
         try {
             if ($contact->id) {
                 $this->writeDebug("Updating existing Contact: ({$contact->email})...");
             } else {
                 $this->writeDebug("Saving new Contact: ({$contact->email})...");
             }
             $contact->save(false);
         } catch (Exception $e) {
             $this->writeError($e);
         }
         $this->_flushApiLogs($contact->getApi());
     }
     return $contact;
 }