Skip to content

Commit 718d244

Browse files
committed
Merge remote-tracking branch 'origin/MC-32229' into 2.4-develop-pr17
2 parents f183416 + 7454729 commit 718d244

File tree

4 files changed

+155
-2
lines changed

4 files changed

+155
-2
lines changed

app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewActionHtml.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,40 @@ public function execute()
4747
if ($model instanceof AbstractCondition) {
4848
$model->setJsFormObject($formName);
4949
$model->setFormName($formName);
50+
$this->setJsFormObject($model);
5051
$html = $model->asHtmlRecursive();
5152
} else {
5253
$html = '';
5354
}
5455
$this->getResponse()
5556
->setBody($html);
5657
}
58+
59+
/**
60+
* Set jsFormObject for the model object
61+
*
62+
* @return void
63+
* @param AbstractCondition $model
64+
*/
65+
private function setJsFormObject(AbstractCondition $model): void
66+
{
67+
$requestJsFormName = $this->getRequest()->getParam('form');
68+
$actualJsFormName = $this->getJsFormObjectName($model->getFormName());
69+
if ($requestJsFormName === $actualJsFormName) { //new
70+
$model->setJsFormObject($actualJsFormName);
71+
} else { //edit
72+
$model->setJsFormObject($requestJsFormName);
73+
}
74+
}
75+
76+
/**
77+
* Get jsFormObject name
78+
*
79+
* @param string $formName
80+
* @return string
81+
*/
82+
private function getJsFormObjectName(string $formName): string
83+
{
84+
return $formName . 'rule_actions_fieldset_';
85+
}
5786
}

app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewConditionHtml.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
77

88
use Magento\Framework\App\Action\HttpPostActionInterface;
9+
use Magento\Rule\Model\Condition\AbstractCondition;
10+
use Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
911

1012
/**
1113
* Controller class NewConditionHtml. Returns condition html
1214
*/
13-
class NewConditionHtml extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote implements HttpPostActionInterface
15+
class NewConditionHtml extends Quote implements HttpPostActionInterface
1416
{
1517
/**
1618
* New condition html action
@@ -39,13 +41,40 @@ public function execute()
3941
$model->setAttribute($typeArr[1]);
4042
}
4143

42-
if ($model instanceof \Magento\Rule\Model\Condition\AbstractCondition) {
44+
if ($model instanceof AbstractCondition) {
4345
$model->setJsFormObject($this->getRequest()->getParam('form'));
4446
$model->setFormName($formName);
47+
$this->setJsFormObject($model);
4548
$html = $model->asHtmlRecursive();
4649
} else {
4750
$html = '';
4851
}
4952
$this->getResponse()->setBody($html);
5053
}
54+
55+
/**
56+
* Set jsFormObject for the model object
57+
*
58+
* @return void
59+
* @param AbstractCondition $model
60+
*/
61+
private function setJsFormObject(AbstractCondition $model): void
62+
{
63+
$requestJsFormName = $this->getRequest()->getParam('form');
64+
$actualJsFormName = $this->getJsFormObjectName($model->getFormName());
65+
if ($requestJsFormName === $actualJsFormName) { //new
66+
$model->setJsFormObject($actualJsFormName);
67+
}
68+
}
69+
70+
/**
71+
* Get jsFormObject name
72+
*
73+
* @param string $formName
74+
* @return string
75+
*/
76+
private function getJsFormObjectName(string $formName): string
77+
{
78+
return $formName . 'rule_conditions_fieldset_';
79+
}
5180
}

dev/tests/integration/testsuite/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/NewActionHtmlTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* New action html test
1414
*
15+
* Verify the request object contains the proper form object for action
1516
* @magentoAppArea adminhtml
1617
*/
1718
class NewActionHtmlTest extends AbstractBackendController
@@ -31,6 +32,11 @@ class NewActionHtmlTest extends AbstractBackendController
3132
*/
3233
private $formName = 'test_form';
3334

35+
/**
36+
* @var string
37+
*/
38+
private $requestFormName = 'rule_actions_fieldset_';
39+
3440
/**
3541
* Test verifies that execute method has the proper data-form-part value in html response
3642
*
@@ -73,6 +79,7 @@ private function prepareRequest(): void
7379
$this->getRequest()->setParams(
7480
[
7581
'id' => 1,
82+
'form' => $this->requestFormName,
7683
'form_namespace' => $this->formName,
7784
'type' => 'Magento\SalesRule\Model\Rule\Condition\Product|quote_item_price',
7885
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\SalesRule\Controller\Adminhtml\Promo\Quote;
9+
10+
use Magento\TestFramework\TestCase\AbstractBackendController;
11+
12+
/**
13+
* New condition html test
14+
*
15+
* Verify the request object contains the proper form object for condition
16+
* @magentoAppArea adminhtml
17+
*/
18+
class NewConditionHtmlTest extends AbstractBackendController
19+
{
20+
/**
21+
* @var string
22+
*/
23+
protected $resource = 'Magento_SalesRule::quote';
24+
25+
/**
26+
* @var string
27+
*/
28+
protected $uri = 'backend/sales_rule/promo_quote/newConditionHtml';
29+
30+
/**
31+
* @var string
32+
*/
33+
private $formName = 'test_form';
34+
35+
/**
36+
* @var string
37+
*/
38+
private $requestFormName = 'rule_conditions_fieldset_';
39+
40+
/**
41+
* Test verifies that execute method has the proper data-form-part value in html response
42+
*
43+
* @return void
44+
*/
45+
public function testExecute(): void
46+
{
47+
$this->prepareRequest();
48+
$this->dispatch($this->uri);
49+
$html = $this->getResponse()
50+
->getBody();
51+
$this->assertContains($this->formName, $html);
52+
}
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
public function testAclHasAccess()
58+
{
59+
$this->prepareRequest();
60+
parent::testAclHasAccess();
61+
}
62+
63+
/**
64+
* @inheritdoc
65+
*/
66+
public function testAclNoAccess()
67+
{
68+
$this->prepareRequest();
69+
parent::testAclNoAccess();
70+
}
71+
72+
/**
73+
* Prepare request
74+
*
75+
* @return void
76+
*/
77+
private function prepareRequest(): void
78+
{
79+
$this->getRequest()->setParams(
80+
[
81+
'id' => 1,
82+
'form' => $this->requestFormName,
83+
'form_namespace' => $this->formName,
84+
'type' => 'Magento\SalesRule\Model\Rule\Condition\Product|category_ids',
85+
]
86+
)->setMethod('POST');
87+
}
88+
}

0 commit comments

Comments
 (0)