Skip to content

Commit

Permalink
merge magento/2.3-develop into magento-pangolin/MQE-920-MSI-MFTF-Test…
Browse files Browse the repository at this point in the history
…-Cases-2
  • Loading branch information
Magento CICD authored Apr 24, 2018
2 parents d96938a + 65eb999 commit 66015ff
Show file tree
Hide file tree
Showing 95 changed files with 7,400 additions and 891 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/magento/magento2?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Crowdin](https://d322cqt584bo4o.cloudfront.net/magento-2/localized.png)](https://crowdin.com/project/magento-2)
<h2>Welcome</h2>
Welcome to Magento 2 installation! We're glad you chose to install Magento 2, a cutting edge, feature-rich eCommerce solution that gets results.
Welcome to Magento 2 installation! We're glad you chose to install Magento 2, a cutting-edge, feature-rich eCommerce solution that gets results.

## Magento system requirements
[Magento system requirements](http://devdocs.magento.com/guides/v2.2/install-gde/system-requirements2.html)
[Magento system requirements](http://devdocs.magento.com/guides/v2.3/install-gde/system-requirements2.html)

## Install Magento
To install Magento, see either:

* [Magento DevBox](https://magento.com/tech-resources/download), the easiest way to get started with Magento.
* [Installation guide](http://devdocs.magento.com/guides/v2.2/install-gde/bk-install-guide.html)
* [Installation guide](http://devdocs.magento.com/guides/v2.3/install-gde/bk-install-guide.html)

<h2>Contributing to the Magento 2 code base</h2>
Contributions can take the form of new components or features, changes to existing features, tests, documentation (such as developer guides, user guides, examples, or specifications), bug fixes, optimizations, or just good suggestions.
Expand All @@ -23,11 +22,24 @@ To learn about issues, click [here][2]. To open an issue, click [here][3].

To suggest documentation improvements, click [here][4].

[1]: <http://devdocs.magento.com/guides/v2.2/contributor-guide/contributing.html>
[2]: <http://devdocs.magento.com/guides/v2.2/contributor-guide/contributing.html#report>
[1]: <http://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html>
[2]: <http://devdocs.magento.com/guides/v2.3/contributor-guide/contributing.html#report>
[3]: <https://github.com/magento/magento2/issues>
[4]: <http://devdocs.magento.com>

<h3>Community Maintainers</h3>
The members of this team have been recognized for their outstanding commitment to maintaining and improving Magento. Magento has granted them permission to accept, merge, and reject pull requests, as well as review issues, and thanks these Community Maintainers for their valuable contributions.

<a href="https://magento.com/magento-contributors#maintainers">
<img src="https://raw.githubusercontent.com/wiki/magento/magento2/images/maintainers.png"/>
</a>

<h3>Top Contributors</h3>
Magento team thanks for any contribution that can improve our code base, documentation or increase test coverage. We always recognize our most active members, your contributions are the foundation of the Magento open source platform.
<a href="https://magento.com/magento-contributors">
<img src="https://raw.githubusercontent.com/wiki/magento/magento2/images/contributors.png"/>
</a>

<h3>Labels applied by the Magento team</h3>

| Label | Description |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\ConditionProcessor\ConditionBuilder;

use Magento\Framework\Api\SearchCriteria\CollectionProcessor\ConditionProcessor\CustomConditionInterface;
use Magento\Framework\Api\Filter;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;

/**
* Based on Magento\Framework\Api\Filter builds condition
* that can be applied to Catalog\Model\ResourceModel\Product\Collection
* to filter products that has specific value for EAV attribute
*/
class EavAttributeCondition implements CustomConditionInterface
{
/**
* @var \Magento\Framework\App\ResourceConnection
*/
private $resourceConnection;

/**
* @var \Magento\Eav\Model\Config
*/
private $eavConfig;

/**
* @param \Magento\Eav\Model\Config $eavConfig
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
*/
public function __construct(
\Magento\Eav\Model\Config $eavConfig,
\Magento\Framework\App\ResourceConnection $resourceConnection
) {
$this->eavConfig = $eavConfig;
$this->resourceConnection = $resourceConnection;
}

/**
* Build condition to filter product collection by EAV attribute
*
* @param Filter $filter
* @return string
* @throws \DomainException
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function build(Filter $filter): string
{
$attribute = $this->getAttributeByCode($filter->getField());
$tableAlias = 'ca_' . $attribute->getAttributeCode();

$conditionType = $this->mapConditionType($filter->getConditionType());
$conditionValue = $this->mapConditionValue($conditionType, $filter->getValue());

// NOTE: store scope was ignored intentionally to perform search across all stores
$attributeSelect = $this->resourceConnection->getConnection()
->select()
->from(
[$tableAlias => $attribute->getBackendTable()],
$tableAlias . '.' . $attribute->getEntityIdField()
)->where(
$this->resourceConnection->getConnection()->prepareSqlCondition(
$tableAlias . '.' . $attribute->getIdFieldName(),
['eq' => $attribute->getAttributeId()]
)
)->where(
$this->resourceConnection->getConnection()->prepareSqlCondition(
$tableAlias . '.value',
[$conditionType => $conditionValue]
)
);

return $this->resourceConnection
->getConnection()
->prepareSqlCondition(
Collection::MAIN_TABLE_ALIAS . '.' . $attribute->getEntityIdField(),
[
'in' => $attributeSelect
]
);
}

/**
* @param string $field
* @return Attribute
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function getAttributeByCode(string $field): Attribute
{
return $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field);
}

/**
* Map equal and not equal conditions to in and not in
*
* @param string $conditionType
* @return mixed
*/
private function mapConditionType(string $conditionType): string
{
$conditionsMap = [
'eq' => 'in',
'neq' => 'nin'
];

return isset($conditionsMap[$conditionType]) ? $conditionsMap[$conditionType] : $conditionType;
}

/**
* Wraps value with '%' if condition type is 'like' or 'not like'
*
* @param string $conditionType
* @param string $conditionValue
* @return string
*/
private function mapConditionValue(string $conditionType, string $conditionValue): string
{
$conditionsMap = ['like', 'nlike'];

if (in_array($conditionType, $conditionsMap)) {
$conditionValue = '%' . $conditionValue . '%';
}

return $conditionValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\ConditionProcessor\ConditionBuilder;

use Magento\Framework\Api\Filter;
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\ConditionProcessor\CustomConditionInterface;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;

/**
* Creates appropriate condition builder based on filter field
* - native attribute condition builder if filter field is native attribute in product
* - eav condition builder if filter field is eav attribute
*/
class Factory
{
/**
* @var \Magento\Eav\Model\Config
*/
private $eavConfig;

/**
* @var \Magento\Catalog\Model\ResourceModel\Product
*/
private $productResource;

/**
* @var CustomConditionInterface
*/
private $eavAttributeConditionBuilder;

/**
* @var CustomConditionInterface
*/
private $nativeAttributeConditionBuilder;

/**
* @param \Magento\Eav\Model\Config $eavConfig
* @param \Magento\Catalog\Model\ResourceModel\Product $productResource
* @param CustomConditionInterface $eavAttributeConditionBuilder
* @param CustomConditionInterface $nativeAttributeConditionBuilder
*/
public function __construct(
\Magento\Eav\Model\Config $eavConfig,
\Magento\Catalog\Model\ResourceModel\Product $productResource,
CustomConditionInterface $eavAttributeConditionBuilder,
CustomConditionInterface $nativeAttributeConditionBuilder
) {
$this->eavConfig = $eavConfig;
$this->productResource = $productResource;
$this->eavAttributeConditionBuilder = $eavAttributeConditionBuilder;
$this->nativeAttributeConditionBuilder = $nativeAttributeConditionBuilder;
}

/**
* Decides which condition builder should be used for passed filter
* can be either EAV attribute builder or native attribute builder
* "native" attribute means attribute that is in catalog_product_entity table
*
* @param Filter $filter
* @return CustomConditionInterface
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function createByFilter(Filter $filter): CustomConditionInterface
{
$attribute = $this->getAttributeByCode($filter->getField());

if ($attribute->getBackendTable() === $this->productResource->getEntityTable()) {
return $this->nativeAttributeConditionBuilder;
}

return $this->eavAttributeConditionBuilder;
}

/**
* @param string $field
* @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function getAttributeByCode(string $field): Attribute
{
return $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, $field);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\ConditionProcessor\ConditionBuilder;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\ConditionProcessor\CustomConditionInterface;
use Magento\Framework\Api\Filter;
use Magento\Catalog\Model\ResourceModel\Product\Collection;

/**
* Based on Magento\Framework\Api\Filter builds condition
* that can be applied to Catalog\Model\ResourceModel\Product\Collection
* to filter products that has specific value for their native attribute
*/
class NativeAttributeCondition implements CustomConditionInterface
{
/**
* @var \Magento\Framework\App\ResourceConnection
*/
private $resourceConnection;

/**
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
*/
public function __construct(
\Magento\Framework\App\ResourceConnection $resourceConnection
) {
$this->resourceConnection = $resourceConnection;
}

/**
* Build condition to filter product collection by product native attribute
* "native" attribute means attribute that is in catalog_product_entity table
*
* @param Filter $filter
* @return string
* @throws \DomainException
*/
public function build(Filter $filter): string
{
$conditionType = $this->mapConditionType($filter->getConditionType(), $filter->getField());
$conditionValue = $this->mapConditionValue($conditionType, $filter->getValue());

return $this->resourceConnection
->getConnection()
->prepareSqlCondition(
Collection::MAIN_TABLE_ALIAS . '.' . $filter->getField(),
[
$conditionType => $conditionValue
]
);
}

/**
* Map equal and not equal conditions to in and not in
*
* @param string $conditionType
* @param string $field
* @return mixed
*/
private function mapConditionType(string $conditionType, string $field): string
{
if (strtolower($field) === ProductInterface::SKU) {
$conditionsMap = [
'eq' => 'like',
'neq' => 'nlike'
];
} else {
$conditionsMap = [
'eq' => 'in',
'neq' => 'nin'
];
}

return isset($conditionsMap[$conditionType]) ? $conditionsMap[$conditionType] : $conditionType;
}

/**
* Wraps value with '%' if condition type is 'like' or 'not like'
*
* @param string $conditionType
* @param string $conditionValue
* @return string
*/
private function mapConditionValue(string $conditionType, string $conditionValue): string
{
$conditionsMap = ['like', 'nlike'];

if (in_array($conditionType, $conditionsMap)) {
$conditionValue = '%' . $conditionValue . '%';
}

return $conditionValue;
}
}
Loading

0 comments on commit 66015ff

Please sign in to comment.