Skip to content

Commit

Permalink
MAGETWO-55838: [Add address] Same address can be added several times at
Browse files Browse the repository at this point in the history
once

Merge branch 'develop' of github.com:magento/magento2ce into MAGETWO-55838
  • Loading branch information
rganin committed Sep 30, 2016
2 parents 74d130c + f39ad29 commit 40224b8
Show file tree
Hide file tree
Showing 58 changed files with 1,349 additions and 1,362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ private function getTierPriceStructure($tierPricePath)
'data' => [
'config' => [
'componentType' => Field::NAME,
'component' => 'Magento_Catalog/js/form/element/price-input',
'formElement' => Input::NAME,
'dataType' => Price::NAME,
'label' => __('Price'),
Expand Down

This file was deleted.

This file was deleted.

11 changes: 11 additions & 0 deletions app/code/Magento/CatalogSearch/Block/Advanced/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function __construct(
*/
protected function _prepareLayout()
{
$this->pageConfig->getTitle()->set($this->getPageTitle());
$breadcrumbs = $this->getLayout()->getBlock('breadcrumbs');
if ($breadcrumbs) {
$breadcrumbs->addCrumb(
Expand All @@ -84,6 +85,16 @@ protected function _prepareLayout()
return parent::_prepareLayout();
}

/**
* Get page title
*
* @return \Magento\Framework\Phrase
*/
private function getPageTitle()
{
return __('Advanced Search Results');
}

/**
* Set order options
*
Expand Down
8 changes: 5 additions & 3 deletions app/code/Magento/CatalogSearch/Model/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,11 @@ protected function getPreparedSearchCriteria($attribute, $value)
$value = $value['label'];
}
} elseif ($attribute->getFrontendInput() == 'boolean') {
$value = $value == 1
? __('Yes')
: __('No');
if (is_numeric($value)) {
$value = $value == 1 ? __('Yes') : __('No');
} else {
$value = false;
}
}

return $value;
Expand Down
65 changes: 26 additions & 39 deletions app/code/Magento/CatalogSearch/Model/Search/RequestGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
use Magento\Catalog\Api\Data\EavAttributeInterface;
use Magento\Catalog\Model\Entity\Attribute;
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
use Magento\Framework\Search\Request\BucketInterface;
use Magento\CatalogSearch\Model\Search\RequestGenerator\GeneratorResolver;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Search\Request\FilterInterface;
use Magento\Framework\Search\Request\QueryInterface;

Expand All @@ -25,12 +26,22 @@ class RequestGenerator
*/
private $productAttributeCollectionFactory;

/**
* @var GeneratorResolver
*/
private $generatorResolver;

/**
* @param CollectionFactory $productAttributeCollectionFactory
* @param GeneratorResolver $generatorResolver
*/
public function __construct(CollectionFactory $productAttributeCollectionFactory)
{
public function __construct(
CollectionFactory $productAttributeCollectionFactory,
GeneratorResolver $generatorResolver = null
) {
$this->productAttributeCollectionFactory = $productAttributeCollectionFactory;
$this->generatorResolver = $generatorResolver
?: ObjectManager::getInstance()->get(GeneratorResolver::class);
}

/**
Expand Down Expand Up @@ -62,7 +73,7 @@ private function generateRequest($attributeType, $container, $useFulltext)
$request = [];
foreach ($this->getSearchableAttributes() as $attribute) {
if ($attribute->getData($attributeType)) {
if (!in_array($attribute->getAttributeCode(), ['price', 'category_ids'])) {
if (!in_array($attribute->getAttributeCode(), ['price', 'category_ids'], true)) {
$queryName = $attribute->getAttributeCode() . '_query';

$request['queries'][$container]['queryReference'][] = [
Expand All @@ -76,58 +87,33 @@ private function generateRequest($attributeType, $container, $useFulltext)
'filterReference' => [['ref' => $filterName]],
];
$bucketName = $attribute->getAttributeCode() . self::BUCKET_SUFFIX;
if ($attribute->getBackendType() == 'decimal') {
$request['filters'][$filterName] = [
'type' => FilterInterface::TYPE_RANGE,
'name' => $filterName,
'field' => $attribute->getAttributeCode(),
'from' => '$' . $attribute->getAttributeCode() . '.from$',
'to' => '$' . $attribute->getAttributeCode() . '.to$',
];
$request['aggregations'][$bucketName] = [
'type' => BucketInterface::TYPE_DYNAMIC,
'name' => $bucketName,
'field' => $attribute->getAttributeCode(),
'method' => 'manual',
'metric' => [["type" => "count"]],
];
} else {
$request['filters'][$filterName] = [
'type' => FilterInterface::TYPE_TERM,
'name' => $filterName,
'field' => $attribute->getAttributeCode(),
'value' => '$' . $attribute->getAttributeCode() . '$',
];
$request['aggregations'][$bucketName] = [
'type' => BucketInterface::TYPE_TERM,
'name' => $bucketName,
'field' => $attribute->getAttributeCode(),
'metric' => [["type" => "count"]],
];
}
$generator = $this->generatorResolver->getGeneratorForType($attribute->getBackendType());
$request['filters'][$filterName] = $generator->getFilterData($attribute, $filterName);
$request['aggregations'][$bucketName] = $generator->getAggregationData($attribute, $bucketName);
}
}
/** @var $attribute Attribute */
if (in_array($attribute->getAttributeCode(), ['price', 'sku'])
|| !$attribute->getIsSearchable()
) {
//same fields have special semantics
if (!$attribute->getIsSearchable() || in_array($attribute->getAttributeCode(), ['price', 'sku'], true)) {
// Some fields have their own specific handlers
continue;
}
if ($useFulltext) {

// Match search by custom price attribute isn't supported
if ($useFulltext && $attribute->getFrontendInput() !== 'price') {
$request['queries']['search']['match'][] = [
'field' => $attribute->getAttributeCode(),
'boost' => $attribute->getSearchWeight() ?: 1,
];
}
}

return $request;
}

/**
* Retrieve searchable attributes
*
* @return \Magento\Catalog\Model\Entity\Attribute[]
* @return \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
*/
protected function getSearchableAttributes()
{
Expand Down Expand Up @@ -231,6 +217,7 @@ private function generateAdvancedSearchRequest()
];
}
}

return $request;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CatalogSearch\Model\Search\RequestGenerator;


use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Framework\Search\Request\BucketInterface;
use Magento\Framework\Search\Request\FilterInterface;

class Decimal implements GeneratorInterface
{

/**
* {@inheritdoc}
*/
public function getFilterData(Attribute $attribute, $filterName)
{
return [
'type' => FilterInterface::TYPE_RANGE,
'name' => $filterName,
'field' => $attribute->getAttributeCode(),
'from' => '$' . $attribute->getAttributeCode() . '.from$',
'to' => '$' . $attribute->getAttributeCode() . '.to$',
];
}

/**
* {@inheritdoc}
*/
public function getAggregationData(Attribute $attribute, $bucketName)
{
return [
'type' => BucketInterface::TYPE_DYNAMIC,
'name' => $bucketName,
'field' => $attribute->getAttributeCode(),
'method' => 'manual',
'metric' => [['type' => 'count']],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CatalogSearch\Model\Search\RequestGenerator;


use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
use Magento\Framework\Search\Request\BucketInterface;
use Magento\Framework\Search\Request\FilterInterface;

class General implements GeneratorInterface
{

/**
* {@inheritdoc}
*/
public function getFilterData(Attribute $attribute, $filterName)
{
return [
'type' => FilterInterface::TYPE_TERM,
'name' => $filterName,
'field' => $attribute->getAttributeCode(),
'value' => '$' . $attribute->getAttributeCode() . '$',
];
}

/**
* {@inheritdoc}
*/
public function getAggregationData(Attribute $attribute, $bucketName)
{
return [
'type' => BucketInterface::TYPE_TERM,
'name' => $bucketName,
'field' => $attribute->getAttributeCode(),
'metric' => [['type' => 'count']],
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CatalogSearch\Model\Search\RequestGenerator;


use Magento\Catalog\Model\ResourceModel\Eav\Attribute;

interface GeneratorInterface
{
/**
* Get filter data for specific attribute
* @param Attribute $attribute
* @param string $filterName
* @return array
*/
public function getFilterData(Attribute $attribute, $filterName);

/**
* Get aggregation data for specific attribute
* @param Attribute $attribute
* @param string $bucketName
* @return array
*/
public function getAggregationData(Attribute $attribute, $bucketName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\CatalogSearch\Model\Search\RequestGenerator;

class GeneratorResolver
{
/**
* @var GeneratorInterface[]
*/
private $generators;

/**
* @var GeneratorInterface
*/
private $defaultGenerator;

/**
* @param GeneratorInterface $defaultGenerator
* @param GeneratorInterface[] $generators
*/
public function __construct(GeneratorInterface $defaultGenerator, array $generators)
{
$this->defaultGenerator = $defaultGenerator;
$this->generators = $generators;
}

/**
* @param string $type
* @return GeneratorInterface
* @throws \InvalidArgumentException
*/
public function getGeneratorForType($type)
{
$generator = isset($this->generators[$type]) ? $this->generators[$type] : $this->defaultGenerator;
if (!($generator instanceof GeneratorInterface)) {
throw new \InvalidArgumentException(
'Generator must implement ' . GeneratorInterface::class
);
}
return $generator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function addFiltersDataProvider()
'static'
)
],
'values' => ['is_active' => false],
'values' => ['is_active' => 0],
'currentCurrencyCode' => 'GBP',
'baseCurrencyCode' => 'USD'
],
Expand Down
Loading

0 comments on commit 40224b8

Please sign in to comment.