Skip to content

Commit 1a08ff0

Browse files
committed
ACP2E-682: [Magento Cloud] - Add to cart button translation reverts back to English after clicking
- Fixed the solution part when deploy strategy mode is compact. - Added the test coverage based on the solution part.
1 parent 2ac6767 commit 1a08ff0

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

app/code/Magento/Translation/Model/Js/PreProcessor.php

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@
77

88
namespace Magento\Translation\Model\Js;
99

10+
use Magento\Deploy\Console\DeployStaticOptions;
1011
use Magento\Framework\App\AreaList;
1112
use Magento\Framework\TranslateInterface;
1213
use Magento\Framework\View\Asset\File\FallbackContext;
1314
use Magento\Framework\View\Asset\PreProcessor\Chain;
1415
use Magento\Framework\View\Asset\PreProcessorInterface;
16+
use Symfony\Component\Console\Input\ArgvInput;
17+
use Magento\Deploy\Strategy\DeployStrategyFactory;
1518

1619
/**
1720
* PreProcessor responsible for replacing translation calls in js files to translated strings
@@ -40,16 +43,27 @@ class PreProcessor implements PreProcessorInterface
4043
*/
4144
protected $areasThemesLocales = [];
4245

46+
/**
47+
* @var ArgvInput
48+
*/
49+
private $input;
50+
4351
/**
4452
* @param Config $config
4553
* @param AreaList $areaList
4654
* @param TranslateInterface $translate
55+
* @param ArgvInput $input
4756
*/
48-
public function __construct(Config $config, AreaList $areaList, TranslateInterface $translate)
49-
{
57+
public function __construct(
58+
Config $config,
59+
AreaList $areaList,
60+
TranslateInterface $translate,
61+
ArgvInput $input
62+
) {
5063
$this->config = $config;
5164
$this->areaList = $areaList;
5265
$this->translate = $translate;
66+
$this->input = $input;
5367
}
5468

5569
/**
@@ -74,7 +88,11 @@ public function process(Chain $chain)
7488
$area = $this->areaList->getArea($areaCode);
7589
$area->load(\Magento\Framework\App\Area::PART_TRANSLATE);
7690

77-
$chain->setContent($this->translate($chain->getContent()));
91+
if (!$this->isCheckStrategyCompact()) {
92+
$chain->setContent($this->translate($chain->getContent()));
93+
} else {
94+
$chain->setContent($chain->getContent());
95+
}
7896
}
7997
}
8098

@@ -120,4 +138,24 @@ public function loadTranslationDataBasedOnThemesAndLocales(FallbackContext $cont
120138
$this->translate->loadData($context->getAreaCode(), false);
121139
}
122140
}
141+
142+
/**
143+
* Check deploy argument strategy is compact.
144+
*
145+
* @return bool
146+
*/
147+
public function isCheckStrategyCompact(): bool
148+
{
149+
$isCompact = false;
150+
$isStrategy = $this->input->hasParameterOption('--' . DeployStaticOptions::STRATEGY) ||
151+
$this->input->hasParameterOption('-s');
152+
if ($isStrategy) {
153+
$strategyValue = $this->input->getParameterOption('--' . DeployStaticOptions::STRATEGY) ?:
154+
$this->input->getParameterOption('-s');
155+
if ($strategyValue === DeployStrategyFactory::DEPLOY_STRATEGY_COMPACT) {
156+
$isCompact = true;
157+
}
158+
}
159+
return $isCompact;
160+
}
123161
}

app/code/Magento/Translation/Test/Unit/Model/Js/PreProcessorTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\View\Asset\PreProcessor\Chain;
1616
use Magento\Translation\Model\Js\Config;
1717
use Magento\Translation\Model\Js\PreProcessor;
18+
use Symfony\Component\Console\Input\ArgvInput;
1819
use PHPUnit\Framework\TestCase;
1920

2021
class PreProcessorTest extends TestCase
@@ -39,6 +40,11 @@ class PreProcessorTest extends TestCase
3940
*/
4041
private $translateMock;
4142

43+
/**
44+
* @var ArgvInput|MockObject
45+
*/
46+
private $inputMock;
47+
4248
/**
4349
* @inheritdoc
4450
*/
@@ -47,10 +53,12 @@ protected function setUp(): void
4753
$this->configMock = $this->createMock(Config::class);
4854
$this->areaListMock = $this->createMock(AreaList::class);
4955
$this->translateMock = $this->getMockForAbstractClass(TranslateInterface::class);
56+
$this->inputMock = $this->createMock(ArgvInput::class);
5057
$this->model = new PreProcessor(
5158
$this->configMock,
5259
$this->areaListMock,
53-
$this->translateMock
60+
$this->translateMock,
61+
$this->inputMock
5462
);
5563
}
5664

@@ -93,14 +101,23 @@ public function testProcess()
93101
->method('loadData')
94102
->with($areaCode, false)
95103
->willReturnSelf();
104+
$this->translateMock->expects($this->any())
105+
->method('getData')
106+
->willReturn(['$t("Add to Cart")' => 'In Winkelwagen']);
96107
$area->expects($this->once())->method('load')->willReturnSelf();
108+
$this->inputMock->expects($this->once())
109+
->method('hasParameterOption')
110+
->willReturn(true);
111+
$this->inputMock->expects($this->once())
112+
->method('getParameterOption')
113+
->willReturn('quick');
97114
$this->areaListMock->expects($this->once())
98115
->method('getArea')
99116
->with($areaCode)
100117
->willReturn($area);
101118
$chain->expects($this->once())
102119
->method('getContent')
103-
->willReturn('$t("Add to Cart")');
120+
->willReturnMap([$this->translateMock]);
104121
$this->configMock->expects($this->any())
105122
->method('getPatterns')
106123
->willReturn(new \ArrayIterator(
@@ -109,6 +126,9 @@ public function testProcess()
109126
'~\$\.mage\.__\(([\'"])(.+?)\1\)~'
110127
],
111128
));
129+
$chain->expects($this->once())
130+
->method('setContent')
131+
->willReturn($this->translateMock);
112132
$this->model->process($chain);
113133
}
114134
}

0 commit comments

Comments
 (0)