/** * Prepare data from text to values * * @param FixtureInterface $fixture * @return array */ protected function prepareData(FixtureInterface $fixture) { $categoryId = $fixture->getDataFieldConfig('root_category_id')['source']->getCategory()->getId(); $websiteId = $fixture->getDataFieldConfig('website_id')['source']->getWebsite()->getWebsiteId(); $data = ['group' => ['name' => $fixture->getName(), 'root_category_id' => $categoryId, 'website_id' => $websiteId, 'group_id' => $fixture->hasData('group_id') ? $fixture->getGroupId() : ''], 'store_action' => 'add', 'store_type' => 'group']; return $data; }
/** * 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; }
/** * Prepare data from text to values. * * @param FixtureInterface $fixture * @return array */ protected function prepareData($fixture) { /** @var CustomerBalance $fixture */ $customer = $fixture->getDataFieldConfig('customer_id')['source']->getCustomer(); /** @var Website $website */ $website = $fixture->getDataFieldConfig('website_id')['source']->getWebsite(); /** @var Customer $customer */ return ['customer_id' => $customer->getId(), 'customerbalance' => ['amount_delta' => $fixture->getAmountDelta(), 'website_id' => $website->getWebsiteId(), 'comment' => $fixture->getComment()]]; }
/** * Prepare data. * * @param FixtureInterface $fixture * @param $isSearchByEmail * @return array */ protected function prepareData(FixtureInterface $fixture, $isSearchByEmail) { /** @var Order $fixture */ /** @var Customer $customer */ $customer = $fixture->getDataFieldConfig('customer_id')['source']->getCustomer(); $data = ['order_id' => $fixture->getId(), 'billing_last_name' => $customer->getLastname()]; if ($isSearchByEmail) { $data['find_order_by'] = 'Email'; $data['email_address'] = $customer->getEmail(); } else { $data['find_order_by'] = 'ZIP Code'; $data['billing_zip_code'] = $fixture->getDataFieldConfig('billing_address_id')['source']->getPostcode(); } return $data; }
/** * Fill the root form. * * @param FixtureInterface $fixture * @param SimpleElement|null $element * @param array|null $mapping * @return $this */ public function fill(FixtureInterface $fixture, SimpleElement $element = null, array $mapping = null) { $attribute = $fixture->getDataFieldConfig('custom_attribute')['source']->getAttribute(); $mapping['custom_attribute']['selector'] = sprintf($this->inputSelector, $attribute->getAttributeCode()); $this->_fill($mapping, $element); return $this; }
/** * Preparing matrix data * * @param FixtureInterface $product * @return array */ protected function prepareVariationsMatrix(FixtureInterface $product) { /** @var ConfigurableAttributesData $configurableAttributesData */ $configurableAttributesData = $product->getDataFieldConfig('configurable_attributes_data')['source']; $attributesData = $configurableAttributesData->getAttributesData(); $assignedProducts = $configurableAttributesData->getProducts(); $matrixData = $product->getConfigurableAttributesData()['matrix']; $result = []; foreach ($matrixData as $variationKey => $variation) { // For assigned products doesn't send data about them if (isset($assignedProducts[$variationKey])) { continue; } $compositeKeys = explode(' ', $variationKey); $keyIds = []; $configurableAttribute = []; foreach ($compositeKeys as $compositeKey) { list($attributeKey, $optionKey) = explode(':', $compositeKey); $attribute = $attributesData[$attributeKey]; $keyIds[] = $attribute['options'][$optionKey]['id']; $configurableAttribute[] = sprintf('"%s":"%s"', $attribute['attribute_code'], $attribute['options'][$optionKey]['id']); } $keyIds = implode('-', $keyIds); $variation['configurable_attribute'] = '{' . implode(',', $configurableAttribute) . '}'; $result[$keyIds] = $variation; } return $result; }
/** * 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; }
/** * Post request for creating order. * * @param FixtureInterface|null $fixture [optional] * @return array */ public function persist(FixtureInterface $fixture = null) { $this->order = $fixture; $this->customer = $fixture->getDataFieldConfig('customer_id')['source']->getCustomer(); $data = $this->replaceMappingData($this->prepareData($fixture)); return ['id' => $this->createOrder($data)]; }
/** * 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]]; }
/** * 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; }
/** * 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]; }
/** * 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 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; }
/** * Prepare fixture data. * * @param FixtureInterface $fixture * @return array */ protected function prepareData(FixtureInterface $fixture) { /** @var Reward $fixture */ $customer = $fixture->getDataFieldConfig('customer_id')['source']->getCustomer(); /** @var Customer $customer */ $data = $customer->getData(); $data['customer_id'] = $customer->getId(); $data['reward']['points_delta'] = $fixture->getPointsDelta(); return $data; }
/** * Fill the form. * * @param FixtureInterface $fixture * @param SimpleElement|null $element * @param bool $isSearchByEmail [optional] * @return $this */ public function fill(FixtureInterface $fixture, SimpleElement $element = null, $isSearchByEmail = true) { /** @var OrderInjectable $fixture */ /** @var Customer $customer */ $customer = $fixture->getDataFieldConfig('customer_id')['source']->getCustomer(); $data = ['order_id' => $fixture->getId(), 'billing_last_name' => $customer->getLastname()]; if ($isSearchByEmail) { $data['find_order_by'] = 'Email'; $data['email_address'] = $customer->getEmail(); } else { $data['find_order_by'] = 'ZIP Code'; $data['billing_zip_code'] = $fixture->getDataFieldConfig('billing_address_id')['source']->getPostcode(); } $fields = isset($data['fields']) ? $data['fields'] : $data; $mapping = $this->dataMapping($fields); $this->waitLoadForm(); $this->_fill($mapping, $element); return $this; }
/** * Prepare data for create widget. * * @param FixtureInterface $widget * @return array */ protected function prepareData(FixtureInterface $widget) { $data = $this->replaceMappingData($widget->getData()); if ($widget->hasData('store_ids')) { $data['store_ids'][0] = $widget->getDataFieldConfig('store_ids')['source']->getStores()[0]->getStoreId(); } unset($data['code']); unset($data['theme_id']); $data = $this->prepareWidgetInstance($data); $data = $this->prepareParameters($data); return $data; }
/** * Prepare data * * @param FixtureInterface $fixture * @return array */ protected function prepareData($fixture) { $data = []; /** @var \Magento\CheckoutAgreements\Test\Fixture\CheckoutAgreement $fixture */ $stores = $fixture->getDataFieldConfig('stores')['source']->getStores(); foreach ($stores as $store) { /** @var \Magento\Store\Test\Fixture\Store $store */ $data['stores'][] = $store->getStoreId(); } $data = $this->replaceMappingData(array_merge($fixture->getData(), $data)); return $data; }
/** * Fill the root form. * * @param FixtureInterface $fixture * @param SimpleElement|null $element * @param array|null $mapping * @return $this */ public function fill(FixtureInterface $fixture, SimpleElement $element = null, array $mapping = null) { $data = $fixture->getData(); // Mapping $mapping = $this->dataMapping($data, $mapping); $attribute = $fixture->getDataFieldConfig('custom_attribute')['source']->getAttribute(); $mappingDate['custom_attribute']['from'] = $mapping['custom_attribute']; $mappingDate['custom_attribute']['to'] = $mapping['custom_attribute']; $attributeCode = $attribute->getAttributeCode(); $mappingDate['custom_attribute']['from']['selector'] = sprintf($this->dateFromSelector, $attributeCode); $mappingDate['custom_attribute']['to']['selector'] = sprintf($this->dateToSelector, $attributeCode); $this->_fill($mappingDate, $element); return $this; }
/** * Assert form data equals fixture data * * @param FixtureInterface $product * @param CatalogProductIndex $productGrid * @param CatalogProductEdit $productPage * @return void */ public function processAssert(FixtureInterface $product, CatalogProductIndex $productGrid, CatalogProductEdit $productPage) { $filter = ['sku' => $product->getSku()]; $productGrid->open(); $productGrid->getProductGrid()->searchAndOpen($filter); $productData = $product->getData(); if ($product->hasData('custom_options')) { $customOptionsSource = $product->getDataFieldConfig('custom_options')['source']; $productData['custom_options'] = $customOptionsSource->getCustomOptions(); } $fixtureData = $this->prepareFixtureData($productData, $this->sortFields); $formData = $this->prepareFormData($productPage->getProductForm()->getData($product), $this->sortFields); $error = $this->verifyData($fixtureData, $formData); \PHPUnit_Framework_Assert::assertTrue(empty($error), $error); }
/** * 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)]; }
/** * Verify product price on category view page. * * @param FixtureInterface $bundle * @param CatalogCategoryView $catalogCategoryView * @return void */ protected function assertPrice(FixtureInterface $bundle, CatalogCategoryView $catalogCategoryView) { /** @var BundleProduct $bundle */ $priceData = $bundle->getDataFieldConfig('price')['source']->getPreset(); //Price from/to verification $priceBlock = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($bundle->getName()); if ($bundle->hasData('special_price') || $bundle->hasData('group_price')) { $priceLow = $priceBlock->getFinalPrice(); } else { $priceLow = $bundle->getPriceView() == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice(); } \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow, 'Bundle price From on category page is not correct.'); if ($bundle->getPriceView() == 'Price Range') { \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo(), 'Bundle price To on category page is not correct.'); } }
/** * Fill in the option specified for the product * * @param FixtureInterface $product * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function fillOptions(FixtureInterface $product) { $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; $checkoutData = null; /** @var CatalogProductSimple $product */ if ($this->hasRender($typeId)) { $this->callRender($typeId, 'fillOptions', ['product' => $product]); } /** @var CatalogProductSimple $product */ $checkoutData = $product->getCheckoutData(); $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : []; $customOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : []; $checkoutCustomOptions = $this->prepareCheckoutData($customOptions, $checkoutCustomOptions); $this->getCustomOptionsBlock()->fillCustomOptions($checkoutCustomOptions); }
/** * Fill the root form. * * @param FixtureInterface $fixture * @param SimpleElement|null $element * @param array $replace [optional] * @return $this */ public function fill(FixtureInterface $fixture, SimpleElement $element = null, array $replace = []) { $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'; } foreach ($replace as $key => $value) { if (isset($data[$key])) { $data[$key] = preg_replace('`(\\$.*?' . $value['name'] . '\\$)`', $value['value'], $data[$key]); } } $mapping = $this->dataMapping($data); $this->_fill($mapping, $element); return $this; }
/** * Curl creation of Admin User. * * @param FixtureInterface $fixture * @return array|mixed * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { /** @var \Mage\Admin\Test\Fixture\User $fixture */ $data = $this->replaceMappingData($fixture->getData()); if ($fixture->hasData('role_id')) { $data['roles[]'] = $fixture->getDataFieldConfig('role_id')['source']->getRole()->getRoleId(); } $url = $_ENV['app_backend_url'] . 'permissions_user/save/'; $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("Admin user entity creating by curl handler was not successful! Response: {$response}"); } return ['user_id' => $this->getId()]; }
/** * Create gift card account. * * @param FixtureInterface|null $fixture [optional] * @return array * @throws \Exception */ public function persist(FixtureInterface $fixture = null) { $data = $this->replaceMappingData($fixture->getData()); $data['website_id'] = $fixture->getDataFieldConfig('website_id')['source']->getWebsite()->getWebsiteId(); $url = $_ENV['app_backend_url'] . $this->activeTabInfo; $generateCode = $_ENV['app_backend_url'] . $this->generate; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->addOption(CURLOPT_HEADER, 1); $curl->write(CurlInterface::GET, $generateCode); $curl->read(); $curl->write(CurlInterface::POST, $url, '1.0', [], $data); $content = $curl->read(); $curl->close(); if (!strpos($content, 'class="success-msg"')) { throw new \Exception("Gift card account creation by curl handler was not successful! Response: {$content}"); } return ['code' => $this->getCode()]; }
/** * Preparation options before comparing * * @param FixtureInterface $product * @param int|null $actualPrice * @return array * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function prepareOptions(FixtureInterface $product, $actualPrice = null) { $result = []; $customOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : null; $actualPrice = $actualPrice ? $actualPrice : $product->getPrice(); foreach ($customOptions as $customOption) { $skippedField = isset($this->skippedFieldOptions[$customOption['type']]) ? $this->skippedFieldOptions[$customOption['type']] : []; foreach ($customOption['options'] as &$option) { // recalculate percent price if ('Percent' == $option['price_type']) { $option['price'] = $actualPrice * $option['price'] / 100; $option['price'] = round($option['price'], 2); } $option = array_diff_key($option, array_flip($skippedField)); } $result[$customOption['title']] = $customOption; } return $result; }
/** * Returns data for curl POST params. * * @param FixtureInterface $fixture * @return mixed * * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ protected function prepareData(FixtureInterface $fixture) { $data = $fixture->getData(); $fields = ['tax_rate', 'tax_customer_class', 'tax_product_class']; foreach ($fields as $field) { if (!array_key_exists($field, $data)) { $data[$field][] = $this->defaultTaxClasses[$field]; continue; } $fieldFixture = $fixture->getDataFieldConfig($field); $fieldFixture = $fieldFixture['source']->getFixtures(); foreach ($data[$field] as $key => $value) { $id = $fieldFixture[$key]->getId(); if ($id === null) { $fieldFixture[$key]->persist(); $id = $fieldFixture[$key]->getId(); } $data[$field][$key] = $id; } } return $data; }
/** * 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]]; }
/** * @constructor * @param FixtureInterface $product */ public function __construct(FixtureInterface $product) { /** @var GroupedProduct $product */ $checkoutData = $product->getCheckoutData(); $this->data = isset($checkoutData['cartItem']) ? $checkoutData['cartItem'] : []; $products = $product->getDataFieldConfig('associated')['source']->getProducts(); $cartItem = []; $associatedProducts = []; foreach ($products as $key => $product) { $key = 'product_key_' . $key; $associatedProducts[$key] = $product; } // Replace key in checkout data foreach ($this->data as $fieldName => $fieldValues) { foreach ($fieldValues as $key => $value) { $cartItem[$fieldName][$associatedProducts[$key]->getSku()] = $value; } } // Add empty "options" field foreach ($associatedProducts as $product) { $cartItem['options'][] = ['title' => $product->getName(), 'value' => $cartItem['qty'][$product->getSku()]]; } $this->data = $cartItem; }
/** * Assign products to category. * * @param int $categoryId * @param FixtureInterface $fixture * @return void * @throws \Exception */ protected function assignProducts($categoryId, FixtureInterface $fixture) { /** @var Category $fixture */ if ($fixture->hasData('category_products')) { $products = $fixture->getDataFieldConfig('category_products')['source']->getProducts(); $url = $_ENV['app_frontend_url'] . 'rest/V1/categories/' . $categoryId . '/products'; foreach ($products as $product) { $data = ['productLink' => ['sku' => $product->getSku(), 'category_id' => $categoryId]]; $this->webapiTransport->write($url, $data); $response = $this->webapiTransport->read(); $this->webapiTransport->close(); if ('true' != $response) { $this->eventManager->dispatchEvent(['webapi_failed'], [$response]); throw new \Exception('Assign product to category was not successful!'); } } } }