Skip to content

Commit

Permalink
Merge pull request #130 from blmage/master
Browse files Browse the repository at this point in the history
Prepare new 1.5.2 version
  • Loading branch information
blmage committed Jun 28, 2023
2 parents d3a953e + b175ece commit af2e35c
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 22 deletions.
38 changes: 25 additions & 13 deletions Controller/Adminhtml/Shipping/Method/Rule/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace ShoppingFeed\Manager\Controller\Adminhtml\Shipping\Method\Rule;

use Magento\Backend\App\Action\Context;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Controller\Result\RawFactory as RawResultFactory;
use Magento\Framework\DataObjectFactory;
use Magento\Framework\Exception\LocalizedException;
Expand All @@ -12,6 +13,7 @@
use Magento\Framework\View\Result\PageFactory as PageResultFactory;
use ShoppingFeed\Manager\Api\Shipping\Method\RuleRepositoryInterface;
use ShoppingFeed\Manager\Controller\Adminhtml\Shipping\Method\RuleAction;
use ShoppingFeed\Manager\Model\InputFilterFactory;
use ShoppingFeed\Manager\Model\Shipping\Method\ApplierPoolInterface;
use ShoppingFeed\Manager\Model\Shipping\Method\RuleFactory;
use ShoppingFeed\Manager\Ui\DataProvider\Shipping\Method\Rule\Form\DataProvider as RuleFormDataProvider;
Expand All @@ -30,6 +32,11 @@ class Save extends RuleAction
*/
private $dateFilterFactory;

/**
* @var InputFilterFactory
*/
private $inputFilterFactory;

/**
* @var ApplierPoolInterface
*/
Expand All @@ -45,6 +52,7 @@ class Save extends RuleAction
* @param DataObjectFactory $dataObjectFactory
* @param DateFilterFactory $dateFilterFactory
* @param ApplierPoolInterface $applierPool
* @param InputFilterFactory|null $inputFilterFactory
*/
public function __construct(
Context $context,
Expand All @@ -55,11 +63,13 @@ public function __construct(
RuleRepositoryInterface $ruleRepository,
DataObjectFactory $dataObjectFactory,
DateFilterFactory $dateFilterFactory,
ApplierPoolInterface $applierPool
ApplierPoolInterface $applierPool,
InputFilterFactory $inputFilterFactory = null
) {
$this->dataObjectFactory = $dataObjectFactory;
$this->dateFilterFactory = $dateFilterFactory;
$this->applierPool = $applierPool;
$this->inputFilterFactory = $inputFilterFactory ?? ObjectManager::getInstance()->get(InputFilterFactory::class);

parent::__construct(
$context,
Expand Down Expand Up @@ -111,7 +121,7 @@ public function execute()

$dateFilter = $this->dateFilterFactory->create();

$inputFilter = new \Zend_Filter_Input(
$inputFilter = $this->inputFilterFactory->getInputFilter(
array_intersect_key(
[
RuleFormDataProvider::FIELD_FROM_DATE => $dateFilter,
Expand All @@ -120,20 +130,20 @@ public function execute()
array_filter($ruleData)
),
[
RuleFormDataProvider::FIELD_NAME => 'NotEmpty',
RuleFormDataProvider::FIELD_NAME => $this->inputFilterFactory->getNotEmptyRuleValue(),
RuleFormDataProvider::FIELD_DESCRIPTION => [],
RuleFormDataProvider::FIELD_IS_ACTIVE => [],
RuleFormDataProvider::FIELD_FROM_DATE => [],
RuleFormDataProvider::FIELD_TO_DATE => [],
RuleFormDataProvider::FIELD_SORT_ORDER => 'NotEmpty',
RuleFormDataProvider::FIELD_SORT_ORDER => $this->inputFilterFactory->getNotEmptyRuleValue(),
RuleFormDataProvider::FIELD_CONDITIONS => [
\Zend_Filter_Input::PRESENCE => \Zend_Filter_Input::PRESENCE_OPTIONAL,
InputFilterFactory::PRESENCE => InputFilterFactory::PRESENCE_OPTIONAL,
],
],
$ruleData,
[
\Zend_Filter_Input::ALLOW_EMPTY => true,
\Zend_Filter_Input::PRESENCE => \Zend_Filter_Input::PRESENCE_REQUIRED,
InputFilterFactory::ALLOW_EMPTY => true,
InputFilterFactory::PRESENCE => InputFilterFactory::PRESENCE_REQUIRED,
]
);

Expand All @@ -155,13 +165,15 @@ public function execute()
$this->messageManager->addSuccessMessage(__('The shipping method rule has been successfully saved.'));
} catch (LocalizedException $e) {
$this->messageManager->addExceptionMessage($e, $e->getMessage());
} catch (\Zend_Filter_Exception $e) {
$this->messageManager->addExceptionMessage($e, __($e->getMessage()));
} catch (\Exception $e) {
$this->messageManager->addExceptionMessage(
$e,
__('An error occurred while saving the shipping method rule.')
);
if ($this->inputFilterFactory->isFilterException($e)) {
$this->messageManager->addExceptionMessage($e, __($e->getMessage()));
} else {
$this->messageManager->addExceptionMessage(
$e,
__('An error occurred while saving the shipping method rule.')
);
}
}

if (!$isSaveSuccessful || $this->getRequest()->getParam('back')) {
Expand Down
15 changes: 14 additions & 1 deletion Model/Config/Value/Handler/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ class Email extends Text
{
const TYPE_CODE = 'email';

/**
* @var EmailAddressValidator
*/
private $emailAddressValidator;

/**
* @param EmailAddressValidator $emailAddressValidator
*/
public function __construct(EmailAddressValidator $emailAddressValidator)
{
$this->emailAddressValidator = $emailAddressValidator;
}

public function getFieldValidationClasses()
{
return array_merge(parent::getFieldValidationClasses(), [ self::VALIDATION_CLASS_EMAIL ]);
Expand All @@ -16,6 +29,6 @@ public function getFieldValidationClasses()
public function isValidValue($value, $isRequired)
{
return parent::isValidValue($value, $isRequired)
&& (($value === '') || \Zend_Validate::is($value, EmailAddressValidator::class));
&& (($value === '') || $this->emailAddressValidator->isValid($value));
}
}
2 changes: 1 addition & 1 deletion Model/Feed/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

class Exporter
{
const MODULE_VERSION = '1.5.1';
const MODULE_VERSION = '1.5.2';

const CHILDREN_EXPORT_MODE_NONE = 'none';
const CHILDREN_EXPORT_MODE_SEPARATELY = 'separately';
Expand Down
2 changes: 1 addition & 1 deletion Model/Feed/Product/Attribute/Value/Renderer/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function renderAttributeValue(StoreInterface $store, AbstractAttribute $a
{
$label = null;

if (!$this->isUndefinedValue($value)) {
if (!$this->isUndefinedValue($value) && is_scalar($value)) {
$oldStoreId = $attribute->getData('store_id');
$attribute->setData('store_id', $store->getBaseStoreId());

Expand Down
70 changes: 70 additions & 0 deletions Model/InputFilterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace ShoppingFeed\Manager\Model;

class InputFilterFactory
{
public const ALLOW_EMPTY = 'allowEmpty';
public const BREAK_CHAIN = 'breakChainOnFailure';
public const DEFAULT_VALUE = 'default';
public const MESSAGES = 'messages';
public const ESCAPE_FILTER = 'escapeFilter';
public const FIELDS = 'fields';
public const FILTER = 'filter';
public const FILTER_CHAIN = 'filterChain';
public const MISSING_MESSAGE = 'missingMessage';
public const INPUT_NAMESPACE = 'inputNamespace';
public const VALIDATOR_NAMESPACE = 'validatorNamespace';
public const FILTER_NAMESPACE = 'filterNamespace';
public const NOT_EMPTY_MESSAGE = 'notEmptyMessage';
public const PRESENCE = 'presence';
public const PRESENCE_OPTIONAL = 'optional';
public const PRESENCE_REQUIRED = 'required';
public const RULE = 'rule';
public const RULE_WILDCARD = '*';
public const VALIDATE = 'validate';
public const VALIDATOR = 'validator';
public const VALIDATOR_CHAIN = 'validatorChain';
public const VALIDATOR_CHAIN_COUNT = 'validatorChainCount';

public function getNotEmptyRuleValue()
{
return !class_exists('\Magento\Framework\Filter\FilterInput')
? 'NotEmpty'
: 'Magento\Framework\Validator\NotEmpty';
}

/**
* @param array $filterRules
* @param array $validatorRules
* @param array|null $data
* @param array|null $options
* @return \Magento\Framework\Filter\FilterInput|\Zend_Filter_Input
* @throws \Exception
*/
public function getInputFilter(array $filterRules, array $validatorRules, array $data = null, array $options = null)
{
if (class_exists('Zend_Filter_Input')) {
return new \Zend_Filter_Input($filterRules, $validatorRules, $data, $options);
} elseif (class_exists('\Magento\Framework\Filter\FilterInput')) {
return new \Magento\Framework\Filter\FilterInput($filterRules, $validatorRules, $data, $options);
}

throw new \Exception('No input filter class found.');
}

/**
* @param \Exception $e
* @return bool
*/
public function isFilterException(\Exception $e)
{
if (class_exists('Zend_Filter_Exception')) {
return $e instanceof \Zend_Filter_Exception;
} elseif (class_exists('\Magento\Framework\Filter\FilterException')) {
return $e instanceof \Magento\Framework\Filter\FilterException;
}

return false;
}
}
1 change: 0 additions & 1 deletion Model/ResourceModel/Feed/Catalog/Product/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace ShoppingFeed\Manager\Model\ResourceModel\Feed\Catalog\Product;

use Magento\Catalog\Model\ResourceModel\Frontend;
use Magento\Catalog\Model\ResourceModel\Product\Collection as BaseCollection;
use Magento\Framework\DB\Adapter\AdapterInterface as DbAdapterInterface;
use Magento\Framework\Exception\LocalizedException;
Expand Down
2 changes: 1 addition & 1 deletion Model/ResourceModel/Feed/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ private function joinSectionTablesToProductSelect(
[ $sectionDataKey => 'data' ]
);
} else {
throw new Exception(sprintf('Unsupported join type: "%s".', $joinType));
throw new \Exception(sprintf('Unsupported join type: "%s".', $joinType));
}
}
}
Expand Down
16 changes: 13 additions & 3 deletions Model/Sales/Order/Customer/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Directory\Helper\Data as DirectoryHelper;
use Magento\Directory\Model\Region;
use Magento\Directory\Model\ResourceModel\Region\CollectionFactory as RegionCollectionFactory;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DataObjectFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filter\Template as TemplateFilter;
Expand Down Expand Up @@ -110,6 +111,11 @@ class Importer
*/
private $templateFilter;

/**
* @var EmailAddressValidator
*/
private $emailAddressValidator;

/**
* @var RegionCollectionFactory
*/
Expand Down Expand Up @@ -169,6 +175,7 @@ class Importer
* @param CustomerAddressFactory $customerAddressFactory
* @param CustomerAddressResourceFactory $customerAddresssResourceFactory
* @param OrderConfigInterface $orderGeneralConfig
* @param EmailAddressValidator|null $emailAddressValidator
*/
public function __construct(
DataObjectFactory $dataObjectFactory,
Expand All @@ -183,7 +190,8 @@ public function __construct(
CustomerRegistry $customerRegistry,
CustomerAddressFactory $customerAddressFactory,
CustomerAddressResourceFactory $customerAddresssResourceFactory,
OrderConfigInterface $orderGeneralConfig
OrderConfigInterface $orderGeneralConfig,
EmailAddressValidator $emailAddressValidator = null
) {
$this->dataObjectFactory = $dataObjectFactory;
$this->randomGenerator = $randomGenerator;
Expand All @@ -198,6 +206,8 @@ public function __construct(
$this->customerAddressFactory = $customerAddressFactory;
$this->customerAddressResource = $customerAddresssResourceFactory->create();
$this->orderGeneralConfig = $orderGeneralConfig;
$this->emailAddressValidator = $emailAddressValidator
?? ObjectManager::getInstance()->get(EmailAddressValidator::class);
}

/**
Expand Down Expand Up @@ -425,7 +435,7 @@ public function getAddressEmail(
if (
$this->orderGeneralConfig->shouldForceDefaultEmailAddressForMarketplace($store, $marketplace)
|| ('' === $email)
|| !\Zend_Validate::is($email, EmailAddressValidator::class)
|| !$this->emailAddressValidator->isValid($email)
) {
$this->templateFilter->setVariables(
array_merge(
Expand All @@ -436,7 +446,7 @@ public function getAddressEmail(
],
function ($email) {
return ('' !== $email)
&& \Zend_Validate::is($email, EmailAddressValidator::class);
&& $this->emailAddressValidator->isValid($email);
}
),
array_map(
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "shoppingfeed/magento2-manager",
"type": "magento2-module",
"version": "1.5.1",
"version": "1.5.2",
"license": "OSL-3.0",
"description": "Official module for Shopping Feed integration.",
"require": {
Expand Down

0 comments on commit af2e35c

Please sign in to comment.