Skip to content
Snippets Groups Projects
Commit 0a63aa89 authored by Dmytro Aponasenko's avatar Dmytro Aponasenko
Browse files

Merge branch 'MTA-2478' of https://github.corp.magento.com/magento-qmt/magento2ce into develop

parents e9484459 f262b212
No related merge requests found
......@@ -62,11 +62,13 @@ class Content extends Tab
/**
* Clicking in content tab 'Insert Variable' button.
*
* @param SimpleElement $element [optional]
* @return void
*/
public function clickInsertVariable()
public function clickInsertVariable(SimpleElement $element = null)
{
$addVariableButton = $this->_rootElement->find($this->addVariableButton);
$context = $element === null ? $this->_rootElement : $element;
$addVariableButton = $context->find($this->addVariableButton);
if ($addVariableButton->isVisible()) {
$addVariableButton->click();
}
......@@ -75,11 +77,13 @@ class Content extends Tab
/**
* Clicking in content tab 'Insert Widget' button.
*
* @param SimpleElement $element [optional]
* @return void
*/
public function clickInsertWidget()
public function clickInsertWidget(SimpleElement $element = null)
{
$addWidgetButton = $this->_rootElement->find($this->addWidgetButton);
$context = $element === null ? $this->_rootElement : $element;
$addWidgetButton = $context->find($this->addWidgetButton);
if ($addWidgetButton->isVisible()) {
$addWidgetButton->click();
}
......
......@@ -25,14 +25,19 @@ class Content extends DataSource
*/
protected $fixtureFactory;
/**
* Repository factory.
*
* @var RepositoryFactory
*/
protected $repositoryFactory;
/**
* @constructor
* @param RepositoryFactory $repositoryFactory
* @param FixtureFactory $fixtureFactory
* @param array $params
* @param array $data
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function __construct(
RepositoryFactory $repositoryFactory,
......@@ -41,37 +46,62 @@ class Content extends DataSource
array $data = []
) {
$this->fixtureFactory = $fixtureFactory;
$this->repositoryFactory = $repositoryFactory;
$this->params = $params;
$this->data = $data;
if (isset($data['widget']['dataset']) && isset($this->params['repository'])) {
$this->data['widget']['dataset'] = $repositoryFactory->get($this->params['repository'])->get(
$data['widget']['dataset']
$this->prepareSourceData();
}
/**
* Prepare source data.
*
* @return void
*/
protected function prepareSourceData()
{
if (isset($this->data['widget']['dataset']) && isset($this->params['repository'])) {
$this->data['widget']['dataset'] = $this->repositoryFactory->get($this->params['repository'])->get(
$this->data['widget']['dataset']
);
foreach ($this->data['widget']['dataset'] as $key => $widget) {
if (isset($widget['chosen_option']['category_path'])
&& !isset($widget['chosen_option']['filter_sku'])
) {
$category = $this->createCategory($widget);
$categoryName = $category->getData('name');
$this->data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName;
}
if (isset($widget['chosen_option']['category_path']) && isset($widget['chosen_option']['filter_sku'])) {
$product = $this->createProduct($widget);
$categoryName = $product->getCategoryIds()[0]['name'];
$productSku = $product->getData('sku');
$this->data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName;
$this->data['widget']['dataset'][$key]['chosen_option']['filter_sku'] = $productSku;
}
if ($widget['widget_type'] == 'Catalog New Products List') {
$this->createProduct();
}
if ($widget['widget_type'] == 'CMS Static Block') {
$block = $this->createBlock($widget);
$blockIdentifier = $block->getIdentifier();
$this->data['widget']['dataset'][$key]['chosen_option']['filter_identifier'] = $blockIdentifier;
}
$this->data = array_merge($this->data, $this->prepareWidgetData($this->data['widget']));
}
}
/**
* Prepare widget data for the source.
*
* @param array $widgets
* @return array
*/
protected function prepareWidgetData(array $widgets)
{
$data = [];
foreach ($widgets['dataset'] as $key => $widget) {
if (isset($widget['chosen_option']['category_path'])
&& !isset($widget['chosen_option']['filter_sku'])
) {
$category = $this->createCategory($widget);
$categoryName = $category->getData('name');
$data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName;
}
if (isset($widget['chosen_option']['category_path']) && isset($widget['chosen_option']['filter_sku'])) {
$product = $this->createProduct($widget);
$categoryName = $product->getCategoryIds()[0]['name'];
$productSku = $product->getData('sku');
$data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName;
$data['widget']['dataset'][$key]['chosen_option']['filter_sku'] = $productSku;
}
if ($widget['widget_type'] == 'Catalog New Products List') {
$this->createProduct();
}
if ($widget['widget_type'] == 'CMS Static Block') {
$block = $this->createBlock($widget);
$blockIdentifier = $block->getIdentifier();
$data['widget']['dataset'][$key]['chosen_option']['filter_identifier'] = $blockIdentifier;
}
}
return $data;
}
/**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment