Skip to content

Commit

Permalink
Merge branch '1.1-develop' into 1.1.4-develop-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
sidolov authored Dec 19, 2019
2 parents ff018ec + ea18cd3 commit cdf5b2d
Show file tree
Hide file tree
Showing 57 changed files with 1,471 additions and 762 deletions.
19 changes: 13 additions & 6 deletions Inventory/Model/ResourceModel/SourceItem/SaveMultiple.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/**
* Implementation of SourceItem save multiple operation for specific db layer
*
* Save Multiple used here for performance efficient purposes over single save operation
*/
class SaveMultiple
Expand Down Expand Up @@ -69,6 +70,8 @@ public function execute(array $sourceItems)
}

/**
* Build column sql part
*
* @param array $columns
* @return string
*/
Expand All @@ -81,6 +84,8 @@ private function buildColumnsSqlPart(array $columns): string
}

/**
* Build sql query for values
*
* @param SourceItemInterface[] $sourceItems
* @return string
*/
Expand All @@ -91,24 +96,26 @@ private function buildValuesSqlPart(array $sourceItems): string
}

/**
* Get Sql bind data
*
* @param SourceItemInterface[] $sourceItems
* @return array
*/
private function getSqlBindData(array $sourceItems): array
{
$bind = [];
foreach ($sourceItems as $sourceItem) {
$bind = array_merge($bind, [
$sourceItem->getSourceCode(),
$sourceItem->getSku(),
$sourceItem->getQuantity(),
$sourceItem->getStatus(),
]);
$bind[] = $sourceItem->getSourceCode();
$bind[] = $sourceItem->getSku();
$bind[] = $sourceItem->getQuantity();
$bind[] = $sourceItem->getStatus();
}
return $bind;
}

/**
* Build sql query for on duplicate event
*
* @param array $fields
* @return string
*/
Expand Down
47 changes: 36 additions & 11 deletions Inventory/Model/Source/Validator/CodeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

use Magento\Framework\Validation\ValidationResult;
use Magento\Framework\Validation\ValidationResultFactory;
use Magento\Inventory\Model\Validators\NoSpecialCharsInString;
use Magento\Inventory\Model\Validators\NotAnEmptyString;
use Magento\Inventory\Model\Validators\NoWhitespaceInString;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Model\SourceValidatorInterface;

Expand All @@ -22,12 +25,37 @@ class CodeValidator implements SourceValidatorInterface
*/
private $validationResultFactory;

/**
* @var NotAnEmptyString
*/
private $notAnEmptyString;

/**
* @var NoWhitespaceInString
*/
private $noWhitespaceInString;

/**
* @var NoSpecialCharsInString
*/
private $noSpecialCharsInString;

/**
* @param ValidationResultFactory $validationResultFactory
* @param NotAnEmptyString $notAnEmptyString
* @param NoWhitespaceInString $noWhitespaceInString
* @param NoSpecialCharsInString $noSpecialCharsInString
*/
public function __construct(ValidationResultFactory $validationResultFactory)
{
public function __construct(
ValidationResultFactory $validationResultFactory,
NotAnEmptyString $notAnEmptyString,
NoWhitespaceInString $noWhitespaceInString,
NoSpecialCharsInString $noSpecialCharsInString
) {
$this->validationResultFactory = $validationResultFactory;
$this->notAnEmptyString = $notAnEmptyString;
$this->noWhitespaceInString = $noWhitespaceInString;
$this->noSpecialCharsInString = $noSpecialCharsInString;
}

/**
Expand All @@ -36,16 +64,13 @@ public function __construct(ValidationResultFactory $validationResultFactory)
public function validate(SourceInterface $source): ValidationResult
{
$value = (string)$source->getSourceCode();
$errors = [
$this->notAnEmptyString->execute(SourceInterface::SOURCE_CODE, $value),
$this->noWhitespaceInString->execute(SourceInterface::SOURCE_CODE, $value),
$this->noSpecialCharsInString->execute($value)
];
$errors = !empty($errors) ? array_merge(...$errors) : $errors;

if ('' === trim($value)) {
$errors[] = __('"%field" can not be empty.', ['field' => SourceInterface::SOURCE_CODE]);
} elseif (preg_match('/\s/', $value)) {
$errors[] = __('"%field" can not contain whitespaces.', ['field' => SourceInterface::SOURCE_CODE]);
} elseif (preg_match('/\$[:]*{(.)*}/', $value)) {
$errors[] = __('Validation Failed');
} else {
$errors = [];
}
return $this->validationResultFactory->create(['errors' => $errors]);
}
}
24 changes: 17 additions & 7 deletions Inventory/Model/Source/Validator/CountryValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Framework\Validation\ValidationResult;
use Magento\Framework\Validation\ValidationResultFactory;
use Magento\Inventory\Model\Validators\NotAnEmptyString;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Model\SourceValidatorInterface;

Expand All @@ -22,12 +23,21 @@ class CountryValidator implements SourceValidatorInterface
*/
private $validationResultFactory;

/**
* @var NotAnEmptyString
*/
private $notAnEmptyString;

/**
* @param ValidationResultFactory $validationResultFactory
* @param NotAnEmptyString $notAnEmptyString
*/
public function __construct(ValidationResultFactory $validationResultFactory)
{
public function __construct(
ValidationResultFactory $validationResultFactory,
NotAnEmptyString $notAnEmptyString
) {
$this->validationResultFactory = $validationResultFactory;
$this->notAnEmptyString = $notAnEmptyString;
}

/**
Expand All @@ -37,11 +47,11 @@ public function validate(SourceInterface $source): ValidationResult
{
$value = (string)$source->getCountryId();

if ('' === trim($value)) {
$errors[] = __('"%field" can not be empty.', ['field' => SourceInterface::COUNTRY_ID]);
} else {
$errors = [];
}
$errors = [
$this->notAnEmptyString->execute(SourceInterface::COUNTRY_ID, $value)
];
$errors = !empty($errors) ? array_merge(...$errors) : $errors;

return $this->validationResultFactory->create(['errors' => $errors]);
}
}
35 changes: 26 additions & 9 deletions Inventory/Model/Source/Validator/NameValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

use Magento\Framework\Validation\ValidationResult;
use Magento\Framework\Validation\ValidationResultFactory;
use Magento\Inventory\Model\Validators\NoSpecialCharsInString;
use Magento\Inventory\Model\Validators\NotAnEmptyString;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Model\SourceValidatorInterface;

Expand All @@ -22,12 +24,29 @@ class NameValidator implements SourceValidatorInterface
*/
private $validationResultFactory;

/**
* @var NotAnEmptyString
*/
private $notAnEmptyString;

/**
* @var NoSpecialCharsInString
*/
private $noSpecialCharsInString;

/**
* @param ValidationResultFactory $validationResultFactory
* @param NotAnEmptyString $notAnEmptyString
* @param NoSpecialCharsInString $noSpecialCharsInString
*/
public function __construct(ValidationResultFactory $validationResultFactory)
{
public function __construct(
ValidationResultFactory $validationResultFactory,
NotAnEmptyString $notAnEmptyString,
NoSpecialCharsInString $noSpecialCharsInString
) {
$this->validationResultFactory = $validationResultFactory;
$this->notAnEmptyString = $notAnEmptyString;
$this->noSpecialCharsInString = $noSpecialCharsInString;
}

/**
Expand All @@ -36,14 +55,12 @@ public function __construct(ValidationResultFactory $validationResultFactory)
public function validate(SourceInterface $source): ValidationResult
{
$value = (string)$source->getName();
$errors = [
$this->notAnEmptyString->execute(SourceInterface::NAME, $value),
$this->noSpecialCharsInString->execute($value)
];
$errors = !empty($errors) ? array_merge(...$errors) : $errors;

if ('' === trim($value)) {
$errors[] = __('"%field" can not be empty.', ['field' => SourceInterface::NAME]);
} elseif (preg_match('/\$[:]*{(.)*}/', $value)) {
$errors[] = __('Validation Failed');
} else {
$errors = [];
}
return $this->validationResultFactory->create(['errors' => $errors]);
}
}
24 changes: 17 additions & 7 deletions Inventory/Model/Source/Validator/PostcodeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Framework\Validation\ValidationResult;
use Magento\Framework\Validation\ValidationResultFactory;
use Magento\Inventory\Model\Validators\NotAnEmptyString;
use Magento\InventoryApi\Api\Data\SourceInterface;
use Magento\InventoryApi\Model\SourceValidatorInterface;

Expand All @@ -22,12 +23,21 @@ class PostcodeValidator implements SourceValidatorInterface
*/
private $validationResultFactory;

/**
* @var NotAnEmptyString
*/
private $notAnEmptyString;

/**
* @param ValidationResultFactory $validationResultFactory
* @param NotAnEmptyString $notAnEmptyString
*/
public function __construct(ValidationResultFactory $validationResultFactory)
{
public function __construct(
ValidationResultFactory $validationResultFactory,
NotAnEmptyString $notAnEmptyString
) {
$this->validationResultFactory = $validationResultFactory;
$this->notAnEmptyString = $notAnEmptyString;
}

/**
Expand All @@ -37,11 +47,11 @@ public function validate(SourceInterface $source): ValidationResult
{
$value = (string)$source->getPostcode();

if ('' === trim($value)) {
$errors[] = __('"%field" can not be empty.', ['field' => SourceInterface::POSTCODE]);
} else {
$errors = [];
}
$errors = [
$this->notAnEmptyString->execute(SourceInterface::POSTCODE, $value)
];
$errors = !empty($errors) ? array_merge(...$errors) : $errors;

return $this->validationResultFactory->create(['errors' => $errors]);
}
}
26 changes: 17 additions & 9 deletions Inventory/Model/SourceItem/Validator/QuantityValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Framework\Validation\ValidationResult;
use Magento\Framework\Validation\ValidationResultFactory;
use Magento\Inventory\Model\Validators\IsNumericValue;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryApi\Model\SourceItemValidatorInterface;

Expand All @@ -22,26 +23,33 @@ class QuantityValidator implements SourceItemValidatorInterface
*/
private $validationResultFactory;

/**
* @var IsNumericValue
*/
private $isNumericValue;

/**
* @param ValidationResultFactory $validationResultFactory
* @param IsNumericValue $isNumericValue
*/
public function __construct(ValidationResultFactory $validationResultFactory)
{
public function __construct(
ValidationResultFactory $validationResultFactory,
IsNumericValue $isNumericValue
) {
$this->validationResultFactory = $validationResultFactory;
$this->isNumericValue = $isNumericValue;
}

/**
* @inheritdoc
*/
public function validate(SourceItemInterface $source): ValidationResult
{
$errors = [];
if (!is_numeric($source->getQuantity())) {
$errors[] = __(
'"%field" should be numeric.',
['field' => SourceItemInterface::QUANTITY]
);
}
$value = $source->getQuantity();
$errors = [
$this->isNumericValue->execute(SourceItemInterface::QUANTITY, $value)
];
$errors = !empty($errors) ? array_merge(...$errors) : $errors;

return $this->validationResultFactory->create(['errors' => $errors]);
}
Expand Down
26 changes: 17 additions & 9 deletions Inventory/Model/SourceItem/Validator/SkuValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Magento\Framework\Validation\ValidationResult;
use Magento\Framework\Validation\ValidationResultFactory;
use Magento\Inventory\Model\Validators\NotAnEmptyString;
use Magento\InventoryApi\Api\Data\SourceItemInterface;
use Magento\InventoryApi\Model\SourceItemValidatorInterface;

Expand All @@ -22,26 +23,33 @@ class SkuValidator implements SourceItemValidatorInterface
*/
private $validationResultFactory;

/**
* @var NotAnEmptyString
*/
private $notAnEmptyString;

/**
* @param ValidationResultFactory $validationResultFactory
* @param NotAnEmptyString $notAnEmptyString
*/
public function __construct(ValidationResultFactory $validationResultFactory)
{
public function __construct(
ValidationResultFactory $validationResultFactory,
NotAnEmptyString $notAnEmptyString
) {
$this->validationResultFactory = $validationResultFactory;
$this->notAnEmptyString = $notAnEmptyString;
}

/**
* @inheritdoc
*/
public function validate(SourceItemInterface $source): ValidationResult
{
$errors = [];
if ('' === trim((string)$source->getSku())) {
$errors[] = __(
'"%field" can not be empty.',
['field' => SourceItemInterface::SKU]
);
}
$value = $source->getSku();
$errors = [
$this->notAnEmptyString->execute(SourceItemInterface::SKU, $value)
];
$errors = !empty($errors) ? array_merge(...$errors) : $errors;

return $this->validationResultFactory->create(['errors' => $errors]);
}
Expand Down
Loading

0 comments on commit cdf5b2d

Please sign in to comment.