Skip to content

Commit 688cd2b

Browse files
Merge pull request #1686 from magento-tango/PR-2.2.2-develop
Tasks - MAGETWO-80207 [2.2.x] - Modified Bundle.js because of breaking Encoding in Production - Mode. #10563 - MAGETWO-80188 [2.2.x] - Prevent change log entry when nothing has changed #4893 - MAGETWO-70323 [GITHUB] Can't add to cart Bundle product with simple product option price as "zero" #8969
2 parents 7648220 + 1ec4856 commit 688cd2b

File tree

6 files changed

+110
-37
lines changed

6 files changed

+110
-37
lines changed

app/code/Magento/Deploy/Package/Bundle/RequireJs.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,12 @@ private function endBundleFile(WriteInterface $bundleFile, array $contents)
240240
private function getFileContent($sourcePath)
241241
{
242242
if (!isset($this->fileContent[$sourcePath])) {
243-
$this->fileContent[$sourcePath] = utf8_encode(
244-
$this->staticDir->readFile($this->minification->addMinifiedSign($sourcePath))
245-
);
243+
$content = $this->staticDir->readFile($this->minification->addMinifiedSign($sourcePath));
244+
if (mb_detect_encoding($content) !== "UTF-8") {
245+
$content = mb_convert_encoding($content, "UTF-8");
246+
}
247+
248+
$this->fileContent[$sourcePath] = $content;
246249
}
247250
return $this->fileContent[$sourcePath];
248251
}

app/code/Magento/SalesRule/Model/Quote/Discount.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ protected function distributeDiscount(\Magento\Quote\Model\Quote\Item\AbstractIt
179179
$roundingDelta[$key] = 0.0000001;
180180
}
181181
foreach ($item->getChildren() as $child) {
182-
$ratio = $child->getBaseRowTotal() / $parentBaseRowTotal;
182+
$ratio = $parentBaseRowTotal != 0 ? $child->getBaseRowTotal() / $parentBaseRowTotal : 0;
183183
foreach ($keys as $key) {
184184
if (!$item->hasData($key)) {
185185
continue;

app/code/Magento/SalesRule/Test/Unit/Model/Quote/DiscountTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,30 @@ public function collectItemHasChildrenDataProvider()
229229
{
230230
$data = [
231231
// 3 items, each $100, testing that discount are distributed to item correctly
232-
'three_items' => [
232+
[
233+
'child_item_data' => [
234+
'item1' => [
235+
'base_row_total' => 0,
236+
]
237+
],
238+
'parent_item_data' => [
239+
'discount_amount' => 20,
240+
'base_discount_amount' => 10,
241+
'original_discount_amount' => 40,
242+
'base_original_discount_amount' => 20,
243+
'base_row_total' => 0,
244+
],
245+
'expected_child_item_data' => [
246+
'item1' => [
247+
'discount_amount' => 0,
248+
'base_discount_amount' => 0,
249+
'original_discount_amount' => 0,
250+
'base_original_discount_amount' => 0,
251+
]
252+
],
253+
],
254+
[
255+
// 3 items, each $100, testing that discount are distributed to item correctly
233256
'child_item_data' => [
234257
'item1' => [
235258
'base_row_total' => 100,

app/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,4 +1337,11 @@
13371337
<argument name="defaultExceptionMessageFactory" xsi:type="object">Magento\Framework\Message\ExceptionMessageFactory</argument>
13381338
</arguments>
13391339
</type>
1340+
<type name="Magento\Framework\Mview\View\Subscription">
1341+
<arguments>
1342+
<argument name="ignoredUpdateColumns" xsi:type="array">
1343+
<item name="updated_at" xsi:type="string">updated_at</item>
1344+
</argument>
1345+
</arguments>
1346+
</type>
13401347
</config>

lib/internal/Magento/Framework/Mview/View/Subscription.php

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
use Magento\Framework\App\ResourceConnection;
1212
use Magento\Framework\DB\Ddl\Trigger;
13+
use Magento\Framework\DB\Ddl\TriggerFactory;
14+
use Magento\Framework\Mview\ViewInterface;
1315

1416
class Subscription implements SubscriptionInterface
1517
{
@@ -21,12 +23,12 @@ class Subscription implements SubscriptionInterface
2123
protected $connection;
2224

2325
/**
24-
* @var \Magento\Framework\DB\Ddl\TriggerFactory
26+
* @var TriggerFactory
2527
*/
2628
protected $triggerFactory;
2729

2830
/**
29-
* @var \Magento\Framework\Mview\View\CollectionInterface
31+
* @var CollectionInterface
3032
*/
3133
protected $viewCollection;
3234

@@ -57,21 +59,31 @@ class Subscription implements SubscriptionInterface
5759
*/
5860
protected $resource;
5961

62+
/**
63+
* List of columns that can be updated in a subscribed table
64+
* without creating a new change log entry
65+
*
66+
* @var array
67+
*/
68+
private $ignoredUpdateColumns = [];
69+
6070
/**
6171
* @param ResourceConnection $resource
62-
* @param \Magento\Framework\DB\Ddl\TriggerFactory $triggerFactory
63-
* @param \Magento\Framework\Mview\View\CollectionInterface $viewCollection
64-
* @param \Magento\Framework\Mview\ViewInterface $view
72+
* @param TriggerFactory $triggerFactory
73+
* @param CollectionInterface $viewCollection
74+
* @param ViewInterface $view
6575
* @param string $tableName
6676
* @param string $columnName
77+
* @param array $ignoredUpdateColumns
6778
*/
6879
public function __construct(
6980
ResourceConnection $resource,
70-
\Magento\Framework\DB\Ddl\TriggerFactory $triggerFactory,
71-
\Magento\Framework\Mview\View\CollectionInterface $viewCollection,
72-
\Magento\Framework\Mview\ViewInterface $view,
81+
TriggerFactory $triggerFactory,
82+
CollectionInterface $viewCollection,
83+
ViewInterface $view,
7384
$tableName,
74-
$columnName
85+
$columnName,
86+
array $ignoredUpdateColumns = []
7587
) {
7688
$this->connection = $resource->getConnection();
7789
$this->triggerFactory = $triggerFactory;
@@ -80,12 +92,13 @@ public function __construct(
8092
$this->tableName = $tableName;
8193
$this->columnName = $columnName;
8294
$this->resource = $resource;
95+
$this->ignoredUpdateColumns = $ignoredUpdateColumns;
8396
}
8497

8598
/**
86-
* Create subsciption
99+
* Create subscription
87100
*
88-
* @return \Magento\Framework\Mview\View\SubscriptionInterface
101+
* @return SubscriptionInterface
89102
*/
90103
public function create()
91104
{
@@ -102,7 +115,7 @@ public function create()
102115

103116
// Add statements for linked views
104117
foreach ($this->getLinkedViews() as $view) {
105-
/** @var \Magento\Framework\Mview\ViewInterface $view */
118+
/** @var ViewInterface $view */
106119
$trigger->addStatement($this->buildStatement($event, $view->getChangelog()));
107120
}
108121

@@ -116,7 +129,7 @@ public function create()
116129
/**
117130
* Remove subscription
118131
*
119-
* @return \Magento\Framework\Mview\View\SubscriptionInterface
132+
* @return SubscriptionInterface
120133
*/
121134
public function remove()
122135
{
@@ -131,7 +144,7 @@ public function remove()
131144

132145
// Add statements for linked views
133146
foreach ($this->getLinkedViews() as $view) {
134-
/** @var \Magento\Framework\Mview\ViewInterface $view */
147+
/** @var ViewInterface $view */
135148
$trigger->addStatement($this->buildStatement($event, $view->getChangelog()));
136149
}
137150

@@ -154,10 +167,10 @@ public function remove()
154167
protected function getLinkedViews()
155168
{
156169
if (!$this->linkedViews) {
157-
$viewList = $this->viewCollection->getViewsByStateMode(\Magento\Framework\Mview\View\StateInterface::MODE_ENABLED);
170+
$viewList = $this->viewCollection->getViewsByStateMode(StateInterface::MODE_ENABLED);
158171

159172
foreach ($viewList as $view) {
160-
/** @var \Magento\Framework\Mview\ViewInterface $view */
173+
/** @var ViewInterface $view */
161174
// Skip the current view
162175
if ($view->getId() == $this->getView()->getId()) {
163176
continue;
@@ -175,35 +188,58 @@ protected function getLinkedViews()
175188
}
176189

177190
/**
178-
* Build trigger statement for INSER, UPDATE, DELETE events
191+
* Build trigger statement for INSERT, UPDATE, DELETE events
179192
*
180193
* @param string $event
181-
* @param \Magento\Framework\Mview\View\ChangelogInterface $changelog
194+
* @param ChangelogInterface $changelog
182195
* @return string
183196
*/
184197
protected function buildStatement($event, $changelog)
185198
{
186199
switch ($event) {
187200
case Trigger::EVENT_INSERT:
201+
$trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);";
202+
break;
203+
188204
case Trigger::EVENT_UPDATE:
189-
return sprintf(
190-
"INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);",
191-
$this->connection->quoteIdentifier($this->resource->getTableName($changelog->getName())),
192-
$this->connection->quoteIdentifier($changelog->getColumnName()),
193-
$this->connection->quoteIdentifier($this->getColumnName())
194-
);
205+
$trigger = "INSERT IGNORE INTO %s (%s) VALUES (NEW.%s);";
206+
207+
if ($this->connection->isTableExists($this->getTableName())
208+
&& $describe = $this->connection->describeTable($this->getTableName())
209+
) {
210+
$columnNames = array_column($describe, 'COLUMN_NAME');
211+
$columnNames = array_diff($columnNames, $this->ignoredUpdateColumns);
212+
if ($columnNames) {
213+
$columns = [];
214+
foreach ($columnNames as $columnName) {
215+
$columns[] = sprintf(
216+
'NEW.%1$s != OLD.%1$s',
217+
$this->connection->quoteIdentifier($columnName)
218+
);
219+
}
220+
$trigger = sprintf(
221+
"IF (%s) THEN %s END IF;",
222+
implode(' OR ', $columns),
223+
$trigger
224+
);
225+
}
226+
}
227+
break;
195228

196229
case Trigger::EVENT_DELETE:
197-
return sprintf(
198-
"INSERT IGNORE INTO %s (%s) VALUES (OLD.%s);",
199-
$this->connection->quoteIdentifier($this->resource->getTableName($changelog->getName())),
200-
$this->connection->quoteIdentifier($changelog->getColumnName()),
201-
$this->connection->quoteIdentifier($this->getColumnName())
202-
);
230+
$trigger = "INSERT IGNORE INTO %s (%s) VALUES (OLD.%s);";
231+
break;
203232

204233
default:
205234
return '';
206235
}
236+
237+
return sprintf(
238+
$trigger,
239+
$this->connection->quoteIdentifier($this->resource->getTableName($changelog->getName())),
240+
$this->connection->quoteIdentifier($changelog->getColumnName()),
241+
$this->connection->quoteIdentifier($this->getColumnName())
242+
);
207243
}
208244

209245
/**
@@ -225,7 +261,7 @@ private function getAfterEventTriggerName($event)
225261
/**
226262
* Retrieve View related to subscription
227263
*
228-
* @return \Magento\Framework\Mview\ViewInterface
264+
* @return ViewInterface
229265
* @codeCoverageIgnore
230266
*/
231267
public function getView()

lib/internal/Magento/Framework/View/Asset/Bundle.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ protected function getAssetContent(LocalInterface $asset)
212212
$assetContentType = $asset->getContentType();
213213
$assetKey = $this->getAssetKey($asset);
214214
if (!isset($this->assetsContent[$assetContextCode][$assetContentType][$assetKey])) {
215-
$this->assetsContent[$assetContextCode][$assetContentType][$assetKey] = utf8_encode($asset->getContent());
215+
$content = $asset->getContent();
216+
if (mb_detect_encoding($content) !== "UTF-8") {
217+
$content = mb_convert_encoding($content, "UTF-8");
218+
}
219+
$this->assetsContent[$assetContextCode][$assetContentType][$assetKey] = $content;
216220
}
217221

218222
return $this->assetsContent[$assetContextCode][$assetContentType][$assetKey];

0 commit comments

Comments
 (0)