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

MTA-2494: Update widget adding to the CMS page content

parent cfb2937c
Branches
No related merge requests found
...@@ -62,11 +62,13 @@ class Content extends Tab ...@@ -62,11 +62,13 @@ class Content extends Tab
/** /**
* Clicking in content tab 'Insert Variable' button. * Clicking in content tab 'Insert Variable' button.
* *
* @param SimpleElement $element [optional]
* @return void * @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()) { if ($addVariableButton->isVisible()) {
$addVariableButton->click(); $addVariableButton->click();
} }
...@@ -75,11 +77,13 @@ class Content extends Tab ...@@ -75,11 +77,13 @@ class Content extends Tab
/** /**
* Clicking in content tab 'Insert Frontend App' button. * Clicking in content tab 'Insert Frontend App' button.
* *
* @param SimpleElement $element [optional]
* @return void * @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()) { if ($addWidgetButton->isVisible()) {
$addWidgetButton->click(); $addWidgetButton->click();
} }
......
...@@ -25,14 +25,19 @@ class Content extends DataSource ...@@ -25,14 +25,19 @@ class Content extends DataSource
*/ */
protected $fixtureFactory; protected $fixtureFactory;
/**
* Repository factory.
*
* @var RepositoryFactory
*/
protected $repositoryFactory;
/** /**
* @constructor * @constructor
* @param RepositoryFactory $repositoryFactory * @param RepositoryFactory $repositoryFactory
* @param FixtureFactory $fixtureFactory * @param FixtureFactory $fixtureFactory
* @param array $params * @param array $params
* @param array $data * @param array $data
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/ */
public function __construct( public function __construct(
RepositoryFactory $repositoryFactory, RepositoryFactory $repositoryFactory,
...@@ -41,37 +46,62 @@ class Content extends DataSource ...@@ -41,37 +46,62 @@ class Content extends DataSource
array $data = [] array $data = []
) { ) {
$this->fixtureFactory = $fixtureFactory; $this->fixtureFactory = $fixtureFactory;
$this->repositoryFactory = $repositoryFactory;
$this->params = $params; $this->params = $params;
$this->data = $data; $this->data = $data;
if (isset($data['widget']['dataset']) && isset($this->params['repository'])) { $this->prepareSourceData();
$this->data['widget']['dataset'] = $repositoryFactory->get($this->params['repository'])->get( }
$data['widget']['dataset']
/**
* 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) { $this->data = array_merge($this->data, $this->prepareWidgetData($this->data['widget']));
if (isset($widget['chosen_option']['category_path']) }
&& !isset($widget['chosen_option']['filter_sku']) }
) {
$category = $this->createCategory($widget); /**
$categoryName = $category->getData('name'); * Prepare widget data for the source.
$this->data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName; *
} * @param array $widgets
if (isset($widget['chosen_option']['category_path']) && isset($widget['chosen_option']['filter_sku'])) { * @return array
$product = $this->createProduct($widget); */
$categoryName = $product->getCategoryIds()[0]['name']; protected function prepareWidgetData(array $widgets)
$productSku = $product->getData('sku'); {
$this->data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName; $data = [];
$this->data['widget']['dataset'][$key]['chosen_option']['filter_sku'] = $productSku; foreach ($widgets['dataset'] as $key => $widget) {
} if (isset($widget['chosen_option']['category_path'])
if ($widget['widget_type'] == 'Catalog New Products List') { && !isset($widget['chosen_option']['filter_sku'])
$this->createProduct(); ) {
} $category = $this->createCategory($widget);
if ($widget['widget_type'] == 'CMS Static Block') { $categoryName = $category->getData('name');
$block = $this->createBlock($widget); $data['widget']['dataset'][$key]['chosen_option']['category_path'] = $categoryName;
$blockIdentifier = $block->getIdentifier(); }
$this->data['widget']['dataset'][$key]['chosen_option']['filter_identifier'] = $blockIdentifier; 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