Skip to content

Commit 4bf9910

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into PR_Branch
2 parents 60f5d47 + ff70f6e commit 4bf9910

File tree

6 files changed

+92
-21
lines changed

6 files changed

+92
-21
lines changed

app/code/Magento/Downloadable/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Downloadable.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function afterInitialize(
7777
if (!$linkData || (isset($linkData['is_delete']) && (bool)$linkData['is_delete'])) {
7878
continue;
7979
} else {
80-
unset($linkData['link_id']);
80+
//unset($linkData['link_id']);
8181
// TODO: need to implement setLinkFileContent()
8282
$link = $this->linkFactory->create(['data' => $linkData]);
8383
if (isset($linkData['type'])) {
@@ -89,7 +89,9 @@ public function afterInitialize(
8989
if (isset($linkData['file_content'])) {
9090
$link->setLinkFileContent($linkData['file_content']);
9191
}
92-
$link->setId(null);
92+
if (isset($linkData['link_id'])) {
93+
$link->setId($linkData['link_id']);
94+
}
9395
if (isset($linkData['sample']['type'])) {
9496
$link->setSampleType($linkData['sample']['type']);
9597
}
@@ -125,10 +127,11 @@ public function afterInitialize(
125127
if (!$sampleData || (isset($sampleData['is_delete']) && (bool)$sampleData['is_delete'])) {
126128
continue;
127129
} else {
128-
unset($sampleData['sample_id']);
129130
$sample = $this->sampleFactory->create(['data' => $sampleData]);
130-
$sample->setId(null);
131131
$sample->setStoreId($product->getStoreId());
132+
if (isset($sampleData['sample_id'])) {
133+
$sample->setId($sampleData['sample_id']);
134+
}
132135
if (isset($sampleData['type'])) {
133136
$sample->setSampleType($sampleData['type']);
134137
}

app/code/Magento/Downloadable/Model/Link/SaveHandler.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,26 @@ public function __construct(LinkRepository $linkRepository)
3636
*/
3737
public function execute($entityType, $entity, $arguments = [])
3838
{
39+
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
3940
if ($entity->getTypeId() !== 'downloadable') {
4041
return $entity;
4142
}
42-
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
43-
foreach ($this->linkRepository->getList($entity->getSku()) as $link) {
44-
$this->linkRepository->delete($link->getId());
45-
}
43+
44+
$oldLinks = $this->linkRepository->getList($entity->getSku());
4645
$links = $entity->getExtensionAttributes()->getDownloadableProductLinks() ?: [];
46+
$updatedLinkIds = [];
4747
foreach ($links as $link) {
48+
if ($link->getId()) {
49+
$updatedLinkIds[] = $link->getId();
50+
}
4851
$this->linkRepository->save($entity->getSku(), $link, !(bool)$entity->getStoreId());
4952
}
53+
foreach ($oldLinks as $link) {
54+
if (!in_array($link->getId(), $updatedLinkIds)) {
55+
$this->linkRepository->delete($link->getId());
56+
}
57+
}
58+
5059
return $entity;
5160
}
5261
}

app/code/Magento/Downloadable/Model/Sample/SaveHandler.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,22 @@ public function execute($entityType, $entity, $arguments = [])
3939
if ($entity->getTypeId() != \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
4040
return $entity;
4141
}
42-
/** @var \Magento\Catalog\Api\Data\ProductInterface $entity */
43-
foreach ($this->sampleRepository->getList($entity->getSku()) as $sample) {
44-
$this->sampleRepository->delete($sample->getId());
45-
}
42+
43+
$oldSamples = $this->sampleRepository->getList($entity->getSku());
4644
$samples = $entity->getExtensionAttributes()->getDownloadableProductSamples() ?: [];
45+
$updatedSampleIds = [];
4746
foreach ($samples as $sample) {
47+
if ($sample->getId()) {
48+
$updatedSampleIds[] = $sample->getId();
49+
}
4850
$this->sampleRepository->save($entity->getSku(), $sample, !(bool)$entity->getStoreId());
4951
}
52+
foreach ($oldSamples as $sample) {
53+
if (!in_array($sample->getId(), $updatedSampleIds)) {
54+
$this->sampleRepository->delete($sample->getId());
55+
}
56+
}
57+
5058
return $entity;
5159
}
5260
}

app/code/Magento/Payment/Model/Method/Cc.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ public function validate()
144144
'|8[6-9][0-9]{10}|9[0-9]{11})|62(2(12[6-9][0-9]{10}|1[3-9][0-9]{11}|[2-8][0-9]{12}' .
145145
'|9[0-1][0-9]{11}|92[0-5][0-9]{10})|[4-6][0-9]{13}|8[2-8][0-9]{12})|6(4[4-9][0-9]{13}' .
146146
'|5[0-9]{14}))$/',
147+
'MI' => '/^(5(0|[6-9])|63|67(?!59|6770|6774))\d*$/',
148+
'MD' => '/^(6759(?!24|38|40|6[3-9]|70|76)|676770|676774)\d*$/',
147149
];
148150

149151
$ccNumAndTypeMatches = isset(
@@ -213,6 +215,8 @@ public function getVerificationRegEx()
213215
'SO' => '/^[0-9]{3,4}$/',
214216
'OT' => '/^[0-9]{3,4}$/',
215217
'JCB' => '/^[0-9]{3,4}$/',
218+
'MI' => '/^[0-9]{3}$/',
219+
'MD' => '/^[0-9]{3}$/',
216220
];
217221
return $verificationExpList;
218222
}

app/code/Magento/Paypal/Model/Report/Settlement.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\Paypal\Model\Report;
1010

11+
use DateTime;
1112
use Magento\Framework\Filesystem;
1213
use Magento\Framework\Filesystem\DirectoryList;
1314

@@ -162,6 +163,13 @@ class Settlement extends \Magento\Framework\Model\AbstractModel
162163
*/
163164
protected $_scopeConfig;
164165

166+
/**
167+
* Columns with DateTime data type
168+
*
169+
* @var array
170+
*/
171+
private $dateTimeColumns = ['transaction_initiation_date', 'transaction_completion_date'];
172+
165173
/**
166174
* @param \Magento\Framework\Model\Context $context
167175
* @param \Magento\Framework\Registry $registry
@@ -249,7 +257,8 @@ public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection)
249257

250258
// Set last modified date, this value will be overwritten during parsing
251259
if (isset($attributes['mtime'])) {
252-
$lastModified = new \DateTime($attributes['mtime']);
260+
$date = new \DateTime();
261+
$lastModified = $date->setTimestamp($attributes['mtime']);
253262
$this->setReportLastModified(
254263
$lastModified->format('Y-m-d H:i:s')
255264
);
@@ -324,7 +333,7 @@ public function parseCsv($localCsv, $format = 'new')
324333
$rowMap = $this->_csvColumns[$format]['rowmap'];
325334

326335
$flippedSectionColumns = array_flip($sectionColumns);
327-
$stream = $this->_tmpDirectory->openFile($localCsv);
336+
$stream = $this->_tmpDirectory->openFile($localCsv, 'r');
328337
while ($line = $stream->readCsv()) {
329338
if (empty($line)) {
330339
// The line was empty, so skip it.
@@ -360,11 +369,7 @@ public function parseCsv($localCsv, $format = 'new')
360369
break;
361370
case 'SB':
362371
// Section body.
363-
$bodyItem = [];
364-
for ($i = 1; $i < count($line); $i++) {
365-
$bodyItem[$rowMap[$flippedSectionColumns[$i]]] = $line[$i];
366-
}
367-
$this->_rows[] = $bodyItem;
372+
$this->_rows[] = $this->getBodyItems($line, $flippedSectionColumns, $rowMap);
368373
break;
369374
case 'SC':
370375
// Section records count.
@@ -385,6 +390,41 @@ public function parseCsv($localCsv, $format = 'new')
385390
return $this;
386391
}
387392

393+
/**
394+
* Parse columns from line of csv file
395+
*
396+
* @param array $line
397+
* @param array $sectionColumns
398+
* @param array $rowMap
399+
* @return array
400+
*/
401+
private function getBodyItems(array $line, array $sectionColumns, array $rowMap)
402+
{
403+
$bodyItem = [];
404+
for ($i = 1, $count = count($line); $i < $count; $i++) {
405+
if(isset($rowMap[$sectionColumns[$i]])) {
406+
if (in_array($rowMap[$sectionColumns[$i]], $this->dateTimeColumns)) {
407+
$line[$i] = $this->formatDateTimeColumns($line[$i]);
408+
}
409+
$bodyItem[$rowMap[$sectionColumns[$i]]] = $line[$i];
410+
}
411+
}
412+
return $bodyItem;
413+
}
414+
415+
/**
416+
* Format date columns in UTC
417+
*
418+
* @param string $lineItem
419+
* @return string
420+
*/
421+
private function formatDateTimeColumns($lineItem)
422+
{
423+
/** @var DateTime $date */
424+
$date = new DateTime($lineItem, new \DateTimeZone('UTC'));
425+
return $date->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
426+
}
427+
388428
/**
389429
* Load report by unique key (accoutn + report date)
390430
*

app/code/Magento/Usps/Model/Carrier.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C
6767
*/
6868
protected $_code = self::CODE;
6969

70+
/**
71+
* Weight precision
72+
*
73+
* @var int
74+
*/
75+
private static $weightPrecision = 10;
76+
7077
/**
7178
* Rate request data
7279
*
@@ -324,7 +331,7 @@ public function setRequest(\Magento\Quote\Model\Quote\Address\RateRequest $reque
324331

325332
$weight = $this->getTotalNumOfBoxes($request->getPackageWeight());
326333
$r->setWeightPounds(floor($weight));
327-
$r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 1));
334+
$r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, self::$weightPrecision));
328335
if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
329336
$r->setFreeMethodWeight($request->getFreeMethodWeight());
330337
}
@@ -371,7 +378,7 @@ protected function _setFreeMethodRequest($freeMethod)
371378

372379
$weight = $this->getTotalNumOfBoxes($r->getFreeMethodWeight());
373380
$r->setWeightPounds(floor($weight));
374-
$r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 1));
381+
$r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, self::$weightPrecision));
375382
$r->setService($freeMethod);
376383
}
377384

0 commit comments

Comments
 (0)