/** * Post request for creating customer in frontend. * * @param FixtureInterface|null $customer * @return array * @throws \Exception */ public function persist(FixtureInterface $customer = null) { $result = []; /** @var Customer $customer */ $url = $_ENV['app_frontend_url'] . 'customer/account/createpost/?nocookie=true'; $data = $customer->getData(); $data['group_id'] = $this->getCustomerGroup($customer); if ($customer->hasData('address')) { $data['address'] = http_build_query($data['address']); } $curl = new CurlTransport(); $curl->write(CurlInterface::POST, $url, '1.0', [], $data); $response = $curl->read(); $curl->close(); if (!strpos($response, 'class="success-msg"')) { throw new \Exception("Customer entity creating by curl handler was not successful! Response: {$response}"); } $result['id'] = $this->getCustomerId($customer->getEmail()); $data['customer_id'] = $result['id']; if ($this->checkForUpdateData($data)) { parse_str($data['address'], $data['address']); $this->updateCustomer($data); } return $result; }
/** * Post request for creating customer in frontend * * @param FixtureInterface|null $customer * @return array * @throws \Exception */ public function persist(FixtureInterface $customer = null) { $address = []; $result = []; /** @var Customer $customer */ $url = $_ENV['app_frontend_url'] . 'customer/account/createpost/?nocookie=true'; $data = $customer->getData(); $data['group_id'] = $this->getCustomerGroup($customer); if ($customer->hasData('address')) { $address = $customer->getAddress(); unset($data['address']); } $curl = new CurlTransport(); $curl->write(CurlInterface::POST, $url, '1.0', [], $data); $response = $curl->read(); $curl->close(); // After caching My Account page we cannot check by success message if (!strpos($response, 'customer/account/logout')) { throw new \Exception("Customer entity creating by curl handler was not successful! Response: {$response}"); } $result['id'] = $this->getCustomerId($customer->getEmail()); $data['customer_id'] = $result['id']; if (!empty($address)) { $data['address'] = $address; } $this->updateCustomer($data); return $result; }
/** * Send request to the remote server. * * @param string $url * @param mixed $params * @param string $method * @param mixed $headers * @return void */ public function write($url, $params = [], $method = CurlInterface::POST, $headers = []) { if ($this->formKey) { $params['form_key'] = $this->formKey; } $headers = ['Set-Cookie:' . $this->cookies]; $this->transport->write($url, http_build_query($params), $method, $headers); }
/** * Send request to the remote server * * @param string $method * @param string $url * @param string $httpVer * @param array $headers * @param array $params * @return void * @throws \Exception */ public function write($method, $url, $httpVer = '1.1', $headers = [], $params = []) { if ($this->formKey) { $params['form_key'] = $this->formKey; } else { throw new \Exception(sprintf('Form key is absent! Url: "%s" Response: "%s"', $url, $this->response)); } $this->transport->write($method, $url, $httpVer, $headers, http_build_query($params)); }
/** * Send request to the remote server * * @param string $method * @param string $url * @param string $http_ver * @param array $headers * @param array $params * @return void * * @throws \Exception */ public function write($method, $url, $http_ver = '1.1', $headers = [], $params = []) { if ($this->_formKey) { $params['form_key'] = $this->_formKey; isset($params['data']) ? $params['data'] = preg_replace('!formKey!', $this->_formKey, $params['data']) : null; } else { throw new \Exception('Form key is absent! Response: \\n' . "Url:" . $url . "Response:" . $this->_response); } $this->_transport->write($method, $url, $http_ver, $headers, http_build_query($params)); }
/** * Post request for creating customer * * @param FixtureInterface $fixture [optional] * @return mixed|string */ public function persist(FixtureInterface $fixture = null) { $data = $fixture->getData('fields'); $fields = []; foreach ($data as $key => $field) { $fields[$key] = $field['value']; } $url = $_ENV['app_frontend_url'] . 'customer/account/createpost/?nocookie=true'; $curl = new CurlTransport(); $curl->write(CurlInterface::POST, $url, '1.0', [], $fields); $response = $curl->read(); $curl->close(); return $response; }
/** * Send request to the remote server. * * @param string $url * @param array $params * @param string $method * @param array $headers * @return void */ public function write($url, $params = [], $method = CurlInterface::POST, $headers = []) { $headers = array_merge(['Authorization: Bearer ' . $this->configuration->get(self::CONFIG_TOKEN_PATH)], $this->headers, $headers); $this->transport->write($url, json_encode($params), $method, $headers); }
/** * Send request to the remote server * * @param string $method * @param string $url * @param string $httpVer * @param array $headers * @param array $params * @return void * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function write($method, $url, $httpVer = '1.1', $headers = [], $params = []) { $this->transport->write($method, $url, $httpVer, ['Set-Cookie:' . $this->cookies], http_build_query($params)); }
/** * Save new customer and get form key * * @param \Magento\Customer\Test\Fixture\Customer $fixture * @return CurlTransport */ protected function saveCustomer(\Magento\Customer\Test\Fixture\Customer $fixture) { $data = $fixture->getData('fields'); $fields = []; foreach ($data as $key => $field) { $fields[$key] = $field['value']; } $url = $_ENV['app_frontend_url'] . $this->saveCustomer; $curl = new CurlTransport(); $curl->write(CurlInterface::POST, $url, '1.0', [], $fields); $curl->read(); $urlForm = $_ENV['app_frontend_url'] . $this->addressNew; $curl->write(CurlInterface::GET, $urlForm, '1.0', []); $response = $curl->read(); $this->formKey = $this->getFromKey($response); return $curl; }