objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $this->cache = $this->objectManager->create('\Magento\Framework\App\CacheInterface'); } private function createPostDataForLogin($email, $password) { return array( "userEmail" => $email, "password" => $password ); } private function createCustomerCache($body){ return json_encode(array( "token" => $body["token"], "userId" => $body["data"]["userId"], "userEmail" => $body["data"]["userEmail"], "firstName" => $body["data"]["firstName"], "lastName" => $body["data"]["lastName"], )); } public function loginAdmin() { $response = $this->post( self::API_LOGIN_URL, array( "userEmail" => self::ADMIN_EMAIL, "password" => self::ADMIN_PASSWORD ) ); if ($response->getBody()){ $body = json_decode($response->getBody()->getContents(), true); } if ($response->getStatusCode() == 200) { $this->cache->save($this->createCustomerCache($body), self::CACHE_TOKEN . self::ADMIN_EMAIL, array(), null); } return $response; } public function getProductFromErp(){ $customer_cache = $this->cache->load(self::CACHE_TOKEN . self::ADMIN_EMAIL); if (!empty($customer_cache)) { $customer_cache = json_decode($customer_cache, true); $this->setToken($customer_cache["token"]); } $query = json_decode('{"urlAPI":"/api/magento/sync-data","filter":{"skip":0,"limit":10,"where":{"update_time_from":"2020-04-05T01:02:10.189Z","update_time_to":""}}}', true); $response = $this->get(self::TRANSFER_GET_DATA, $query); return $response; } }