/** * @param Bronto_Api_Contact $customerObject * @param array $customerCache * @param array $result * * @return array */ protected function _flushCustomers($customerObject, $customerCache, $result) { $fieldModel = Mage::getModel('bronto_common/system_config_source_field'); $flushResult = $customerObject->flush(); $flushCount = count($flushResult); Mage::helper('bronto_customer')->writeDebug(" Flush resulted in {$flushCount} customers processed"); Mage::helper('bronto_customer')->writeVerboseDebug('===== FLUSH =====', 'bronto_customer_api.log'); Mage::helper('bronto_customer')->writeVerboseDebug(var_export($customerObject->getApi()->getLastRequest(), true), 'bronto_customer_api.log'); Mage::helper('bronto_customer')->writeVerboseDebug(var_export($customerObject->getApi()->getLastResponse(), true), 'bronto_customer_api.log'); foreach ($flushResult as $i => $flushResultRow) { if ($flushResultRow->hasError()) { $hasError = true; $errorCode = $flushResultRow->getErrorCode(); $errorMessage = $flushResultRow->getErrorMessage(); } else { $hasError = false; $errorCode = false; $errorMessage = false; } if (isset($customerCache[$i])) { // Get Customer Object $customer = Mage::getModel('customer/customer')->load($customerCache[$i]['customerId']); $store = Mage::getModel('core/store')->load($customerCache[$i]['storeId']); $website = Mage::getModel('core/website')->load($store->getWebsiteId()); $storeMessage = "For `{$website->getName()}`:`{$store->getName()}`: "; $customerRow = Mage::getModel('bronto_customer/queue')->getCustomerRow($customerCache[$i]['customerId'], $customerCache[$i]['storeId']); } else { if ($hasError) { Mage::helper('bronto_customer')->writeError("[{$errorCode}] {$errorMessage}"); $result['error']++; } continue; } if ($hasError) { // If Error Code In specified Array, suppress contact if (in_array($errorCode, array(302, 303, 314, 315, 317))) { $customerRow->setBrontoSuppressed($errorMessage); } Mage::helper('bronto_customer')->writeError("[{$errorCode}] {$storeMessage}{$errorMessage} ({$customer->getEmail()})"); // Mark Customer as not imported $customerRow->setBrontoImported(null); $customerRow->save(); $result['error']++; } else { Mage::helper('bronto_customer')->writeDebug(" {$customerCache[$i]['customerId']} = SUCCESS"); // Mark Customer as imported $customerRow->setBrontoImported(Mage::getSingleton('core/date')->gmtDate()); $customerRow->save(); $result['success']++; } } return $result; }
/** * @param Bronto_Api_Contact $customerObject * @param array $customerCache * @param array $result * * @return array */ protected function _flushCustomers($customerObject, $customerCache, $result) { $fieldModel = Mage::getModel('bronto_common/system_config_source_field'); $flushResult = $customerObject->flush(); $flushCount = count($flushResult); Mage::helper('bronto_customer')->writeDebug(" Flush resulted in {$flushCount} customers processed"); Mage::helper('bronto_customer')->writeVerboseDebug('===== FLUSH =====', 'bronto_customer_api.log'); Mage::helper('bronto_customer')->writeVerboseDebug(var_export($customerObject->getApi()->getLastRequest(), true), 'bronto_customer_api.log'); Mage::helper('bronto_customer')->writeVerboseDebug(var_export($customerObject->getApi()->getLastResponse(), true), 'bronto_customer_api.log'); foreach ($flushResult as $i => $flushResultRow) { if ($flushResultRow->hasError()) { $hasError = true; $errorCode = $flushResultRow->getErrorCode(); $errorMessage = $flushResultRow->getErrorMessage(); } else { $hasError = false; $errorCode = false; $errorMessage = false; } if (isset($customerCache[$i])) { // Get Customer Object $customer = Mage::getModel('customer/customer')->load($customerCache[$i]['customerId']); $store = Mage::getModel('core/store')->load($customerCache[$i]['storeId']); $website = Mage::getModel('core/website')->load($store->getWebsiteId()); $storeMessage = "For `{$website->getName()}`:`{$store->getName()}`: "; $customerRow = Mage::getModel('bronto_customer/queue')->getCustomerRow($customerCache[$i]['customerId'], $customerCache[$i]['storeId']); } else { if ($hasError) { Mage::helper('bronto_customer')->writeError("[{$errorCode}] {$errorMessage}"); $result['error']++; } continue; } if ($hasError) { // Catch Error and Replace Field ID with Field Name if (preg_match_all("/([a-zA-Z0-9\\-]){36}/", $errorMessage, $matches)) { // Grab field id if exists foreach ($matches[0] as $match) { $fieldObject = $fieldModel->getFieldObjectById($match); if ($fieldObject) { $errorMessage = str_replace($match, $fieldObject->name, $errorMessage); } elseif (array_key_exists($match, $this->_fieldMap)) { $mageLabel = $this->_fieldMap[$match]; $errorMessage = "Bronto field mapped for {$mageLabel} no longer exists in your bronto account"; } } } // If Error Code In specified Array, suppress contact if (in_array($errorCode, array(302, 303, 314, 315, 317))) { $customerRow->setBrontoSuppressed($errorMessage); } Mage::helper('bronto_customer')->writeError("[{$errorCode}] {$storeMessage}{$errorMessage} ({$customer->getEmail()})"); // Mark Customer as not imported $customerRow->setBrontoImported(null); $customerRow->save(); $result['error']++; } else { Mage::helper('bronto_customer')->writeDebug(" {$customerCache[$i]['customerId']} = SUCCESS"); // Mark Customer as imported $customerRow->setBrontoImported(Mage::getSingleton('core/date')->gmtDate()); $customerRow->save(); $result['success']++; } } return $result; }