Skip to content

Commit

Permalink
Merge pull request #541 from magento-mpi/MPI-BUGFIXES
Browse files Browse the repository at this point in the history
[MPI] BUGFIXES
  • Loading branch information
Paliarush, Alexander(apaliarush) committed Apr 15, 2016
2 parents 2a71879 + 5fe77c2 commit ff70f6e
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -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']);
}
Expand Down Expand Up @@ -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']);
}
Expand Down
17 changes: 13 additions & 4 deletions app/code/Magento/Downloadable/Model/Link/SaveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
16 changes: 12 additions & 4 deletions app/code/Magento/Downloadable/Model/Sample/SaveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 4 additions & 0 deletions app/code/Magento/Payment/Model/Method/Cc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}
Expand Down
54 changes: 47 additions & 7 deletions app/code/Magento/Paypal/Model/Report/Settlement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Magento\Paypal\Model\Report;

use DateTime;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\DirectoryList;

Expand Down Expand Up @@ -162,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
Expand Down Expand Up @@ -249,7 +257,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')
);
Expand Down Expand Up @@ -324,7 +333,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.
Expand Down Expand Up @@ -360,11 +369,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.
Expand All @@ -385,6 +390,41 @@ 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]])) {
if (in_array($rowMap[$sectionColumns[$i]], $this->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)
*
Expand Down
11 changes: 9 additions & 2 deletions app/code/Magento/Usps/Model/Carrier.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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, 1));
$r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, self::$weightPrecision));
if ($request->getFreeMethodWeight() != $request->getPackageWeight()) {
$r->setFreeMethodWeight($request->getFreeMethodWeight());
}
Expand Down Expand Up @@ -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, 1));
$r->setWeightOunces(round(($weight - floor($weight)) * self::OUNCES_POUND, self::$weightPrecision));
$r->setService($freeMethod);
}

Expand Down

0 comments on commit ff70f6e

Please sign in to comment.