Skip to content

Commit

Permalink
Merge pull request #556 from magento-south/merchant_beta
Browse files Browse the repository at this point in the history
[MERCHANT_BETA][SOUTH+TROLL] Create a customer on the frontend, open customer acct in admin, receive error message
  • Loading branch information
slavvka committed Sep 1, 2015
2 parents d0dd2b9 + 290dcf4 commit 1bc2180
Show file tree
Hide file tree
Showing 19 changed files with 172 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
namespace Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing;

use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
use \Magento\Framework\Validator\AbstractValidator;
use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator;

class Validator extends AbstractValidator implements RowValidatorInterface
class Validator extends AbstractImportValidator implements RowValidatorInterface
{
/**
* @var RowValidatorInterface[]|AbstractValidator[]
* @var RowValidatorInterface[]|AbstractImportValidator[]
*/
protected $validators = [];

Expand Down Expand Up @@ -43,14 +43,12 @@ public function isValid($value)
}

/**
* Init validators
*
* @return void
* {@inheritdoc}
*/
public function init()
{
foreach ($this->validators as $validator) {
$validator->init();
$validator->setContext($this->getContext())->init();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
namespace Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing\Validator;

use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing;
use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractPrice;

class GroupPrice extends \Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractPrice
class GroupPrice extends AbstractPrice
{
/**
* @var \Magento\CatalogImportExport\Model\Import\Product\StoreResolver
Expand Down Expand Up @@ -38,15 +39,14 @@ public function __construct(
}

/**
* Call parent init()
*
* @return $this
* {@inheritdoc}
*/
public function init()
{
foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $group) {
$this->customerGroups[$group->getCode()] = $group->getId();
}
return $this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function init()
foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $group) {
$this->customerGroups[$group->getCode()] = $group->getId();
}
return $this;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
namespace Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing\Validator;

use Magento\AdvancedPricingImportExport\Model\Import\AdvancedPricing;
use \Magento\Framework\Validator\AbstractValidator;
use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator;
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;

class Website extends AbstractValidator implements RowValidatorInterface
class Website extends AbstractImportValidator implements RowValidatorInterface
{
/**
* @var \Magento\CatalogImportExport\Model\Import\Product\StoreResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public function setUp()
'Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface',
[],
'',
false
false,
false,
true,
['setContext']
);
$messages = ['messages'];
$this->validatorTest->expects($this->any())->method('getMessages')->willReturn($messages);
Expand All @@ -42,6 +45,7 @@ public function setUp()
['_clearMessages', '_addMessages'],
[$this->validators]
);

}

/**
Expand Down Expand Up @@ -71,9 +75,12 @@ public function testIsValidAddMessagesCall()

public function testInit()
{
$this->validatorTest->expects($this->once())->method('init');

$this->validator->init();
$this->validator->expects($this->any())->method('setContext')->will($this->returnSelf());
$this->validatorTest->expects($this->once())->method('init')->will($this->returnSelf());
$this->validatorTest->expects($this->any())->method('setContext')->will($this->returnSelf());
/** @var \Magento\CatalogImportExport\Model\Import\ContextInterface $contextMock */
$contextMock = $this->getMock('Magento\CatalogImportExport\Model\Import\ContextInterface', [], [], '', false);
$this->validator->setContext($contextMock)->init();
}

public function isValidDataProvider()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CatalogImportExport\Model\Import;

/**
* Interface ContextInterface
* @package Magento\CatalogImportExport\Model\Import
*/
interface ContextInterface
{
/**
* Get context params
*
* @return array|null
*/
public function getParams();

/**
* Get context param by name
*
* @param string $name
*
* @return mixed
*/
public function getParam($name);
}
26 changes: 24 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity implements ContextInterface
{
const CONFIG_KEY_PRODUCT_TYPES = 'global/importexport/import_product_types';

Expand Down Expand Up @@ -660,7 +660,7 @@ public function __construct(
$this->_initAttributeSets()
->_initTypeModels()
->_initSkus();
$this->validator->init();
$this->validator->setContext($this)->init();
}

/**
Expand Down Expand Up @@ -2288,4 +2288,26 @@ protected function _saveValidatedBunches()
$this->getOptionEntity()->validateAmbiguousData();
return parent::_saveValidatedBunches();
}

/**
* Get context params
*
* @return array|null
*/
public function getParams()
{
return $this->_parameters;
}

/**
* Get context param by name
*
* @param string $name
*
* @return mixed
*/
public function getParam($name)
{
return isset($this->_parameters[$name]) ? $this->_parameters[$name] : null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
*/
namespace Magento\CatalogImportExport\Model\Import\Product;

use \Magento\Framework\Validator\AbstractValidator;
use Magento\CatalogImportExport\Model\Import\Product\Validator\AbstractImportValidator;

class Validator extends AbstractValidator implements RowValidatorInterface
class Validator extends AbstractImportValidator implements RowValidatorInterface
{
/**
* @var RowValidatorInterface[]|AbstractValidator[]
* @var RowValidatorInterface[]|AbstractImportValidator[]
*/
protected $validators = [];

Expand Down Expand Up @@ -44,7 +44,7 @@ public function isValid($value)
public function init()
{
foreach ($this->validators as $validator) {
$validator->init();
$validator->setContext($this->getContext())->init();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogImportExport\Model\Import\Product\Validator;

use Magento\Framework\Exception\State\InitException;
use Magento\Framework\Validator\AbstractValidator;
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;
use Magento\CatalogImportExport\Model\Import\ContextInterface;

abstract class AbstractImportValidator extends AbstractValidator implements RowValidatorInterface
{
/**
* @var \Magento\CatalogImportExport\Model\Import\Product
*/
protected $context;

/**
* {@inheritdoc}
*/
public function init()
{
return $this;
}

/**
* Set context object
*
* @param ContextInterface $context
*
* @return $this
*/
public function setContext(ContextInterface $context)
{
$this->context = $context;
return $this;
}

/**
* Get context object
*
* @return ContextInterface
* @throws InitException
*/
public function getContext()
{
if (!$this->context instanceof ContextInterface) {
throw new InitException(__('Validation context is not initialized.'));
}
return $this->context;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Magento\Framework\Validator\AbstractValidator;
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;

abstract class AbstractPrice extends AbstractValidator implements RowValidatorInterface
abstract class AbstractPrice extends AbstractImportValidator implements RowValidatorInterface
{
/**
* @var \Magento\Customer\Api\GroupRepositoryInterface
Expand Down Expand Up @@ -47,6 +47,6 @@ public function init()
foreach ($this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems() as $group) {
$this->customerGroups[$group->getId()] = true;
}
return $this;
return parent::init();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ public function __construct(
parent::__construct($groupRepository, $searchCriteriaBuilder);
}

/**
* {@inheritdoc}
*/
public function init()
{
return parent::init();
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,8 @@
use \Magento\Framework\Validator\AbstractValidator;
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;

class Media extends AbstractValidator implements RowValidatorInterface
class Media extends AbstractImportValidator implements RowValidatorInterface
{
/**
* {@inheritdoc}
*/
public function init()
{
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use \Magento\Framework\Validator\AbstractValidator;
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface;

class SuperProductsSku extends AbstractValidator implements RowValidatorInterface
class SuperProductsSku extends AbstractImportValidator implements RowValidatorInterface
{
/**
* @var \Magento\CatalogImportExport\Model\Import\Product\SkuProcessor
Expand All @@ -24,14 +24,6 @@ public function __construct(
$this->skuProcessor = $skuProcessor;
}

/**
* {@inheritdoc}
*/
public function init()
{
return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ public function __construct(
parent::__construct($groupRepository, $searchCriteriaBuilder);
}

/**
* {@inheritdoc}
*/
public function init()
{
return parent::init();
}

/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
Expand Down
Loading

0 comments on commit 1bc2180

Please sign in to comment.