_soap = new SoapClient($this->_wsdl); } /** * Returns the customers account information * - API Connect get_settings * * @param int $storeId * @return array */ public function getAccountInfo($storeId = null) { if ($this->_soap !== null) { try{ $response = $this->_soap->getSnapshot( $this->_getApiDataAsString($storeId), self::_getVersion() ); if ($response!=="LoginFailed") { return unserialize(utf8_decode($response)); } return array(); }catch(SoapFault $e){ $this->log($e->getMessage(), Zend_Log::ERR); return array(); } } return array(); } /** * Returns the customer settings * - API Connect get_settings * * @param int $storeId * @return array */ public function getSettings($storeId = null) { if ($this->_soap !== null) { try{ $response = $this->_soap->getSettings( $this->_getApiDataAsString($storeId), self::_getVersion() ); if ($response!=="LoginFailed") { return unserialize(utf8_decode($response)); } return array(); }catch(SoapFault $e){ $this->log($e->getMessage(), Zend_Log::ERR); return array(); } } return array(); } /** * Adds a product to eKomi's * Database * * @param Mage_Sales_Model_Order_Item $product * @param int $storeId * @return boolean if failed or not */ public function addProduct(Mage_Sales_Model_Order_Item $product, $storeId = null) { if ($this->_soap !== null) { try{ $productOther = array(); if ((int)Mage::getStoreConfig('web/secure/use_in_frontend')==1) { $productOther['image_url'] = Mage::getUrl( 'ekomimeetsmage/image/get', array('_secure' => true, '_forced_secure' => true, 'sku' => $product->getSku()) ); } $response = $this->_getResult( $this->_soap->putProduct( $this->_getApiDataAsString($storeId), self::_getVersion(), utf8_encode($product->getSku()), utf8_encode($product->getName()), utf8_encode(serialize($productOther)) ) ); return (is_array($response) && $response['done'] == 1) ? true : false; }catch(SoapFault $e){ $this->log($e->getMessage(), Zend_Log::ERR); } } } /** * Transmitts an order to eKomi's database * * @param Mage_Sales_Model_Order $order * @return boolean|string if false the order could be transmitted */ public function addOrder(Mage_Sales_Model_Order $order) { if ($this->_soap !== null) { try{ $productSkus = array(); foreach ($order->getAllItems() as $item) { $productSkus[] = $item->getSku(); } $response = $this->_getResult( $this->_soap->putOrder( $this->_getApiDataAsString($order->getStoreId()), self::_getVersion(), $order->getIncrementId(), implode(",", $productSkus) // utf8_encode(serialize($productSkus)) ) ); if (is_array($response) && $response['done'] == 1) { return $response['link']; } return false; }catch(SoapFault $e){ Mage::log($e->getMessage(), Zend_Log::ERR, "ekomimeetsmage.log", true); } } } /** * Returns the version number * */ private function _getVersion() { return MeetsEcommerce_Ekomimeetsmage_Model_Version::getVersionName(); } /** * Returns API data as string * - user|pass * * @param int $storeId * @return string|false */ private function _getApiDataAsString($storeId = null) { if ($storeId === null) { $storeId = (Mage::app()->getStore()->getId() == 0) ? null : Mage::app()->getStore()->getId(); } if (Mage::helper('ekomimeetsmage')->isSingleStore()) { $storeId = null; } $data = Mage::helper('ekomimeetsmage/api_data')->fetch($storeId); if (count($data) > 0) { if ($data['api_status'] == 1) { return $data['api_id']."|".$data['api_pass']; } } return false; } /** * Unserilizes the result all time * * @return array */ private function _getResult($result) { return unserialize(utf8_decode($result)); } /** * eKomi Logger * * @param mixed $message */ private function log($message, $type=Zend_Log::INFO) { Mage::helper('ekomimeetsmage')->log($message, $type); } }