Skip to content

Commit 03ec736

Browse files
committed
Merge pull request #336 from magento-folks/catalog-promo-form-refactoring
[Folks] Catalog promo form refactoring and Bugfixing
2 parents c0fc5b2 + a05025d commit 03ec736

File tree

58 files changed

+1881
-791
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1881
-791
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogRule\Api\Data;
7+
8+
/**
9+
* @api
10+
*/
11+
interface ConditionInterface extends \Magento\Framework\Api\CustomAttributesDataInterface
12+
{
13+
/**#@+
14+
* Constants defined for keys of data array
15+
*/
16+
const TYPE = 'type';
17+
18+
const ATTRIBUTE = 'attribute';
19+
20+
const OPERATOR = 'operator';
21+
22+
const VALUE = 'value';
23+
24+
const IS_VALUE_PARSED = 'is_value_parsed';
25+
26+
const AGGREGATOR = 'aggregator';
27+
28+
const CONDITIONS = 'conditions';
29+
/**#@-*/
30+
31+
/**
32+
* @param string $type
33+
* @return $this
34+
*/
35+
public function setType($type);
36+
37+
/**
38+
* @return string
39+
*/
40+
public function getType();
41+
42+
/**
43+
* @param string $attribute
44+
* @return $this
45+
*/
46+
public function setAttribute($attribute);
47+
48+
/**
49+
* @return string
50+
*/
51+
public function getAttribute();
52+
53+
/**
54+
* @param string $operator
55+
* @return $this
56+
*/
57+
public function setOperator($operator);
58+
59+
/**
60+
* @return string
61+
*/
62+
public function getOperator();
63+
64+
/**
65+
* @param string $value
66+
* @return $this
67+
*/
68+
public function setValue($value);
69+
70+
/**
71+
* @return string
72+
*/
73+
public function getValue();
74+
75+
/**
76+
* @param bool $isValueParsed
77+
* @return $this
78+
*/
79+
public function setIsValueParsed($isValueParsed);
80+
81+
/**
82+
* @return bool|null
83+
* @SuppressWarnings(PHPMD.BooleanGetMethodName)
84+
*/
85+
public function getIsValueParsed();
86+
87+
/**
88+
* @param string $aggregator
89+
* @return $this
90+
*/
91+
public function setAggregator($aggregator);
92+
93+
/**
94+
* @return string
95+
*/
96+
public function getAggregator();
97+
98+
/**
99+
* @param \Magento\CatalogRule\Api\Data\ConditionInterface[] $conditions
100+
* @return $this
101+
*/
102+
public function setConditions($conditions);
103+
104+
/**
105+
* @return \Magento\CatalogRule\Api\Data\ConditionInterface[]|null
106+
*/
107+
public function getConditions();
108+
109+
/**
110+
* Retrieve existing extension attributes object or create a new one.
111+
*
112+
* @return \Magento\CatalogRule\Api\Data\ConditionExtensionInterface|null
113+
*/
114+
public function getExtensionAttributes();
115+
116+
/**
117+
* Set an extension attributes object.
118+
*
119+
* @param \Magento\CatalogRule\Api\Data\ConditionExtensionInterface $extensionAttributes
120+
* @return $this
121+
*/
122+
public function setExtensionAttributes(
123+
\Magento\CatalogRule\Api\Data\ConditionExtensionInterface $extensionAttributes
124+
);
125+
}

app/code/Magento/CatalogRule/Api/Data/RuleInterface.php

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ interface RuleInterface extends \Magento\Framework\Api\CustomAttributesDataInter
2121

2222
const IS_ACTIVE = 'is_active';
2323

24-
const CONDITIONS_SERIALIZED = 'conditions_serialized';
25-
26-
const ACTIONS_SERIALIZED = 'actions_serialized';
27-
2824
const STOP_RULES_PROCESSING = 'stop_rules_processing';
2925

3026
const SORT_ORDER = 'sort_order';
@@ -38,7 +34,7 @@ interface RuleInterface extends \Magento\Framework\Api\CustomAttributesDataInter
3834
/**
3935
* Returns rule id field
4036
*
41-
* @return int
37+
* @return int|null
4238
*/
4339
public function getRuleId();
4440

@@ -64,7 +60,7 @@ public function setName($name);
6460
/**
6561
* Returns rule description
6662
*
67-
* @return string
63+
* @return string|null
6864
*/
6965
public function getDescription();
7066

@@ -88,35 +84,22 @@ public function getIsActive();
8884
public function setIsActive($isActive);
8985

9086
/**
91-
* Returns serialized rule condition
92-
*
93-
* @return string
94-
*/
95-
public function getConditionsSerialized();
96-
97-
/**
98-
* @param string $conditions
99-
* @return $this
100-
*/
101-
public function setConditionsSerialized($conditions);
102-
103-
/**
104-
* Returns serialized rule actions
87+
* Returns rule condition
10588
*
106-
* @return string
89+
* @return \Magento\CatalogRule\Api\Data\ConditionInterface|null
10790
*/
108-
public function getActionsSerialized();
91+
public function getRuleCondition();
10992

11093
/**
111-
* @param string $actions
94+
* @param \Magento\CatalogRule\Api\Data\ConditionInterface $condition
11295
* @return $this
11396
*/
114-
public function setActionsSerialized($actions);
97+
public function setRuleCondition($condition);
11598

11699
/**
117100
* Returns stop rule processing flag
118101
*
119-
* @return int
102+
* @return int|null
120103
*/
121104
public function getStopRulesProcessing();
122105

@@ -129,7 +112,7 @@ public function setStopRulesProcessing($isStopProcessing);
129112
/**
130113
* Returns rule sort order
131114
*
132-
* @return int
115+
* @return int|null
133116
*/
134117
public function getSortOrder();
135118

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\CatalogRule\Block\Adminhtml\Edit;
7+
8+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
9+
10+
/**
11+
* Class DeleteButton
12+
*/
13+
class DeleteButton extends GenericButton implements ButtonProviderInterface
14+
{
15+
/**
16+
* @return array
17+
*/
18+
public function getButtonData()
19+
{
20+
$data = [];
21+
$ruleId = $this->getRuleId();
22+
if ($ruleId && $this->canRender('delete')) {
23+
$data = [
24+
'label' => __('Delete Rule'),
25+
'class' => 'delete',
26+
'on_click' => 'deleteConfirm(\'' . __(
27+
'Are you sure you want to do this?'
28+
) . '\', \'' . $this->urlBuilder->getUrl('*/*/delete', ['id' => $ruleId]) . '\')',
29+
'sort_order' => 20,
30+
];
31+
}
32+
return $data;
33+
}
34+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogRule\Block\Adminhtml\Edit;
8+
9+
use Magento\CatalogRule\Controller\RegistryConstants;
10+
11+
class GenericButton
12+
{
13+
/**
14+
* Url Builder
15+
*
16+
* @var \Magento\Framework\UrlInterface
17+
*/
18+
protected $urlBuilder;
19+
20+
/**
21+
* Registry
22+
*
23+
* @var \Magento\Framework\Registry
24+
*/
25+
protected $registry;
26+
27+
/**
28+
* Constructor
29+
*
30+
* @param \Magento\Backend\Block\Widget\Context $context
31+
* @param \Magento\Framework\Registry $registry
32+
*/
33+
public function __construct(
34+
\Magento\Backend\Block\Widget\Context $context,
35+
\Magento\Framework\Registry $registry
36+
) {
37+
$this->urlBuilder = $context->getUrlBuilder();
38+
$this->registry = $registry;
39+
}
40+
41+
/**
42+
* Return the current Catalog Rule Id.
43+
*
44+
* @return int|null
45+
*/
46+
public function getRuleId()
47+
{
48+
$catalogRule = $this->registry->registry(RegistryConstants::CURRENT_CATALOG_RULE_ID);
49+
return $catalogRule ? $catalogRule->getId() : null;
50+
}
51+
52+
/**
53+
* Generate url by route and parameters
54+
*
55+
* @param string $route
56+
* @param array $params
57+
* @return string
58+
*/
59+
public function getUrl($route = '', $params = [])
60+
{
61+
return $this->urlBuilder->getUrl($route, $params);
62+
}
63+
64+
/**
65+
* Check where button can be rendered
66+
*
67+
* @param string $name
68+
* @return string
69+
*/
70+
public function canRender($name)
71+
{
72+
return $name;
73+
}
74+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogRule\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
class ResetButton extends GenericButton implements ButtonProviderInterface
12+
{
13+
/**
14+
* @return array
15+
* @codeCoverageIgnore
16+
*/
17+
public function getButtonData()
18+
{
19+
$data = [];
20+
if ($this->canRender('reset')) {
21+
$data = [
22+
'label' => __('Reset'),
23+
'class' => 'reset',
24+
'on_click' => 'location.reload();',
25+
'sort_order' => 30,
26+
];
27+
}
28+
return $data;
29+
}
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogRule\Block\Adminhtml\Edit;
8+
9+
use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
10+
11+
class SaveAndApplyButton extends GenericButton implements ButtonProviderInterface
12+
{
13+
/**
14+
* @return array
15+
* @codeCoverageIgnore
16+
*/
17+
public function getButtonData()
18+
{
19+
$data = [];
20+
if ($this->canRender('save_apply')) {
21+
$data = [
22+
'label' => __('Save and Apply'),
23+
'class' => 'save',
24+
'on_click' => '',
25+
'sort_order' => 80,
26+
];
27+
}
28+
return $data;
29+
}
30+
}

0 commit comments

Comments
 (0)