/** * Create product * * @param FixtureInterface $fixture [optional] * @return mixed|string */ public function persist(FixtureInterface $fixture = null) { Factory::getApp()->magentoBackendLoginUser(); $createProductPage = Factory::getPageFactory()->getCatalogProductNew(); $createProductPage->open(['type' => $fixture->getDataConfig()['create_url_params']['type'], 'set' => $fixture->getDataConfig()['create_url_params']['set']]); $createProductPage->getProductForm()->fill($fixture); $createProductPage->getFormPageActions()->save(); $createProductPage->getMessagesBlock()->waitSuccessMessage(); }
/** * Post request for creating simple product. * * @param FixtureInterface|null $fixture [optional] * @return array * * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function persist(FixtureInterface $fixture = null) { $config = $fixture->getDataConfig(); $prefix = isset($config['input_prefix']) ? $config['input_prefix'] : null; $data = $this->prepareData($fixture, $prefix); return $this->createProduct($data, $config); }
/** * Post request for creating simple product * * @param FixtureInterface $fixture [optional] * @return mixed|string * @throws \Exception * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function persist(FixtureInterface $fixture = null) { $config = $fixture->getDataConfig(); $prefix = isset($config['input_prefix']) ? $config['input_prefix'] : null; // @todo remove "if" when fixtures refactored if ($fixture instanceof InjectableFixture) { $fields = $fixture->getData(); if ($prefix) { $data[$prefix] = $fields; } else { $data = $fields; } } else { $data = $this->_prepareData($fixture->getData('fields'), $prefix); } if ($fixture->getData('category_id')) { $data['product']['category_ids'] = $fixture->getCategoryIds(); } $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); return isset($matches[1]) ? $matches[1] : null; }
/** * Assert that duplicated product is found by sku and has correct product type, product template, * product status disabled and out of stock * * @param FixtureInterface $product * @param CatalogProductIndex $productGrid * @return void */ public function processAssert(FixtureInterface $product, CatalogProductIndex $productGrid) { $config = $product->getDataConfig(); $filter = ['name' => $product->getName(), 'visibility' => $product->getVisibility(), 'status' => 'Disabled', 'sku' => $product->getSku() . '-1', 'type' => ucfirst($config['create_url_params']['type']) . ' Product', 'price_to' => number_format($product->getPrice(), 2)]; $productGrid->open()->getProductGrid()->search($filter); $filter['price_to'] = '$' . $filter['price_to']; \PHPUnit_Framework_Assert::assertTrue($productGrid->getProductGrid()->isRowVisible($filter, false), 'Product duplicate is absent in Products grid.'); }
/** * Select order item. * * @param FixtureInterface $product * @reutrn void */ public function selectItem(FixtureInterface $product) { /** @var CatalogProductSimple $product */ $productConfig = $product->getDataConfig(); if (isset($this->productsGrids[$productConfig['type_id']])) { $this->blockFactory->create($this->productsGrids[$productConfig['type_id']], ['element' => $this->_rootElement])->selectItem($product); } else { $this->searchAndSelect(['name' => $product->getName()]); } }
/** * Select order item. * * @param FixtureInterface $product * @reutrn void */ public function selectItem(FixtureInterface $product) { /** @var CatalogProductSimple $product */ $productConfig = $product->getDataConfig(); $productType = isset($productConfig['type_id']) ? ucfirst($productConfig['type_id']) : ''; $productGridClass = 'Enterprise\\Rma\\Test\\Block\\Adminhtml\\Rma\\NewRma\\Tab\\Items\\Order\\' . $productType . 'Grid'; if (class_exists($productGridClass)) { $productGrid = $this->blockFactory->create($productGridClass, ['element' => $this->_rootElement]); $productGrid->selectItem($product); } else { $this->searchAndSelect(['name' => $product->getName()]); } }
/** * Get cart item block * * @param FixtureInterface $product * @return CartItem */ public function getCartItem(FixtureInterface $product) { $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; $cartItem = null; if ($this->hasRender($typeId)) { $cartItem = $this->callRender($typeId, 'getCartItem', ['product' => $product]); } else { $cartItemBlock = $this->_rootElement->find(sprintf($this->cartItemByProductName, $product->getName()), Locator::SELECTOR_XPATH); $cartItem = $this->blockFactory->create('Magento\\Weee\\Test\\Block\\Cart\\CartItem', ['element' => $cartItemBlock]); } return $cartItem; }
/** * Click on "Save" button * * @param FixtureInterface|null $product [optional] * @return void */ public function save(FixtureInterface $product = null) { $typeId = null; if ($product) { $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; } if ($this->hasRender($typeId)) { $this->callRender($typeId, 'save', ['product' => $product]); } else { parent::save(); } }
/** * 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 product form. * * @param FixtureInterface $product * @param SimpleElement|null $element * @param FixtureInterface|null $category * @return $this * @throws \Exception * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function fill(FixtureInterface $product, SimpleElement $element = null, FixtureInterface $category = null) { $this->waitPageToLoad(); $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; if ($this->hasRender($typeId)) { $renderArguments = ['product' => $product, 'element' => $element, 'category' => $category]; $this->callRender($typeId, 'fill', $renderArguments); } else { $sections = $this->getFixtureFieldsByContainers($product); if ($category) { $sections['product-details']['category_ids']['value'] = $category->getName(); } $this->fillContainers($sections, $element); } return $this; }
/** * Return product options. * * @param FixtureInterface $product * @return array */ public function getOptions(FixtureInterface $product) { /** @var CatalogProductSimple $product */ $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; return $this->hasRender($typeId) ? $this->callRender($typeId, 'getOptions', ['product' => $product]) : $this->getCustomOptionsBlock()->getOptions($product); }
/** * Get product type * * @return string */ protected function getProductType() { $config = $this->product->getDataConfig(); return ucfirst($config['type_id']) . ' Product'; }
/** * Get product type. * * @param FixtureInterface $product * @return string|null */ protected function getProductType(FixtureInterface $product) { $dataConfig = $product->getDataConfig(); return isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; }
/** * Create and save product * * @param FixtureInterface $product * @return void */ protected function createAndSaveProduct(FixtureInterface $product) { $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; $this->catalogProductIndex->open(); $this->catalogProductIndex->getGridPageActionBlock()->addProduct($typeId); $this->catalogProductNew->getProductForm()->fill($product); $this->catalogProductNew->getFormPageActions()->save($product); }
/** * Fill the product form. * * @param FixtureInterface $product * @param SimpleElement|null $element [optional] * @param FixtureInterface|null $category [optional] * @return FormTabs * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function fill(FixtureInterface $product, SimpleElement $element = null, FixtureInterface $category = null) { $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; if ($this->hasRender($typeId)) { $renderArguments = ['product' => $product, 'element' => $element, 'category' => $category]; $this->callRender($typeId, 'fill', $renderArguments); } else { $tabs = $this->getFieldsByTabs($product); if ($category) { $tabs['product-details']['category_ids']['value'] = $category->getName(); } $this->showAdvancedSettings(); $this->fillTabs($tabs, $element); if ($product->hasData('custom_attribute')) { $this->createCustomAttribute($product); } } return $this; }
/** * Get module name from fixture. * * @param FixtureInterface $product * @return string */ protected function getCartItemClass(FixtureInterface $product) { $typeId = $product->getDataConfig()['type_id']; return ObjectManager::getInstance()->create($this->itemRender[$typeId], ['product' => $product]); }
/** * POST request for creating downloadable product * * @param FixtureInterface $fixture [optional] * @return int id of created product */ public function persist(FixtureInterface $fixture = null) { $config = $fixture->getDataConfig(); $curl = new BackendDecorator(new CurlTransport(), new Config()); $curl->addOption(CURLOPT_HEADER, 1); $curl->write(CurlInterface::POST, $this->getUrl($config), '1.0', [], $this->prepareData($fixture->getData('fields'), isset($config['input_prefix']) ? $config['input_prefix'] : null)); $response = $curl->read(); $curl->close(); preg_match("~Location: [^\\s]*\\/id\\/(\\d+)~", $response, $matches); return $matches[1]; }
/** * Post request for creating simple product. * * @param FixtureInterface|null $fixture [optional] * @return array */ public function persist(FixtureInterface $fixture = null) { $config = $fixture->getDataConfig(); $data = $this->prepareData($fixture); return $this->createProduct($data, $config); }