adapters->adapter->toArray(); if (is_array ($adapters) && array_key_exists ('code', $adapters)) { $adapters = array ($adapters); } $this->_adapters = array(); foreach ( $adapters as $adapterInfo) { $code = $adapterInfo['code']; $this->_adapters[$code] = $adapterInfo; } $adaptersDirections = $xmlconfig->directions->direction->toArray(); if (is_array ($adapters) && array_key_exists ('entitytype', $adapters)) { $adaptersDirections = array ($adaptersDirections); } $this->_adaptersDirections = $adaptersDirections; //var_dump ( $this->_adapters ); } catch ( Exception $e ) { //var_dump ($e); Mage::log($e->getMessage(), NULL, 'integration.log', true); echo $e->getMessage(); } } public function syncItems ( $itemType ) { try { foreach ( $this->_adaptersDirections as $directionInfo ) { //var_dump ($directionInfo['entitytype']); //var_dump ( $itemType ); if ($directionInfo['entitytype'] == $itemType) { $publisherAdapterCode = $directionInfo['adapterpublisher']; $subscribersCodes = explode ( ",", $directionInfo['adaptersubscriber'] ); $adapterInfo = $this->_adapters[$publisherAdapterCode]; $className = $adapterInfo['class']; //var_dump ($adapterInfo); //die ( $className ); $publisherAdapter = new $className(); $publisherAdapter->_adapterParams = $this->_adapterParams; if ( $directionInfo['publisher_disable_logging'] ) { $publisherAdapter->_disableLogging = 1; } //var_dump ($publisherAdapter); $items = $publisherAdapter->getItems ( $itemType ); foreach ( $subscribersCodes as $subscriberCode ) { $subscriberInfo = $this->_adapters[$subscriberCode]; $className = $subscriberInfo['class']; $subscriberAdapter = new $className(); if ( $directionInfo['subscriber_disable_logging'] ) { $subscriberAdapter->_disableLogging = 1; } $subscriberAdapter->_adapterParams = $this->_adapterParams; $subscriberAdapter->_adapterPublisher = $publisherAdapter; // so that the publisher could confirm that the item was transferred, directly to the subscriber adapter // ( confirm call ) echo "Processing ".count($items). " entries\n" ; foreach ( $items as $item ) { // by default, publisher is supposed to convert an item if ( $directionInfo['subscriber_convert'] ) { $convertedItem = $subscriberAdapter->convertDataEntry ( $itemType, $item ); } else { $convertedItem = $publisherAdapter->convertDataEntry ( $itemType, $item ); } $convertedItems = is_array ( $convertedItem ) ? $convertedItem : array ( $convertedItem ); $subscriberAdapter->putItems ( $convertedItems, $itemType ); } $subscriberAdapter->finish(); $publisherAdapter->finish(); } } } } catch ( Exception $e ) { echo "Exception in syncItems: ".$e->getMessage() . ", trace: " . $e->getTraceAsString(); } } public function syncCustomers( $params = array() ) { $this->_adapterParams = $params; return $this->syncItems ('customer'); } public function syncOrders( $params = array() ) { $this->_adapterParams = $params; return $this->syncItems ('Orders'); } public function syncOrdersStatus( $params = array() ) { $this->_adapterParams = $params; return $this->syncItems ('OrdersStatus'); } public function syncProducts( $params = array() ) { $this->_adapterParams = $params; return $this->syncItems ('Products'); } public function syncDiscounts() { return $this->syncItems ('discount'); } public function syncOrdersHistory() { return $this->syncItems ('ordershistory'); } public function syncCreditmemoHistory() { return $this->syncItems ('creditmemohistory'); } public function syncStockData( $params = array() ) { $this->_adapterParams = $params; return $this->syncItems ('StockData'); } }