From 785a895e72eafc95ac511ee73b470a368e0eb8b2 Mon Sep 17 00:00:00 2001 From: rliukshyn Date: Mon, 11 Apr 2016 15:12:57 +0000 Subject: [PATCH 1/8] MAGETWO-51789: Paypal Settlement report cannot be generated --- .../Paypal/Model/Report/Settlement.php | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Report/Settlement.php b/app/code/Magento/Paypal/Model/Report/Settlement.php index 96f60664caaa9..47fd581c980a1 100644 --- a/app/code/Magento/Paypal/Model/Report/Settlement.php +++ b/app/code/Magento/Paypal/Model/Report/Settlement.php @@ -8,6 +8,7 @@ namespace Magento\Paypal\Model\Report; +use DateTime; use Magento\Framework\Filesystem; use Magento\Framework\Filesystem\DirectoryList; @@ -249,7 +250,8 @@ public function fetchAndSave(\Magento\Framework\Filesystem\Io\Sftp $connection) // Set last modified date, this value will be overwritten during parsing if (isset($attributes['mtime'])) { - $lastModified = new \DateTime($attributes['mtime']); + $date = new \DateTime(); + $lastModified = $date->setTimestamp($attributes['mtime']); $this->setReportLastModified( $lastModified->format('Y-m-d H:i:s') ); @@ -324,7 +326,7 @@ public function parseCsv($localCsv, $format = 'new') $rowMap = $this->_csvColumns[$format]['rowmap']; $flippedSectionColumns = array_flip($sectionColumns); - $stream = $this->_tmpDirectory->openFile($localCsv); + $stream = $this->_tmpDirectory->openFile($localCsv, 'r'); while ($line = $stream->readCsv()) { if (empty($line)) { // The line was empty, so skip it. @@ -360,11 +362,7 @@ public function parseCsv($localCsv, $format = 'new') break; case 'SB': // Section body. - $bodyItem = []; - for ($i = 1; $i < count($line); $i++) { - $bodyItem[$rowMap[$flippedSectionColumns[$i]]] = $line[$i]; - } - $this->_rows[] = $bodyItem; + $this->_rows[] = $this->getBodyItems($line, $flippedSectionColumns, $rowMap); break; case 'SC': // Section records count. @@ -385,6 +383,42 @@ public function parseCsv($localCsv, $format = 'new') return $this; } + /** + * Parse columns from line of csv file + * + * @param array $line + * @param array $sectionColumns + * @param array $rowMap + * @return array + */ + private function getBodyItems(array $line, array $sectionColumns, array $rowMap) + { + $bodyItem = []; + for ($i = 1, $count = count($line); $i < $count; $i++) { + if(isset($rowMap[$sectionColumns[$i]])) { + $dateTimeColumns = ['transaction_initiation_date', 'transaction_completion_date']; + if (in_array($rowMap[$sectionColumns[$i]], $dateTimeColumns)) { + $line[$i] = $this->formatDateTimeColumns($line[$i]); + } + $bodyItem[$rowMap[$sectionColumns[$i]]] = $line[$i]; + } + } + return $bodyItem; + } + + /** + * Format date columns in UTC + * + * @param string $lineItem + * @return string + */ + private function formatDateTimeColumns($lineItem) + { + /** @var DateTime $date */ + $date = new DateTime($lineItem, new \DateTimeZone('UTC')); + return $date->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT); + } + /** * Load report by unique key (accoutn + report date) * From ebc3cb7e0fcf376d94fb82677673351e7372c215 Mon Sep 17 00:00:00 2001 From: rliukshyn Date: Mon, 11 Apr 2016 16:09:38 +0000 Subject: [PATCH 2/8] MAGETWO-51789: Paypal Settlement report cannot be generated - CR Changes --- app/code/Magento/Paypal/Model/Report/Settlement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Paypal/Model/Report/Settlement.php b/app/code/Magento/Paypal/Model/Report/Settlement.php index 47fd581c980a1..ecf84475d762a 100644 --- a/app/code/Magento/Paypal/Model/Report/Settlement.php +++ b/app/code/Magento/Paypal/Model/Report/Settlement.php @@ -394,9 +394,9 @@ public function parseCsv($localCsv, $format = 'new') private function getBodyItems(array $line, array $sectionColumns, array $rowMap) { $bodyItem = []; + $dateTimeColumns = ['transaction_initiation_date', 'transaction_completion_date']; for ($i = 1, $count = count($line); $i < $count; $i++) { if(isset($rowMap[$sectionColumns[$i]])) { - $dateTimeColumns = ['transaction_initiation_date', 'transaction_completion_date']; if (in_array($rowMap[$sectionColumns[$i]], $dateTimeColumns)) { $line[$i] = $this->formatDateTimeColumns($line[$i]); } From 6a81d001e0008d00aa25ee5942fdb4aabf16b777 Mon Sep 17 00:00:00 2001 From: Roman Liukshyn Date: Tue, 12 Apr 2016 08:50:12 +0000 Subject: [PATCH 3/8] MAGETWO-51789: Paypal Settlement report cannot be generated - CR Changes --- app/code/Magento/Paypal/Model/Report/Settlement.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Paypal/Model/Report/Settlement.php b/app/code/Magento/Paypal/Model/Report/Settlement.php index ecf84475d762a..e1d2c482e2c6b 100644 --- a/app/code/Magento/Paypal/Model/Report/Settlement.php +++ b/app/code/Magento/Paypal/Model/Report/Settlement.php @@ -163,6 +163,13 @@ class Settlement extends \Magento\Framework\Model\AbstractModel */ protected $_scopeConfig; + /** + * Columns with DateTime data type + * + * @var array + */ + private $dateTimeColumns = ['transaction_initiation_date', 'transaction_completion_date']; + /** * @param \Magento\Framework\Model\Context $context * @param \Magento\Framework\Registry $registry @@ -394,10 +401,9 @@ public function parseCsv($localCsv, $format = 'new') private function getBodyItems(array $line, array $sectionColumns, array $rowMap) { $bodyItem = []; - $dateTimeColumns = ['transaction_initiation_date', 'transaction_completion_date']; for ($i = 1, $count = count($line); $i < $count; $i++) { if(isset($rowMap[$sectionColumns[$i]])) { - if (in_array($rowMap[$sectionColumns[$i]], $dateTimeColumns)) { + if (in_array($rowMap[$sectionColumns[$i]], $this->dateTimeColumns)) { $line[$i] = $this->formatDateTimeColumns($line[$i]); } $bodyItem[$rowMap[$sectionColumns[$i]]] = $line[$i]; From d2c05b3a8fdf3be631e9974dd81505730e5a1ae3 Mon Sep 17 00:00:00 2001 From: "Shmyheliuk, Oleksandr" Date: Tue, 12 Apr 2016 16:31:26 +0300 Subject: [PATCH 4/8] MAGETWO-51834: Maestro credit cards doesn't pass validation on server side --- app/code/Magento/Payment/Model/Method/Cc.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Payment/Model/Method/Cc.php b/app/code/Magento/Payment/Model/Method/Cc.php index 73479d2e05931..e9f0bbb991e80 100644 --- a/app/code/Magento/Payment/Model/Method/Cc.php +++ b/app/code/Magento/Payment/Model/Method/Cc.php @@ -144,6 +144,8 @@ public function validate() '|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}' . '|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}' . '|5[0-9]{14}))$/', + 'MI' => '/^(5(0|[6-9])|63|67(?!59|6770|6774))\d*$/', + 'MD' => '/^6759(?!24|38|40|6[3-9]|70|76)|676770|676774\d*$/', ]; $ccNumAndTypeMatches = isset( @@ -213,6 +215,8 @@ public function getVerificationRegEx() 'SO' => '/^[0-9]{3,4}$/', 'OT' => '/^[0-9]{3,4}$/', 'JCB' => '/^[0-9]{3,4}$/', + 'MI' => '/^[0-9]{3}$/', + 'MD' => '/^[0-9]{3}$/', ]; return $verificationExpList; } From 6958587dc1bf64718b68d5c0c252f188d0e56e4d Mon Sep 17 00:00:00 2001 From: "Shmyheliuk, Oleksandr" Date: Tue, 12 Apr 2016 16:37:33 +0300 Subject: [PATCH 5/8] MAGETWO-51834: Maestro credit cards doesn't pass validation on server side --- app/code/Magento/Payment/Model/Method/Cc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Payment/Model/Method/Cc.php b/app/code/Magento/Payment/Model/Method/Cc.php index e9f0bbb991e80..1c6aba88d2118 100644 --- a/app/code/Magento/Payment/Model/Method/Cc.php +++ b/app/code/Magento/Payment/Model/Method/Cc.php @@ -145,7 +145,7 @@ public function validate() '|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}' . '|5[0-9]{14}))$/', 'MI' => '/^(5(0|[6-9])|63|67(?!59|6770|6774))\d*$/', - 'MD' => '/^6759(?!24|38|40|6[3-9]|70|76)|676770|676774\d*$/', + 'MD' => '/^(6759(?!24|38|40|6[3-9]|70|76)|676770|676774)\d*$/', ]; $ccNumAndTypeMatches = isset( From 16dfe94d00117998a6811f34b0d757ea99e7d903 Mon Sep 17 00:00:00 2001 From: Viktor Tymchynskyi Date: Wed, 13 Apr 2016 15:04:44 +0300 Subject: [PATCH 6/8] MAGETWO-50828: Downloadable product links title lost value on global level after edit on store view level - Back processing by id for Link and Sample items --- .../Helper/Plugin/Downloadable.php | 11 +++++++---- .../Downloadable/Model/Link/SaveHandler.php | 17 +++++++++++++---- .../Downloadable/Model/Sample/SaveHandler.php | 16 ++++++++++++---- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/app/code/Magento/Downloadable/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Downloadable.php b/app/code/Magento/Downloadable/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Downloadable.php index b5c4b026c666b..fb082457504b9 100644 --- a/app/code/Magento/Downloadable/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Downloadable.php +++ b/app/code/Magento/Downloadable/Controller/Adminhtml/Product/Initialization/Helper/Plugin/Downloadable.php @@ -77,7 +77,7 @@ public function afterInitialize( if (!$linkData || (isset($linkData['is_delete']) && (bool)$linkData['is_delete'])) { continue; } else { - unset($linkData['link_id']); + //unset($linkData['link_id']); // TODO: need to implement setLinkFileContent() $link = $this->linkFactory->create(['data' => $linkData]); if (isset($linkData['type'])) { @@ -89,7 +89,9 @@ public function afterInitialize( if (isset($linkData['file_content'])) { $link->setLinkFileContent($linkData['file_content']); } - $link->setId(null); + if (isset($linkData['link_id'])) { + $link->setId($linkData['link_id']); + } if (isset($linkData['sample']['type'])) { $link->setSampleType($linkData['sample']['type']); } @@ -125,10 +127,11 @@ public function afterInitialize( if (!$sampleData || (isset($sampleData['is_delete']) && (bool)$sampleData['is_delete'])) { continue; } else { - unset($sampleData['sample_id']); $sample = $this->sampleFactory->create(['data' => $sampleData]); - $sample->setId(null); $sample->setStoreId($product->getStoreId()); + if (isset($sampleData['sample_id'])) { + $sample->setId($sampleData['sample_id']); + } if (isset($sampleData['type'])) { $sample->setSampleType($sampleData['type']); } diff --git a/app/code/Magento/Downloadable/Model/Link/SaveHandler.php b/app/code/Magento/Downloadable/Model/Link/SaveHandler.php index ce2d1a3ff1535..4dd41228a5e4e 100644 --- a/app/code/Magento/Downloadable/Model/Link/SaveHandler.php +++ b/app/code/Magento/Downloadable/Model/Link/SaveHandler.php @@ -36,17 +36,26 @@ public function __construct(LinkRepository $linkRepository) */ public function execute($entityType, $entity, $arguments = []) { + /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */ if ($entity->getTypeId() !== 'downloadable') { return $entity; } - /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */ - foreach ($this->linkRepository->getList($entity->getSku()) as $link) { - $this->linkRepository->delete($link->getId()); - } + + $oldLinks = $this->linkRepository->getList($entity->getSku()); $links = $entity->getExtensionAttributes()->getDownloadableProductLinks() ?: []; + $updatedLinkIds = []; foreach ($links as $link) { + if ($link->getId()) { + $updatedLinkIds[] = $link->getId(); + } $this->linkRepository->save($entity->getSku(), $link, !(bool)$entity->getStoreId()); } + foreach ($oldLinks as $link) { + if (!in_array($link->getId(), $updatedLinkIds)) { + $this->linkRepository->delete($link->getId()); + } + } + return $entity; } } diff --git a/app/code/Magento/Downloadable/Model/Sample/SaveHandler.php b/app/code/Magento/Downloadable/Model/Sample/SaveHandler.php index 94bc5b172ca18..6344a7d6411e0 100644 --- a/app/code/Magento/Downloadable/Model/Sample/SaveHandler.php +++ b/app/code/Magento/Downloadable/Model/Sample/SaveHandler.php @@ -39,14 +39,22 @@ public function execute($entityType, $entity, $arguments = []) if ($entity->getTypeId() != \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) { return $entity; } - /** @var \Magento\Catalog\Api\Data\ProductInterface $entity */ - foreach ($this->sampleRepository->getList($entity->getSku()) as $sample) { - $this->sampleRepository->delete($sample->getId()); - } + + $oldSamples = $this->sampleRepository->getList($entity->getSku()); $samples = $entity->getExtensionAttributes()->getDownloadableProductSamples() ?: []; + $updatedSampleIds = []; foreach ($samples as $sample) { + if ($sample->getId()) { + $updatedSampleIds[] = $sample->getId(); + } $this->sampleRepository->save($entity->getSku(), $sample, !(bool)$entity->getStoreId()); } + foreach ($oldSamples as $sample) { + if (!in_array($sample->getId(), $updatedSampleIds)) { + $this->sampleRepository->delete($sample->getId()); + } + } + return $entity; } } From a92e2037297eba5c92d8cdba54e1f38645388ed6 Mon Sep 17 00:00:00 2001 From: Roman Liukshyn Date: Thu, 14 Apr 2016 11:10:07 +0000 Subject: [PATCH 7/8] MAGETWO-51868: [Github] USPS shipping weight calculation rounds ounces to whole number --- app/code/Magento/Usps/Model/Carrier.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Usps/Model/Carrier.php b/app/code/Magento/Usps/Model/Carrier.php index a29baf72eb463..6a1d64c7a8cb7 100644 --- a/app/code/Magento/Usps/Model/Carrier.php +++ b/app/code/Magento/Usps/Model/Carrier.php @@ -324,7 +324,7 @@ public function setRequest(\Magento\Quote\Model\Quote\Address\RateRequest $reque $weight = $this->getTotalNumOfBoxes($request->getPackageWeight()); $r->setWeightPounds(floor($weight)); - $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 1)); + $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 10)); if ($request->getFreeMethodWeight() != $request->getPackageWeight()) { $r->setFreeMethodWeight($request->getFreeMethodWeight()); } @@ -371,7 +371,7 @@ protected function _setFreeMethodRequest($freeMethod) $weight = $this->getTotalNumOfBoxes($r->getFreeMethodWeight()); $r->setWeightPounds(floor($weight)); - $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 1)); + $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 10)); $r->setService($freeMethod); } From 7635d4289513954c8ea40fefda4bb2f289d92569 Mon Sep 17 00:00:00 2001 From: Roman Liukshyn Date: Fri, 15 Apr 2016 13:01:07 +0000 Subject: [PATCH 8/8] MAGETWO-51868: [Github] USPS shipping weight calculation rounds ounces to whole number - Added private static variable --- app/code/Magento/Usps/Model/Carrier.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Usps/Model/Carrier.php b/app/code/Magento/Usps/Model/Carrier.php index 6a1d64c7a8cb7..ff2e83b4c370d 100644 --- a/app/code/Magento/Usps/Model/Carrier.php +++ b/app/code/Magento/Usps/Model/Carrier.php @@ -67,6 +67,13 @@ class Carrier extends AbstractCarrierOnline implements \Magento\Shipping\Model\C */ protected $_code = self::CODE; + /** + * Weight precision + * + * @var int + */ + private static $weightPrecision = 10; + /** * Rate request data * @@ -324,7 +331,7 @@ public function setRequest(\Magento\Quote\Model\Quote\Address\RateRequest $reque $weight = $this->getTotalNumOfBoxes($request->getPackageWeight()); $r->setWeightPounds(floor($weight)); - $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 10)); + $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, self::$weightPrecision)); if ($request->getFreeMethodWeight() != $request->getPackageWeight()) { $r->setFreeMethodWeight($request->getFreeMethodWeight()); } @@ -371,7 +378,7 @@ protected function _setFreeMethodRequest($freeMethod) $weight = $this->getTotalNumOfBoxes($r->getFreeMethodWeight()); $r->setWeightPounds(floor($weight)); - $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, 10)); + $r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, self::$weightPrecision)); $r->setService($freeMethod); }