Skip to content

Commit

Permalink
Merge pull request #1097 from magento-firedrakes/bugfixes
Browse files Browse the repository at this point in the history
Fixed issues:
- MAGETWO-67291: [Performance] Layered Navigation built for Non Anchored categories
- MAGETWO-64834: Spinner is Always Displayed on Shopping Cart page in Summary block for virtual quote
- MAGETWO-59826: [Github] Opengraphs og:description contains html tags #6776
  • Loading branch information
MomotenkoNatalia authored May 15, 2017
2 parents 1eb9d76 + b3e7eeb commit d4f730e
Show file tree
Hide file tree
Showing 13 changed files with 526 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
?>

<meta property="og:type" content="og:product" />
<meta property="og:title" content="<?php echo $block->escapeHtml($block->getProduct()->getName()); ?>" />
<meta property="og:title" content="<?php echo $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getName())); ?>" />
<meta property="og:image" content="<?php echo $block->escapeUrl($block->getImage($block->getProduct(), 'product_base_image')->getImageUrl()); ?>" />
<meta property="og:description" content="<?php echo $block->escapeHtml($block->getProduct()->getShortDescription()); ?>" />
<meta property="og:description" content="<?php echo $block->escapeHtmlAttr($block->stripTags($block->getProduct()->getShortDescription())); ?>" />
<meta property="og:url" content="<?php echo $block->escapeUrl($block->getProduct()->getProductUrl()); ?>" />
<?php if ($priceAmount = $block->getProduct()->getFinalPrice()):?>
<meta property="product:price:amount" content="<?php /* @escapeNotVerified */ echo $priceAmount; ?>"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,16 @@ class AggregationResolver implements AggregationResolverInterface
*/
private $config;

/**
* @var RequestCheckerInterface
*/
private $requestChecker;

/**
* @var AttributeCollection
*/
private $attributeCollection;

/**
* AggregationResolver constructor
*
Expand All @@ -49,27 +54,35 @@ class AggregationResolver implements AggregationResolverInterface
* @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param Config $config
* @param AttributeCollection $attributeCollection [optional]
* @param RequestCheckerInterface|null $aggregationChecker
*/
public function __construct(
AttributeSetFinderInterface $attributeSetFinder,
ProductAttributeRepositoryInterface $productAttributeRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
Config $config,
AttributeCollection $attributeCollection = null
AttributeCollection $attributeCollection = null,
RequestCheckerInterface $aggregationChecker = null
) {
$this->attributeSetFinder = $attributeSetFinder;
$this->productAttributeRepository = $productAttributeRepository;
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->config = $config;
$this->attributeCollection = $attributeCollection
?: \Magento\Framework\App\ObjectManager::getInstance()->get(AttributeCollection::class);
$this->requestChecker = $aggregationChecker ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(RequestCheckerInterface::class);
}

/**
* {@inheritdoc}
*/
public function resolve(RequestInterface $request, array $documentIds)
{
if (!$this->requestChecker->isApplicable($request)) {
return [];
}

$data = $this->config->get($request->getName());

$bucketKeys = isset($data['aggregations']) ? array_keys($data['aggregations']) : [];
Expand All @@ -79,7 +92,8 @@ public function resolve(RequestInterface $request, array $documentIds)
$request->getAggregation(),
function ($bucket) use ($attributeCodes, $bucketKeys) {
/** @var BucketInterface $bucket */
return in_array($bucket->getField(), $attributeCodes) || in_array($bucket->getName(), $bucketKeys);
return in_array($bucket->getField(), $attributeCodes, true) ||
in_array($bucket->getName(), $bucketKeys, true);
}
);
return array_values($resolvedAggregation);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Model\Adapter\Aggregation\Checker\Query;

use Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface;
use Magento\Framework\Search\RequestInterface;

/**
* Request checker for advanced search.
*
* Checks advanced search query whether required to collect all attributes for entity.
*/
class AdvancedSearch implements RequestCheckerInterface
{
/**
* Identifier for query name
*/
private $name;

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

/**
* {@inheritdoc}
*/
public function isApplicable(RequestInterface $request)
{
$result = true;
// It's no need to render LN filters for advanced search
if ($request->getName() === $this->name) {
$result = false;
}

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Model\Adapter\Aggregation\Checker\Query;

use Magento\Framework\Search\RequestInterface;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Search\Request\QueryInterface;
use Magento\Framework\Search\Request\Query\BoolExpression;
use Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface;
use Magento\Framework\Exception\NoSuchEntityException;

/**
* Request checker for catalog view.
*
* Checks catalog view query whether required to collect all attributes for entity.
*/
class CatalogView implements RequestCheckerInterface
{
/**
* Identifier for query name
*/
private $name;

/**
* @var CategoryRepositoryInterface
*/
private $categoryRepository;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param CategoryRepositoryInterface $categoryRepository
* @param StoreManagerInterface $storeManager
* @param string $name
*/
public function __construct(
CategoryRepositoryInterface $categoryRepository,
StoreManagerInterface $storeManager,
$name
) {
$this->categoryRepository = $categoryRepository;
$this->storeManager = $storeManager;
$this->name = $name;
}

/**
* {@inheritdoc}
*/
public function isApplicable(RequestInterface $request)
{
$result = true;
if ($request->getName() === $this->name) {
$result = $this->hasAnchorCategory($request);
}

return $result;
}

/**
* Check whether category is anchor.
*
* Proceeds with request and check whether at least one of categories is anchor.
*
* @param RequestInterface $request
* @return bool
*/
private function hasAnchorCategory(RequestInterface $request)
{
$queryType = $request->getQuery()->getType();
$result = false;

if ($queryType === QueryInterface::TYPE_BOOL) {
$categories = $this->getCategoriesFromQuery($request->getQuery());

/** @var \Magento\Catalog\Api\Data\CategoryInterface $category */
foreach ($categories as $category) {
// It's no need to render LN filters for non anchor categories
if ($category && $category->getIsAnchor()) {
$result = true;
break;
}
}
}

return $result;
}

/**
* Get categories based on query filter data.
*
* Get categories from query will allow to check if category is anchor
* And proceed with attribute aggregation if it's not
*
* @param QueryInterface $queryExpression
* @return \Magento\Catalog\Api\Data\CategoryInterface[]|[]
*/
private function getCategoriesFromQuery(QueryInterface $queryExpression)
{
/** @var BoolExpression $queryExpression */
$categoryIds = $this->getCategoryIdsFromQuery($queryExpression);
$categories = [];

foreach ($categoryIds as $categoryId) {
try {
$categories[] = $this->categoryRepository
->get($categoryId, $this->storeManager->getStore()->getId());
} catch (NoSuchEntityException $e) {
// do nothing if category is not found by id
}
}

return $categories;
}

/**
* Get Category Ids from search query.
*
* Get Category Ids from Must and Should search queries.
*
* @param QueryInterface $queryExpression
* @return array
*/
private function getCategoryIdsFromQuery(QueryInterface $queryExpression)
{
$queryFilterArray = [];
/** @var BoolExpression $queryExpression */
$queryFilterArray[] = $queryExpression->getMust();
$queryFilterArray[] = $queryExpression->getShould();
$categoryIds = [];

foreach ($queryFilterArray as $item) {
if (!empty($item) && isset($item['category'])) {
$queryFilter = $item['category'];
/** @var \Magento\Framework\Search\Request\Query\Filter $queryFilter */
$categoryIds[] = $queryFilter->getReference()->getValue();
}
}

return $categoryIds;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Model\Adapter\Aggregation;

use Magento\Framework\Search\RequestInterface;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;

class RequestCheckerComposite implements RequestCheckerInterface
{
/**
* @var CategoryRepositoryInterface
*/
private $categoryRepository;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var RequestCheckerInterface[]
*/
private $queryCheckers;

/**
* @param CategoryRepositoryInterface $categoryRepository
* @param StoreManagerInterface $storeManager
* @param RequestCheckerInterface[] $queryCheckers
* @throws \InvalidArgumentException
*/
public function __construct(
CategoryRepositoryInterface $categoryRepository,
StoreManagerInterface $storeManager,
array $queryCheckers
) {
$this->categoryRepository = $categoryRepository;
$this->storeManager = $storeManager;
$this->queryCheckers = $queryCheckers;

foreach ($this->queryCheckers as $queryChecker) {
if (!$queryChecker instanceof RequestCheckerInterface) {
throw new \InvalidArgumentException(
get_class($queryChecker) .
' does not implement ' .
\Magento\CatalogSearch\Model\Adapter\Aggregation\RequestCheckerInterface::class
);
}
}
}

/**
* {@inheritdoc}
*/
public function isApplicable(RequestInterface $request)
{
$result = true;

foreach ($this->queryCheckers as $item) {
/** @var RequestCheckerInterface $item */
$result = $item->isApplicable($request);
if (!$result) {
break;
}
}

return $result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\CatalogSearch\Model\Adapter\Aggregation;

use Magento\Framework\Search\RequestInterface;

/**
* RequestCheckerInterface provides the interface to work with query checkers.
*/
interface RequestCheckerInterface
{
/**
* Provided to check if it's needed to collect all attributes for entity.
*
* Avoiding unnecessary expensive attribute aggregation operation will improve performance.
*
* @param RequestInterface $request
* @return bool
*/
public function isApplicable(RequestInterface $request);
}
Loading

0 comments on commit d4f730e

Please sign in to comment.