/** * Prepare data. * * @param InjectableFixture $fixture * @param $isSearchByEmail * @return array */ protected function prepareData(InjectableFixture $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; }
/** * Assert that redirect from newCategory/oldProduct is correct to new product. * * @param InjectableFixture $product * @param InjectableFixture $initialProduct * @param Browser $browser * @param CatalogProductView $catalogProductView * @return void */ public function processAssert(InjectableFixture $product, InjectableFixture $initialProduct, Browser $browser, CatalogProductView $catalogProductView) { $category = $product->getDataFieldConfig('category_ids')['source']->getProductCategory(); $productUrl = $_ENV['app_frontend_url'] . $category->getUrlKey() . '/' . $initialProduct->getUrlKey() . '.html'; $browser->open($productUrl); \PHPUnit_Framework_Assert::assertEquals($catalogProductView->getViewBlock()->getProductName(), strtoupper($product->getName())); }
/** * Check whether the attribute filter is displayed on the frontend in Layered navigation. * * @param CatalogCategoryView $catalogCategoryView * @param InjectableFixture $product * @param CatalogProductAttribute $attribute * @param CmsIndex $cmsIndex * @param FixtureFactory $fixtureFactory * @return void */ public function processAssert(CatalogCategoryView $catalogCategoryView, InjectableFixture $product, CatalogProductAttribute $attribute, CmsIndex $cmsIndex, FixtureFactory $fixtureFactory) { $fixtureFactory->createByCode('catalogProductSimple', ['dataSet' => 'product_with_category_with_anchor', 'data' => ['category_ids' => ['presets' => null, 'category' => $product->getDataFieldConfig('category_ids')['source']->getCategories()[0]]]])->persist(); $cmsIndex->open()->getTopmenu()->selectCategoryByName($product->getCategoryIds()[0]); $label = $attribute->hasData('manage_frontend_label') ? $attribute->getManageFrontendLabel() : $attribute->getFrontendLabel(); \PHPUnit_Framework_Assert::assertTrue(in_array($label, $catalogCategoryView->getLayeredNavigationBlock()->getFilters()), 'Attribute is absent in layered navigation on category page.'); }
/** * Get associated items for grouped product. * * @param InjectableFixture $product * @return array */ protected function getAssociatedItems(InjectableFixture $product) { $cartItems = []; /** @var GroupedProduct $product */ $associatedProducts = $product->getDataFieldConfig('associated')['source']->getProducts(); foreach ($associatedProducts as $product) { $cartItems[$product->getSku()] = parent::getCartItem($product); } return $cartItems; }
/** * Get full path for all categories. * * @return array */ protected function getFullPathCategories() { $result = []; $categories = $this->product->getDataFieldConfig('category_ids')['source']->getCategories(); foreach ($categories as $key => $itemCategory) { $fullPath = $this->prepareFullCategoryPath($itemCategory); $result[$key] = implode('/', $fullPath); } return $result; }
/** * Preparation of fpt attribute data. * * @return void */ protected function prepareFpt() { if ($this->fixture->hasData('fpt')) { $fptLabel = $this->fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getDataFieldConfig('assigned_attributes')['source']->getAttributes()[0]->getFrontendLabel(); $fptValues = $this->fields['product'][$fptLabel]; foreach ($fptValues as $key => $item) { $item['value'] = $item['price']; unset($item['price']); $fptValues[$key] = $item; } $this->fields['product']['custom_attributes'][] = ['attribute_code' => $fptLabel, 'value' => $fptValues]; unset($this->fields['product'][$fptLabel]); } }
/** * Preparation of fpt attribute data. * * @return void */ protected function prepareFpt() { if (isset($this->fields['product']['fpt'])) { $attributeLabel = $this->fixture->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getDataFieldConfig('assigned_attributes')['source']->getAttributes()[0]->getFrontendLabel(); foreach ($this->fields['product']['fpt'] as &$field) { foreach ($this->fptData as $key => $data) { $field[$data['name']] = $this->fptData[$key]['data'][$field[$key]]; unset($field[$key]); } $field['delete'] = ''; } $this->fields['product'][$attributeLabel] = $this->fields['product']['fpt']; unset($this->fields['product']['fpt']); } }
/** * Prepare tier price data. * * @param InjectableFixture $product * @return array */ protected function prepareTierPrices(InjectableFixture $product) { $tierPrices = $product->getTierPrice(); $percents = $product->getDataFieldConfig('price')['source']->getPreset(); foreach ($tierPrices as $key => $tierPrice) { $tierPrices[$key]['price'] = number_format($tierPrices[$key]['price'], $this->priceFormat); $tierPrices[$key]['percent'] = $percents[$key]['percent']; } return $tierPrices; }
/** * Prepare attribute data. * * @param InjectableFixture $product * @param int $key * @return array */ protected function prepareAttributeData(InjectableFixture $product, $key) { $data = []; foreach ($this->attributeProduct as $attributeKey => $attribute) { $value = $attribute; $attribute = is_numeric($attributeKey) ? $attribute : $attributeKey; $attributeValue = $attribute != 'price' ? $product->hasData($attribute) ? $product->getData($attribute) : 'N/A' : ($product->getDataFieldConfig('price')['source']->getPreset() !== null ? $product->getDataFieldConfig('price')['source']->getPreset() : number_format($product->getPrice(), 2)); $data['attributeValues'][$attribute] = !is_array($attributeValue) ? strtolower($attributeValue) : $attributeValue; $attributeName = $value === 'name' || $value === 'price' ? 'Info' : 'MetaData'; $data['attributeValuesFromPage'][$attribute] = $this->comparePage->getCompareProductsBlock()->{'getProduct' . $attributeName}($key + 1, $value); } return $data; }
/** * Get assigned products. * * @param InjectableFixture $product * @return array */ protected function getAssignedProducts(InjectableFixture $product) { return $product->getDataFieldConfig('configurable_options')['source']->getProducts(); }
/** * Create data array for filling containers. * * Returns data in format * [[abstract_container_name => [field_name => [attribute_name => attribute_value, ..], ..], ..] * where container name should be set to 'null' if a field is not present on the form. * * @param InjectableFixture $fixture * @return array */ protected function getFixtureFieldsByContainers(InjectableFixture $fixture) { $dataByContainer = []; $data = $fixture->getData(); foreach ($data as $field => $value) { $attributes = $fixture->getDataFieldConfig($field); $attributes['value'] = $value; if (array_key_exists('group', $attributes) && $attributes['group'] != 'null') { $dataByContainer[$attributes['group']][$field] = $attributes; } elseif (!array_key_exists('group', $attributes)) { $this->unassignedFields[$field] = $attributes; } } return $dataByContainer; }
/** * Prepare config data. * * @param InjectableFixture $product * @return array */ protected function prepareConfig(InjectableFixture $product) { $config = $product->getDataConfig(); if ($product->hasData('attribute_set_id')) { $config['create_url_params']['set'] = $product->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getAttributeSetId(); } return $config; }
/** * Prepare catalog price rule. * * @param string $dataSet * @return CatalogRule */ protected function prepareCatalogPriceRule($dataSet) { $rule = $this->fixtureFactory->createByCode('catalogRule', ['dataSet' => $dataSet])->getData('rule'); if ($this->product->hasData('category_ids')) { $pattern = '[Category|is|%d]'; $category = $this->product->getDataFieldConfig('category_ids')['source']->getProductCategory(); $rule = sprintf($pattern, $category->getId()); } return $this->fixtureFactory->createByCode('catalogRule', ['dataSet' => $dataSet, 'data' => ['rule' => $rule]]); }
/** * Get fpt label. * * @param InjectableFixture $product * @return string */ protected function getFptLabel(InjectableFixture $product) { return $product->getDataFieldConfig('attribute_set_id')['source']->getAttributeSet()->getDataFieldConfig('assigned_attributes')['source']->getAttributes()[0]->getFrontendLabel(); }
/** * Get order items from rma fixture. * * @param InjectableFixture $fixture * @return array */ protected function getOrderItems(InjectableFixture $fixture) { /** @var OrderId $sourceOrderId */ $sourceOrderId = $fixture->getDataFieldConfig('order_id')['source']; return $sourceOrderId->getOrder()->getEntityId()['products']; }
/** * Create custom attribute. * * @param InjectableFixture $product * @param string $tabName * @return void */ protected function createCustomAttribute(InjectableFixture $product, $tabName = 'product-details') { $attribute = $product->getDataFieldConfig('custom_attribute')['source']->getAttribute(); $this->openTab('product-details'); if (!$this->checkAttributeLabel($attribute)) { /** @var \Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Tab\ProductDetails $tab */ $tab = $this->openTab($tabName); $tab->addNewAttribute($tabName); $this->getAttributeForm()->fill($attribute); } }
/** * Preparation of fixture data before comparing. * * @param InjectableFixture $productSearch * @return CatalogProductSimple */ protected function prepareFixture(InjectableFixture $productSearch) { $customAttribute = $productSearch->getDataFieldConfig('custom_attribute')['source']->getAttribute(); return $this->fixtureFactory->createByCode('catalogProductSimple', ['data' => ['custom_attribute' => $customAttribute]]); }
/** * Prepare categories for fill. * * @param InjectableFixture $product * @param CatalogCategory|null $category * @return array */ protected function prepareCategories(InjectableFixture $product, CatalogCategory $category = null) { return $category ? [$category] : ($product->hasData('category_ids') ? $product->getDataFieldConfig('category_ids')['source']->getCategories() : []); }