Пример #1
0
 /**
  * Curl creation of Admin User Role
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData();
     $data['all'] = $data['resource_access'] == 'All' ? 1 : 0;
     if (isset($data['roles_resources'])) {
         foreach ((array) $data['roles_resources'] as $resource) {
             $data['resource'][] = $resource;
         }
     }
     unset($data['roles_resources']);
     $data['gws_is_all'] = isset($data['gws_is_all']) ? $data['gws_is_all'] : '1';
     if ($fixture->hasData('in_role_user')) {
         $adminUsers = $fixture->getDataFieldConfig('in_role_user')['source']->getAdminUsers();
         $userIds = [];
         foreach ($adminUsers as $adminUser) {
             $userIds[] = $adminUser->getUserId() . "=true";
         }
         $data['in_role_user'] = implode('&', $userIds);
     }
     $url = $_ENV['app_backend_url'] . 'admin/user_role/saverole/active_tab/info/';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Role creating by curl handler was not successful! Response: {$response}");
     }
     $url = 'admin/user_role/roleGrid/sort/role_id/dir/desc/';
     $regExpPattern = '/class=\\"\\scol\\-id col\\-role_id\\W*>\\W+(\\d+)\\W+<\\/td>\\W+<td[\\w\\s\\"=\\-]*?>\\W+?' . $data['rolename'] . '/siu';
     $extractor = new Extractor($url, $regExpPattern);
     return ['role_id' => $extractor->getData()[1]];
 }
Пример #2
0
 /**
  * Post request for creating customer in backend
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $params = $this->_prepareData($fixture);
     $url = $_ENV['app_backend_url'] . 'customer/index/save/active_tab/account';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $params);
     $response = $curl->read();
     $curl->close();
     return $response;
 }
Пример #3
0
 /**
  * Get created user id.
  *
  * @return string
  */
 protected function getId()
 {
     $url = $_ENV['app_backend_url'] . 'permissions_user/roleGrid/sort/user_id/dir/desc/';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0');
     $response = $curl->read();
     $curl->close();
     preg_match('@edit/user_id/(\\d+)/@siu', $response, $matches);
     return $matches[1];
 }
 /**
  * Execute handler
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed
  */
 public function persist(FixtureInterface $fixture = null)
 {
     /** @var \Magento\Customer\Test\Fixture\CustomerGroup $fixture*/
     $params = $this->prepareData($fixture);
     $url = $_ENV['app_backend_url'] . $this->saveUrl;
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $params);
     $response = $curl->read();
     $curl->close();
     return $this->findId($response, $fixture->getGroupName());
 }
Пример #5
0
 /**
  * Apply config settings via curl
  *
  * @param array $data
  * @param string $section
  * @throws \Exception
  */
 protected function applyConfigSettings(array $data, $section)
 {
     $url = $this->getUrl($section);
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (strpos($response, 'data-ui-id="messages-message-success"') === false) {
         throw new \Exception("Settings are not applied! Response: {$response}");
     }
 }
Пример #6
0
 /**
  * Post request for creating tax rule
  *
  * @param FixtureInterface $fixture
  * @return mixed|null
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $this->prepareData($fixture);
     $url = $_ENV['app_backend_url'] . 'tax/rule/save/?back=1';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     preg_match("~Location: [^\\s]*\\/rule\\/(\\d+)~", $response, $matches);
     $id = isset($matches[1]) ? $matches[1] : null;
     return ['id' => $id];
 }
Пример #7
0
 /**
  * POST request for creating Catalog Price Rule
  *
  * @param FixtureInterface $fixture
  * @return mixed|void
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $this->prepareData($fixture);
     $url = $_ENV['app_backend_url'] . 'catalog_rule/promo_catalog/save/';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Catalog Price Rule entity creating by curl handler was not successful! Response: {$response}");
     }
     return ['id' => $this->getCategoryPriceRuleId($data)];
 }
Пример #8
0
 /**
  * Set tax class id
  *
  * @param string $taxClassName
  * @return void
  * @throws \Exception
  */
 protected function setTaxClassId($taxClassName)
 {
     $url = $_ENV['app_backend_url'] . 'tax/rule/new/';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], []);
     $response = $curl->read();
     $curl->close();
     preg_match('~<option value="(\\d+)".*>' . $taxClassName . '</option>~', $response, $matches);
     if (!isset($matches[1]) || empty($matches[1])) {
         throw new \Exception('Product tax class id ' . $taxClassName . ' undefined!');
     }
     $this->taxClassId = (int) $matches[1];
 }
Пример #9
0
 /**
  * Post request for creating sitemap
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . 'admin/sitemap/save/generate/';
     $data = array_merge($this->defaultAttributeValues, $fixture->getData());
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Sitemap entity creating by curl handler was not successful! Response: {$response}");
     }
     return ['sitemap_id' => $this->getSitemapId($data)];
 }
Пример #10
0
 /**
  * Create product via curl.
  *
  * @param array $data
  * @param array $config
  * @return array
  * @throws \Exception
  */
 protected function createProduct(array $data, array $config)
 {
     $url = $this->getUrl($config);
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         $this->_eventManager->dispatchEvent(['curl_failed'], [$response]);
         throw new \Exception('Product creation by curl handler was not successful!');
     }
     return $this->parseResponse($response);
 }
Пример #11
0
 /**
  * Set tax class id.
  *
  * @param string $taxClassName
  * @return void
  * @throws \Exception
  */
 protected function setTaxClassId($taxClassName)
 {
     $url = $_ENV['app_backend_url'] . 'tax/rule/new/';
     $config = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->create('Magento\\Mtf\\Config\\DataInterface');
     $curl = new BackendDecorator(new CurlTransport(), $config);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, [], CurlInterface::GET);
     $response = $curl->read();
     $curl->close();
     preg_match('~<option value="(\\d+)".*>' . $taxClassName . '</option>~', $response, $matches);
     if (!isset($matches[1]) || empty($matches[1])) {
         throw new \Exception('Product tax class id ' . $taxClassName . ' undefined!');
     }
     $this->taxClassId = (int) $matches[1];
 }
Пример #12
0
 /**
  * Post request for creating tax rule.
  *
  * @param FixtureInterface $fixture [optional]
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $this->prepareData($fixture);
     $url = $_ENV['app_backend_url'] . 'tax_rule/save/?back=1';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.1', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'success-msg')) {
         throw new \Exception("Tax rule creation by curl handler was not successful!\nResponse:\n{$response}");
     }
     $id = $this->getTaxRuleId($response);
     return ['id' => $id];
 }
Пример #13
0
 /**
  * POST request for creating Customer Group.
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data['code'] = $fixture->getCustomerGroupCode();
     $data['tax_class'] = $fixture->getDataFieldConfig('tax_class_id')['source']->getTaxClass()->getId();
     $url = $_ENV['app_backend_url'] . $this->saveUrl;
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Customer Group entity creating by curl handler was not successful! Response: {$response}");
     }
     return ['customer_group_id' => $this->getCustomerGroupId($data)];
 }
Пример #14
0
 /**
  * Create Attribute Set
  *
  * @param CatalogAttributeSet $fixture
  * @return string
  */
 protected function createAttributeSet(CatalogAttributeSet $fixture)
 {
     $data = $fixture->getData();
     if (!isset($data['gotoEdit'])) {
         $data['gotoEdit'] = 1;
     }
     $data['skeleton_set'] = $fixture->getDataFieldConfig('skeleton_set')['source']->getAttributeSet()->getAttributeSetId();
     $url = $_ENV['app_backend_url'] . 'catalog/product_set/save/';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     return $response;
 }
Пример #15
0
 /**
  * Post request for creating a cms page.
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . $this->url;
     $data = $this->replaceMappingData($fixture->getData());
     $data = $this->prepareData($data);
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.1', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'class="success-msg"')) {
         throw new \Exception("Cms page entity creating by curl handler was not successful! Response: {$response}");
     }
     $id = $this->getCmsPageId($response);
     return ['page_id' => $id];
 }
Пример #16
0
 /**
  * Post request for creating custom system variable.
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data['variable'] = $fixture->getData();
     $url = $_ENV['app_backend_url'] . 'admin/system_variable/save/back/edit/';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("System Variable creation by curl handler was not successful! Response: {$response}");
     }
     preg_match("~Location: [^\\s]*system_variable\\/edit\\/variable_id\\/(\\d+)~", $response, $matches);
     $id = isset($matches[1]) ? $matches[1] : null;
     return ['variable_id' => $id];
 }
Пример #17
0
 /**
  * Post request for creating a cms page.
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . $this->url;
     $data = $this->prepareData($this->replaceMappingData($fixture->getData()));
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Cms page entity creating by curl handler was not successful! Response: {$response}");
     }
     preg_match("~page_id\\/(\\d*?)\\/~", $response, $matches);
     $id = isset($matches[1]) ? $matches[1] : null;
     return ['page_id' => $id];
 }
Пример #18
0
 /**
  * Get website id by website name
  *
  * @param string $websiteName
  * @return int
  * @throws \Exception
  */
 protected function getWebSiteIdByWebsiteName($websiteName)
 {
     //Set pager limit to 2000 in order to find created website by name
     $url = $_ENV['app_backend_url'] . 'admin/system_store/index/sort/group_title/dir/asc/limit/2000';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0');
     $response = $curl->read();
     $expectedUrl = '/admin/system_store/editWebsite/website_id/';
     $expectedUrl = preg_quote($expectedUrl);
     $expectedUrl = str_replace('/', '\\/', $expectedUrl);
     preg_match('/' . $expectedUrl . '([0-9]*)\\/(.)*>' . $websiteName . '<\\/a>/', $response, $matches);
     if (empty($matches)) {
         throw new \Exception('Cannot find website id.');
     }
     return intval($matches[1]);
 }
Пример #19
0
 /**
  * Get Store id by name after creating Store
  *
  * @param string $name
  * @return int|null
  * @throws \Exception
  */
 protected function getStoreId($name)
 {
     //Set pager limit to 2000 in order to find created store view by name
     $url = $_ENV['app_backend_url'] . 'admin/system_store/index/sort/store_title/dir/asc/limit/2000';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, [], CurlInterface::GET);
     $response = $curl->read();
     $expectedUrl = '/admin/system_store/editStore/store_id/';
     $expectedUrl = preg_quote($expectedUrl);
     $expectedUrl = str_replace('/', '\\/', $expectedUrl);
     preg_match('/' . $expectedUrl . '([0-9]*)\\/(.)*>' . $name . '<\\/a>/', $response, $matches);
     if (empty($matches)) {
         throw new \Exception('Cannot find store id');
     }
     return empty($matches[1]) ? null : $matches[1];
 }
Пример #20
0
 /**
  * Curl creation of Admin User Role.
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $this->prepareData($fixture);
     $url = $_ENV['app_backend_url'] . 'admin/user_role/saverole/active_tab/info/';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Role creating by curl handler was not successful! Response: {$response}");
     }
     $url = 'admin/user_role/roleGrid/sort/role_id/dir/desc/';
     $regExpPattern = '/col\\-role_id[^\\>]+\\>\\s*(\\d+)\\s*<.td>\\s*<[^<>]*?>\\s*' . $data['rolename'] . '/siu';
     $extractor = new Extractor($url, $regExpPattern);
     return ['role_id' => $extractor->getData()[1]];
 }
Пример #21
0
 /**
  * Post request for creating tax rule.
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     /** @var TaxRule $fixture */
     $data = $this->prepareData($fixture);
     $url = $_ENV['app_backend_url'] . 'tax/rule/save/?back=1';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         $this->_eventManager->dispatchEvent(['curl_failed'], [$response]);
         throw new \Exception("Tax rate creation by curl handler was not successful!");
     }
     preg_match("~Location: [^\\s]*\\/rule\\/(\\d+)~", $response, $matches);
     $id = isset($matches[1]) ? $matches[1] : null;
     return ['id' => $id];
 }
Пример #22
0
 /**
  * Create product via curl
  *
  * @param array $data
  * @param array $config
  * @return array
  * @throws \Exception
  */
 protected function createProduct(array $data, array $config)
 {
     $url = $this->getUrl($config);
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Product creation by curl handler was not successful! Response: {$response}");
     }
     preg_match("~Location: [^\\s]*\\/id\\/(\\d+)~", $response, $matches);
     $checkoutData = isset($data['product']['checkout_data']) ? $data['product']['checkout_data'] : null;
     foreach ($data['downloadable']['link'] as $key => $link) {
         preg_match('`"link_id":"(\\d*?)","title":"' . $link['title'] . '"`', $response, $linkId);
         if (isset($checkoutData['options']['links'][$key]['label'])) {
             $checkoutData['options']['links'][$key]['id'] = $linkId[1];
         }
     }
     return ['id' => $matches[1], 'checkout_data' => $checkoutData];
 }
Пример #23
0
 /**
  * Retrieves data from cURL response
  *
  * @throws \Exception
  * @return array
  */
 public function getData()
 {
     /** @var \Magento\Mtf\Config\DataInterface $config */
     $config = \Magento\Mtf\ObjectManagerFactory::getObjectManager()->get('Magento\\Mtf\\Config\\DataInterface');
     $url = $_ENV['app_backend_url'] . $this->url;
     $curl = new BackendDecorator(new CurlTransport(), $config);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, [], CurlInterface::GET);
     $response = $curl->read();
     $curl->close();
     if ($this->isAll) {
         preg_match_all($this->regExpPattern, $response, $matches);
     } else {
         preg_match($this->regExpPattern, $response, $matches);
     }
     $countMatches = $this->isAll ? count($matches[1]) : count($matches);
     if ($countMatches == 0) {
         throw new \Exception('Matches array can\'t be empty.');
     }
     return $matches;
 }
Пример #24
0
 /**
  * Post request for creating user in backend
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $url = $_ENV['app_backend_url'] . 'admin/user/save';
     $data = $this->_prepareData($fixture->getData('fields'));
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("User creation by curl handler was not successful! Response: {$response}");
     }
     //Sort data in grid to define user id if more than 20 items in grid
     $url = $_ENV['app_backend_url'] . 'admin/user/roleGrid/sort/user_id/dir/desc';
     $curl = new BackendDecorator(new CurlTransport(), new Config());
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $response = $curl->read();
     $curl->close();
     $data['id'] = $this->_getUserId($data);
     return $data;
 }
Пример #25
0
 /**
  * Curl creation of Admin User
  *
  * @param FixtureInterface $fixture
  * @return array|mixed
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     /** @var \Magento\User\Test\Fixture\User $fixture */
     $data = $fixture->getData();
     if ($fixture->hasData('role_id')) {
         $data['roles[]'] = $fixture->getDataFieldConfig('role_id')['source']->getRole()->getRoleId();
     }
     $data['is_active'] = isset($data['is_active']) && $data['is_active'] === 'Inactive' ? 0 : 1;
     $url = $_ENV['app_backend_url'] . 'admin/user/save/active_tab/main_section/';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Admin user entity creating by curl handler was not successful! Response: {$response}");
     }
     $url = 'admin/user/roleGrid/sort/user_id/dir/desc';
     $regExpPattern = '/col-user_id[^\\>]+\\>\\s*(\\d+)\\s*<.td>\\s*<[^<>]*?>\\s*' . $data['username'] . '/siu';
     $extractor = new Extractor($url, $regExpPattern);
     return ['user_id' => $extractor->getData()[1]];
 }
Пример #26
0
 /**
  * Create product via curl
  *
  * @param array $data
  * @param array $config
  * @return array
  * @throws \Exception
  */
 protected function createProduct(array $data, array $config)
 {
     $url = $this->getUrl($config);
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.1', [], $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'class="success-msg"')) {
         throw new \Exception("Product creation by curl handler was not successful! Response: {$response}");
     }
     $id = $this->parseResponse($response);
     $checkoutData = isset($data['product']['checkout_data']) ? $data['product']['checkout_data'] : null;
     foreach ($data['downloadable']['link'] as $key => $link) {
         preg_match('`"link_id":"(\\d*?)","title":"' . $link['title'] . '"`', $response, $linkId);
         if (isset($checkoutData['options']['links'][$key]['label'])) {
             $checkoutData['options']['links'][$key]['id'] = $linkId[1];
         }
     }
     return ['id' => $id['id'], 'checkout_data' => $checkoutData];
 }
Пример #27
0
 /**
  * Create order via curl.
  *
  * @param array $data
  * @return int|null
  * @throws \Exception
  */
 protected function createOrder(array $data)
 {
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     foreach ($this->steps as $key => $step) {
         if (!isset($data[$key])) {
             continue;
         }
         $url = $_ENV['app_backend_url'] . 'sales_order_create/loadBlock/block/' . $step . '?isAjax=true';
         $curl->write(CurlInterface::POST, $url, '1.1', [], $data[$key]);
         $curl->read();
     }
     $url = $_ENV['app_backend_url'] . 'sales_order_create/save';
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.1', [], $data['order_data']);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'class="success-msg"')) {
         throw new \Exception("Order creation by curl handler was not successful! Response: {$response}");
     }
     preg_match("@Order\\s#\\s(\\d+)@", $response, $matches);
     return isset($matches[1]) ? $matches[1] : null;
 }
Пример #28
0
 /**
  * Create product via curl.
  *
  * @param array $data
  * @return int|null
  * @throws \Exception
  */
 protected function createOrder(array $data)
 {
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     foreach ($this->steps as $key => $step) {
         if (!isset($data[$key])) {
             continue;
         }
         $url = $_ENV['app_backend_url'] . 'sales/order_create/loadBlock/block/' . $step . '?isAjax=true';
         $curl->write($url, $data[$key]);
         $curl->read();
     }
     $url = $_ENV['app_backend_url'] . 'sales/order_create/save';
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data['order_data']);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Order creation by curl handler was not successful! Response: {$response}");
     }
     preg_match("~<h1 class=\"page-title\">#(.*)</h1>~", $response, $matches);
     return isset($matches[1]) ? $matches[1] : null;
 }
Пример #29
0
 /**
  * Apply config settings via curl.
  *
  * @param array $data
  * @param string $section
  * @throws \Exception
  */
 protected function applyConfigSettings(array $data, $section)
 {
     $url = $this->getUrl($section);
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (strpos($response, 'data-ui-id="messages-message-success"') === false) {
         $this->_eventManager->dispatchEvent(['curl_failed'], [$response]);
         throw new \Exception("Configuration settings are not applied! Url: {$url}");
     }
 }
Пример #30
0
 /**
  * Get store id by store name.
  *
  * @param string $storeName
  * @return int
  * @throws \Exception
  */
 protected function getStoreGroupIdByGroupName($storeName)
 {
     //Set pager limit to 2000 in order to find created store group by name
     $url = $_ENV['app_backend_url'] . 'system_store/index/sort/group_title/dir/asc/limit/2000';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->addOption(CURLOPT_HEADER, 1);
     $curl->write(CurlInterface::POST, $url, '1.0');
     $response = $curl->read();
     preg_match('@.*group_id/(\\d+).*' . $storeName . '@siu', $response, $matches);
     if (empty($matches)) {
         throw new \Exception('Cannot find store group id');
     }
     return intval($matches[1]);
 }