/**
  * @inheritdoc
  *
  * @return array
  */
 public function run()
 {
     $this->objectManager->create(\Magento\Customer\Test\TestStep\LoginCustomerOnFrontendStep::class, ['customer' => $this->customer])->run();
     $this->customerAccountIndex->getAccountMenuBlock()->openMenuItem('My Credit Cards');
     $myCreditCardsBlock = $this->myCreditCardsPage->getCreditCardsBlock();
     $creditCardData = $this->creditCard->getData();
     $creditCardNumber = preg_grep('/([a-z]+)_number/', array_flip($creditCardData));
     $lastFourDigits = substr(key($creditCardNumber), -4, 4);
     $availableCreditCards = $myCreditCardsBlock->getCreditCards();
     if (key_exists($lastFourDigits, $availableCreditCards)) {
         $myCreditCardsBlock->deleteCreditCard($availableCreditCards[$lastFourDigits]);
     }
     $this->assertCreditCardDeletedMessage->processAssert($this->myCreditCardsPage);
     return ['deletedCreditCard' => $lastFourDigits];
 }
示例#2
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]];
 }
示例#3
0
 /**
  * Prepare and return data of review
  *
  * @param FixtureInterface $review
  * @return array
  */
 protected function getPreparedData(FixtureInterface $review)
 {
     $data = $review->getData();
     /* Prepare ratings */
     if ($review->hasData('ratings')) {
         $sourceRatings = $review->getDataFieldConfig('ratings')['source'];
         $ratings = [];
         foreach ($data['ratings'] as $rating) {
             $ratings[$rating['title']] = $rating['rating'];
         }
         $data['ratings'] = [];
         foreach ($sourceRatings->getRatings() as $ratingFixture) {
             /** @var Rating $ratingFixture */
             $ratingCode = $ratingFixture->getRatingCode();
             if (isset($ratings[$ratingCode])) {
                 $ratingOptions = $ratingFixture->getOptions();
                 $vote = $ratings[$ratingCode];
                 $data['ratings'][$ratingFixture->getRatingId()] = $ratingOptions[$vote];
             }
         }
     }
     if ($review->hasData('select_stores')) {
         foreach (array_keys($data['select_stores']) as $key) {
             if (isset($this->mappingData['select_stores'][$data['select_stores'][$key]])) {
                 $data['select_stores'][$key] = $this->mappingData['select_stores'][$data['select_stores'][$key]];
             }
         }
     }
     /* Prepare product id */
     $data['product_id'] = $data['entity_id'];
     unset($data['entity_id']);
     return $data;
 }
 /**
  * Prepare filter for assert
  *
  * @param FixtureInterface $product
  * @param Review $review
  * @param string $gridStatus
  * @return array
  */
 public function prepareFilter(FixtureInterface $product, Review $review, $gridStatus)
 {
     $filter = [];
     foreach ($this->filter as $key => $item) {
         list($type, $param) = [$key, $item];
         if (is_numeric($key)) {
             $type = $param = $item;
         }
         switch ($param) {
             case 'name':
             case 'sku':
                 $value = $product->getData($param);
                 break;
             case 'select_stores':
                 $value = $review->getData($param)[0];
                 break;
             case 'status_id':
                 $value = $gridStatus != '' ? $gridStatus : $review->getData($param);
                 break;
             default:
                 $value = $review->getData($param);
                 break;
         }
         if ($value !== null) {
             $filter += [$type => $value];
         }
     }
     return $filter;
 }
 /**
  * Get grouped price with fixture product and product page
  *
  * @param View $view
  * @param FixtureInterface $product
  * @return array
  */
 protected function getGroupedPrice(View $view, FixtureInterface $product)
 {
     $fields = $product->getData();
     $groupPrice['onPage'] = $view->getPriceBlock()->getSpecialPrice();
     $groupPrice['fixture'] = number_format($fields['group_price'][array_search($this->customerGroup, $fields['group_price'])]['price'], 2);
     return $groupPrice;
 }
示例#6
0
 /**
  * Prepare data from text to values
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData($fixture)
 {
     $data = $this->replaceMappingData($fixture->getData());
     if (isset($data['website_ids'])) {
         $websiteIds = [];
         foreach ($data['website_ids'] as $websiteId) {
             $websiteIds[] = isset($this->websiteIds[$websiteId]) ? $this->websiteIds[$websiteId] : $websiteId;
         }
         $data['website_ids'] = $websiteIds;
     }
     if (isset($data['customer_group_ids'])) {
         $customerGroupIds = [];
         foreach ($data['customer_group_ids'] as $customerGroupId) {
             $customerGroupIds[] = isset($this->customerGroupIds[$customerGroupId]) ? $this->customerGroupIds[$customerGroupId] : $customerGroupId;
         }
         $data['customer_group_ids'] = $customerGroupIds;
     }
     if (!isset($data['stop_rules_processing'])) {
         $data['stop_rules_processing'] = 0;
     }
     if (!isset($data['rule'])) {
         $data['rule'] = null;
     }
     $data['rule'] = ['conditions' => $this->prepareCondition($data['rule'])];
     return $data;
 }
示例#7
0
 /**
  * Fill the root form.
  *
  * @param FixtureInterface $fixture
  * @param SimpleElement|null $element
  * @return $this
  */
 public function fill(FixtureInterface $fixture, SimpleElement $element = null)
 {
     // Prepare price data
     $data = $fixture->getData();
     if (isset($data['price'])) {
         $data = array_merge($data, $data['price']);
         unset($data['price']);
     }
     // Mapping
     $mapping = $this->dataMapping($data);
     $attributeType = $attributeCode = '';
     if ($fixture->hasData('custom_attribute')) {
         /** @var CatalogProductAttribute $attribute */
         $attribute = $fixture->getDataFieldConfig('custom_attribute')['source']->getAttribute();
         $attributeType = $attribute->getFrontendInput();
         $attributeCode = $attribute->getAttributeCode();
     }
     if ($this->hasRender($attributeType)) {
         $element = $this->_rootElement->find(sprintf($this->customAttributeSelector, $attributeCode));
         $arguments = ['fixture' => $fixture, 'element' => $element, 'mapping' => $mapping];
         $this->callRender($attributeType, 'fill', $arguments);
     } else {
         $this->_fill($mapping, $element);
     }
     return $this;
 }
示例#8
0
文件: Curl.php 项目: opexsw/magento2
 /**
  * Prepare data for POST request.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $result = [];
     $data = $fixture->getData();
     $result['rate'][$data['currency_from']][$data['currency_to']] = $data['rate'];
     return $result;
 }
示例#9
0
 /**
  * Fill form with custom fields.
  * (for End To End Tests)
  *
  * @param FixtureInterface $fixture
  * @param array $fields
  * @param SimpleElement $element
  */
 public function fillCustom(FixtureInterface $fixture, array $fields, SimpleElement $element = null)
 {
     $data = $fixture->getData('fields');
     $dataForMapping = array_intersect_key($data, array_flip($fields));
     $mapping = $this->dataMapping($dataForMapping);
     $this->_fill($mapping, $element);
 }
 /**
  * Prepare filter for assert.
  *
  * @param FixtureInterface $product
  * @param array $review
  * @param string $gridStatus [optional]
  * @return array
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function prepareFilter(FixtureInterface $product, array $review, $gridStatus = '')
 {
     $filter = [];
     foreach ($this->filter as $key => $item) {
         list($type, $param) = [$key, $item];
         if (is_numeric($key)) {
             $type = $param = $item;
         }
         switch ($param) {
             case 'name':
             case 'sku':
                 $value = $product->getData($param);
                 break;
             case 'select_stores':
                 $value = isset($review[$param]) ? $review[$param][0] : null;
                 break;
             case 'status_id':
                 $value = $gridStatus != '' ? $gridStatus : (isset($review[$param]) ? $review[$param] : null);
                 break;
             case 'type':
                 $value = isset($review[$param]) ? $review[$param] : 'Administrator';
                 break;
             default:
                 $value = isset($review[$param]) ? $review[$param] : null;
                 break;
         }
         if ($value !== null) {
             $filter += [$type => $value];
         }
     }
     return $filter;
 }
示例#11
0
 /**
  * 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;
 }
示例#12
0
 /**
  * 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;
 }
示例#13
0
文件: Curl.php 项目: opexsw/magento2
 /**
  * Post request for creating sales rule.
  *
  * @param FixtureInterface $fixture
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $this->mapTypeParams = array_merge($this->mapTypeParams, $this->additionalMapTypeParams);
     $url = $_ENV['app_backend_url'] . 'sales_rule/promo_quote/save/';
     $data = $this->replaceMappingData($fixture->getData());
     $data['rule'] = [];
     if (isset($data['conditions_serialized'])) {
         $data['rule']['conditions'] = $this->prepareCondition($data['conditions_serialized']);
         unset($data['conditions_serialized']);
     }
     $data['website_ids'] = $this->prepareWebsites($data);
     $data['customer_group_ids'] = $this->prepareCustomerGroup($data);
     if (isset($data['actions_serialized'])) {
         $this->mapTypeParams['Conditions combination']['type'] = 'Magento\\SalesRule\\Model\\Rule\\Condition\\Product\\Combine';
         $data['rule']['actions'] = $this->prepareCondition($data['actions_serialized']);
         unset($data['actions_serialized']);
     }
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $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("Sales rule entity creating by curl handler was not successful! Response: {$response}");
     }
     preg_match('`<tr.*title=".*sales_rule\\/promo_quote\\/edit\\/id\\/([\\d]+)`ims', $response, $matches);
     if (empty($matches)) {
         throw new \Exception('Cannot find Sales Rule id');
     }
     return ['id' => $matches[1]];
 }
示例#14
0
 /**
  * Prepare data for curl.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data = ['catalogevent' => $this->replaceMappingData($fixture->getData())];
     $data['catalogevent']['display_state'] = array_values($data['catalogevent']['display_state']);
     $categoryId = isset($data['catalogevent']['category_id']['id']) ? $data['catalogevent']['category_id']['id'] : $fixture->getDataFieldConfig('category_id')['source']->getCategory()->getId();
     return ['data' => $data, 'categoryId' => $categoryId];
 }
示例#15
0
 /**
  * Prepare data from text to values
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data = ['store' => $this->replaceMappingData($fixture->getData()), 'store_action' => 'add', 'store_type' => 'store'];
     $data['store']['group_id'] = $fixture->getDataFieldConfig('group_id')['source']->getStoreGroup()->getGroupId();
     $data['store']['store_id'] = isset($data['store']['store_id']) ? $data['store']['store_id'] : '';
     return $data;
 }
 /**
  * Verify product special price on product view page
  *
  * @param FixtureInterface $product
  * @param View $productViewBlock
  * @return void
  */
 public function assertPrice(FixtureInterface $product, View $productViewBlock)
 {
     $fields = $product->getData();
     $specialPrice = $productViewBlock->getPriceBlock()->getSpecialPrice();
     if (isset($fields['special_price'])) {
         \PHPUnit_Framework_Assert::assertEquals(number_format($fields['special_price'], 2), $specialPrice, $this->errorMessage);
     }
 }
示例#17
0
 /**
  * Prepare fixture data before send.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData();
     $data = $this->prepareResourceAccess($data);
     $data = array_merge($data, $this->prepareAssignedUsers($fixture));
     $data = array_merge($data, $this->prepareAdminScope($data));
     return $this->replaceMappingData($data);
 }
示例#18
0
 /**
  * Fill the 3D Secure form and submit it.
  *
  * @param FixtureInterface $fixture
  * @param SimpleElement|null $element
  * @return $this|void
  */
 public function fill(FixtureInterface $fixture, SimpleElement $element = null)
 {
     $mapping = $this->dataMapping($fixture->getData());
     $this->switchToFrame($this->braintree3dSecure);
     $element = $this->browser->find('body');
     $this->_fill([$mapping['secure3d_password']], $element);
     $this->submit();
     $this->browser->switchToFrame();
 }
 /**
  * Fill the root form
  *
  * @param FixtureInterface $fixture
  * @param SimpleElement|null $element
  * @return $this
  */
 public function fill(FixtureInterface $fixture, SimpleElement $element = null)
 {
     $element = $this->_rootElement->find(sprintf($this->currencyRow, $fixture->getCode()), Locator::SELECTOR_XPATH);
     $data = $fixture->getData();
     unset($data['code']);
     $mapping = $this->dataMapping($data);
     $this->_fill($mapping, $element);
     return $this;
 }
 /**
  * Prepare data for url rewrite fixture.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data = $fixture->getData();
     if (empty($data['entity_type']) && empty($this->getData()['target_path']) && !isset($data['target_path'])) {
         $entity = $fixture->getDataFieldConfig('target_path')['source']->getEntity();
         $data['target_path'] = $entity->hasData('identifier') ? $entity->getIdentifier() : $entity->getUrlKey() . '.html';
     }
     return $data;
 }
示例#21
0
 /**
  * Prepare POST data for creating product request.
  *
  * @param FixtureInterface $fixture
  * @param string|null $prefix [optional]
  * @return array
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function prepareData(FixtureInterface $fixture, $prefix = null)
 {
     $fields = $this->replaceMappingData($fixture->getData());
     if (!isset($fields['status'])) {
         // Default product is enabled
         $fields['status'] = 1;
     }
     if (!isset($fields['visibility'])) {
         // Default product is visible on Catalog, Search
         $fields['visibility'] = 4;
     }
     // Getting Tax class id
     if ($fixture->hasData('tax_class_id')) {
         $fields['tax_class_id'] = $fixture->getDataFieldConfig('tax_class_id')['source']->getTaxClassId();
     }
     if (!empty($fields['category_ids'])) {
         $categoryIds = [];
         foreach ($fixture->getDataFieldConfig('category_ids')['source']->getCategories() as $category) {
             $categoryIds[] = $category->getId();
         }
         $fields['category_ids'] = $categoryIds;
     }
     if (isset($fields['tier_price'])) {
         $fields['tier_price'] = $this->preparePriceData($fields['tier_price']);
     }
     if (isset($fields['fpt'])) {
         $attributeLabel = $fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getDataFieldConfig('assigned_attributes')['source']->getAttributes()[0]->getFrontendLabel();
         $fields[$attributeLabel] = $this->prepareFptData($fields['fpt']);
     }
     if ($isCustomOptions = isset($fields['custom_options'])) {
         $fields = $this->prepareCustomOptionsData($fields);
     }
     if (!empty($fields['website_ids'])) {
         foreach ($fields['website_ids'] as &$value) {
             $value = isset($this->mappingData['website_ids'][$value]) ? $this->mappingData['website_ids'][$value] : $value;
         }
     }
     // Getting Attribute Set id
     if ($fixture->hasData('attribute_set_id')) {
         $attributeSetId = $fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getAttributeSetId();
         $fields['attribute_set_id'] = $attributeSetId;
     }
     // Prepare assigned attribute
     if (isset($fields['attributes'])) {
         $fields += $fields['attributes'];
         unset($fields['attributes']);
     }
     if (isset($fields['custom_attribute'])) {
         $fields[$fields['custom_attribute']['code']] = $fields['custom_attribute']['value'];
     }
     $fields = $this->prepareStockData($fields);
     $fields = $prefix ? [$prefix => $fields] : $fields;
     if ($isCustomOptions) {
         $fields['affect_product_custom_options'] = 1;
     }
     return $fields;
 }
示例#22
0
 /**
  * Fill the review form.
  *
  * @param FixtureInterface $fixture
  * @param SimpleElement|null $element
  * @return $this
  */
 public function fill(FixtureInterface $fixture, SimpleElement $element = null)
 {
     $data = $fixture->getData();
     if (isset($data['entity_id'])) {
         unset($data['entity_id']);
     }
     $mapping = $this->dataMapping($data);
     $this->_fill($mapping, $element);
     return $this;
 }
示例#23
0
 /**
  * Prepare data.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     /** @var Role $fixture */
     $data = $this->replaceMappingData($fixture->getData());
     if (isset($data['roles_resources'])) {
         $data['resource'] = $this->prepareRolesResources($data['roles_resources']);
         unset($data['roles_resources']);
     }
     return $data;
 }
示例#24
0
 /**
  * Post request for creating currency symbol
  *
  * @param FixtureInterface $fixture
  * @return void
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData();
     $url = $_ENV['app_backend_url'] . 'admin/system_currencysymbol/save';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->write(CurlInterface::POST, $url, '1.0', [], $data);
     $curl->read();
     $curl->close();
     // Response verification is absent, because sending a post request returns an index page
 }
示例#25
0
 /**
  * Post request for creating tax class.
  *
  * @param FixtureInterface $fixture [optional]
  * @return mixed|string
  */
 public function persist(FixtureInterface $fixture = null)
 {
     $data = $fixture->getData();
     $url = $_ENV['app_backend_url'] . 'tax/tax/ajaxSave/?isAjax=true';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     $id = $this->getClassId($response);
     return ['id' => $id];
 }
示例#26
0
 /**
  * Fill the root form.
  *
  * @param FixtureInterface $fixture
  * @param SimpleElement|null $element
  * @return $this
  */
 public function fill(FixtureInterface $fixture, SimpleElement $element = null)
 {
     $data = $fixture->getData();
     foreach ($data as $name => $dataValue) {
         $fields['toggle_' . $name] = 'Yes';
         $fields[$name] = $dataValue;
     }
     $mapping = $this->dataMapping($fields);
     $this->_fill($mapping, $element);
     return $this;
 }
 /**
  * Fill popup form
  *
  * @param FixtureInterface $product
  * @param SimpleElement|null $element [optional]
  * @return $this
  */
 public function fill(FixtureInterface $product, SimpleElement $element = null)
 {
     $affectedAttributeSet = $product->getData('affected_attribute_set');
     if ($affectedAttributeSet) {
         $fields = ['new_attribute_set_name' => $affectedAttributeSet];
         $mapping = $this->dataMapping($fields);
         $this->_rootElement->find($this->affectedAttributeSetNew)->click();
         $this->_fill($mapping, $element);
     }
     return $this;
 }
示例#28
0
 /**
  * Post request for creating Product Attribute
  *
  * @param FixtureInterface|null $fixture [optional]
  * @return array
  * @throws \Exception
  */
 public function persist(FixtureInterface $fixture = null)
 {
     if ($fixture->hasData('attribute_id')) {
         return ['attribute_id' => $fixture->getData('attribute_id')];
     }
     $data = $this->replaceMappingData($fixture->getData());
     $data['frontend_label'] = [0 => $data['frontend_label']];
     if (isset($data['options'])) {
         foreach ($data['options'] as $key => $values) {
             $index = 'option_' . $key;
             if ($values['is_default'] == 'Yes') {
                 $data['default'][] = $index;
             }
             $data['option']['value'][$index] = [$values['admin'], $values['view']];
             $data['option']['order'][$index] = $key;
         }
         unset($data['options']);
     }
     $url = $_ENV['app_backend_url'] . 'catalog/product_attribute/save/back/edit';
     $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
     $curl->write($url, $data);
     $response = $curl->read();
     $curl->close();
     if (!strpos($response, 'data-ui-id="messages-message-success"')) {
         throw new \Exception("Product Attribute creating by curl handler was not successful! \n" . $response);
     }
     $resultData = [];
     $matches = [];
     preg_match('#attribute_id[^>]+value="(\\d+)"#', $response, $matches);
     $resultData['attribute_id'] = $matches[1];
     $matches = [];
     preg_match_all('#"id":"(\\d+)"#Umi', $response, $matches);
     if ($fixture->hasData('options')) {
         $optionsData = $fixture->getData()['options'];
         foreach (array_unique($matches[1]) as $key => $optionId) {
             $optionsData[$key]['id'] = $optionId;
         }
         $resultData['options'] = $optionsData;
     }
     return $resultData;
 }
示例#29
0
文件: Curl.php 项目: koliaGI/magento2
 /**
  * Prepare data from text to values.
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData($fixture)
 {
     $data = $this->replaceMappingData($fixture->getData());
     if (isset($data['stores'])) {
         $stores = [];
         foreach ($data['stores'] as $store) {
             $stores[] = isset($this->stores[$store]) ? $this->stores[$store] : $store;
         }
         $data['stores'] = $stores;
     }
     return $data;
 }
 /**
  * Prepare POST data for creating customer request
  *
  * @param FixtureInterface $fixture
  * @return array
  */
 protected function prepareData(FixtureInterface $fixture)
 {
     $data = $fixture->getData('fields');
     foreach ($data as $key => $values) {
         $value = $this->getValue($values);
         if (null === $value) {
             continue;
         }
         $data[$key] = $value;
     }
     return $data;
 }