-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* SWPWA-516 - Magento upgrade 2.3.5 * SWPWA-516 - Magento 2.3.5. upgrade * SWPWA-516 - Fix for layer filters * SWPWA-516 - Added back variant collection and searchcriteria * SWPWA-516 - Removed filter attribute file * Performance - not loading items when not requested (#56) * Performance - not loading items when not requested * Adding isReturnItems flag to product data provider call * Bringing back mandatory collection load for the sake of layered filters, but skipping post processing * Removed throw on missing image, add M2.3.5 dependecy Co-authored-by: Aivars <[email protected]> Co-authored-by: aleksandrsm <[email protected]> Co-authored-by: Alfreds Genkins <[email protected]>
- Loading branch information
1 parent
273cccf
commit 5a000ba
Showing
11 changed files
with
193 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
"email": "[email protected]" | ||
}, | ||
"require": { | ||
"magento/magento2-base": "^2.3.2", | ||
"magento/magento2-base": "^2.3.5", | ||
"scandipwa/performance": "^1.0.3" | ||
}, | ||
"type": "magento2-module", | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace ScandiPWA\CatalogGraphQl\Model\Resolver\Category; | ||
|
||
use Magento\Framework\GraphQl\Config\Element\Field; | ||
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Store\Api\Data\StoreInterface; | ||
use Magento\Framework\Filesystem\DirectoryList; | ||
use Magento\Catalog\Model\Category\FileInfo; | ||
|
||
use Magento\CatalogGraphQl\Model\Resolver\Category\Image as CoreImage; | ||
|
||
class Image extends CoreImage { | ||
/** @var FileInfo */ | ||
protected $fileInfo; | ||
|
||
/** @var DirectoryList */ | ||
protected $directoryList; | ||
|
||
/** | ||
* @param DirectoryList $directoryList | ||
* @param FileInfo $fileInfo | ||
*/ | ||
public function __construct( | ||
DirectoryList $directoryList, | ||
FileInfo $fileInfo | ||
) { | ||
parent::__construct( | ||
$directoryList, | ||
$fileInfo | ||
); | ||
|
||
$this->directoryList = $directoryList; | ||
$this->fileInfo = $fileInfo; | ||
} | ||
|
||
public function resolve( | ||
Field $field, | ||
$context, | ||
ResolveInfo $info, | ||
array $value = null, | ||
array $args = null | ||
) { | ||
if (!isset($value['model'])) { | ||
throw new LocalizedException(__('"model" value should be specified')); | ||
} | ||
|
||
/** @var \Magento\Catalog\Model\Category $category */ | ||
$category = $value['model']; | ||
$imagePath = $category->getData('image'); | ||
if (empty($imagePath)) { | ||
return null; | ||
} | ||
|
||
/** @var StoreInterface $store */ | ||
$store = $context->getExtensionAttributes()->getStore(); | ||
$baseUrl = $store->getBaseUrl(); | ||
|
||
$filenameWithMedia = $this->fileInfo->isBeginsWithMediaDirectoryPath($imagePath) | ||
? $imagePath : $this->formatFileNameWithMediaCategoryFolder($imagePath); | ||
|
||
// return full url | ||
return rtrim($baseUrl, '/') . $filenameWithMedia; | ||
} | ||
|
||
/** | ||
* Format category media folder to filename | ||
* | ||
* @param string $fileName | ||
* @return string | ||
*/ | ||
protected function formatFileNameWithMediaCategoryFolder(string $fileName): string | ||
{ | ||
// phpcs:ignore Magento2.Functions.DiscouragedFunction | ||
$baseFileName = basename($fileName); | ||
|
||
return '/' | ||
. $this->directoryList->getUrlPath('media') | ||
. '/' | ||
. ltrim(FileInfo::ENTITY_MEDIA_PATH, '/') | ||
. '/' | ||
. $baseFileName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,23 @@ | |
* @category ScandiPWA | ||
* @package ScandiPWA_CatalogGraphQl | ||
* @author Artjoms Travkovs <[email protected]> | ||
* @author Aivars Arbidans <[email protected]> | ||
* @copyright Copyright (c) 2019 Scandiweb, Ltd (https://scandiweb.com) | ||
*/ | ||
declare (strict_types=1); | ||
|
||
namespace ScandiPWA\CatalogGraphQl\Model\Resolver\Layer\DataProvider; | ||
|
||
use Magento\Catalog\Model\Layer\Filter\Item; | ||
use Magento\CatalogGraphQl\Model\Resolver\Layer\DataProvider\Filters as CoreFilters; | ||
use Magento\CatalogGraphQl\Model\Resolver\Layer\FiltersProvider; | ||
use Magento\Catalog\Model\Layer\Filter\AbstractFilter; | ||
use Magento\Framework\Exception\LocalizedException; | ||
|
||
/** | ||
* Layered navigation filters data provider. | ||
*/ | ||
class Filters extends \Magento\CatalogGraphQl\Model\Resolver\Layer\DataProvider\Filters | ||
class Filters extends CoreFilters | ||
{ | ||
/** | ||
* @var FiltersProvider | ||
|
@@ -29,73 +31,49 @@ class Filters extends \Magento\CatalogGraphQl\Model\Resolver\Layer\DataProvider\ | |
/** | ||
* @var array | ||
*/ | ||
private $requiredAttributes = []; | ||
private $mappings; | ||
|
||
/** | ||
* Filters constructor. | ||
* | ||
* @param FiltersProvider $filtersProvider | ||
*/ | ||
public function __construct( | ||
FiltersProvider $filtersProvider | ||
) { | ||
$this->filtersProvider = $filtersProvider; | ||
} | ||
|
||
/** | ||
* Sets attributes that are being used by products | ||
* | ||
* @param array $items | ||
* @return void | ||
*/ | ||
public function setRequiredAttributesFromItems(array $items) | ||
{ | ||
$attributes = ['cat']; | ||
|
||
foreach ($items as $item) { | ||
$model = $item['model']; | ||
|
||
$itemAttributeCodes = []; | ||
foreach ($model->getAttributes() as $attribute) { | ||
if ($attribute->getIsFilterable()) { | ||
$itemAttributeCodes[] = $attribute->getAttributeCode(); | ||
} | ||
} | ||
|
||
$attributes = array_unique(array_merge($attributes, $itemAttributeCodes)); | ||
} | ||
|
||
$this->requiredAttributes = $attributes; | ||
$this->mappings = [ | ||
'Category' => 'category' | ||
]; | ||
} | ||
|
||
/** | ||
* Get layered navigation filters data | ||
* | ||
* @param string $layerType | ||
* @param array|null $attributesToFilter | ||
* @return array | ||
* @throws LocalizedException | ||
*/ | ||
public function getData(string $layerType): array | ||
public function getData(string $layerType, array $attributesToFilter = null): array | ||
{ | ||
$filtersData = []; | ||
|
||
/** @var AbstractFilter $filter */ | ||
foreach ($this->filtersProvider->getFilters($layerType) as $filter) { | ||
if ($filter->getItemsCount() && $this->hasFilterContents($filter)) { | ||
if ($this->isNeedToAddFilter($filter, $attributesToFilter)) { | ||
$filterGroup = [ | ||
'name' => (string) $filter->getName(), | ||
'filter_items_count' => $filter->getItemsCount(), | ||
'request_var' => $filter->getRequestVar(), | ||
]; | ||
|
||
/** @var Item $filterItem */ | ||
foreach ($filter->getItems() ?? [] as $filterItem) { | ||
foreach ($filter->getItems() as $filterItem) { | ||
$filterGroup['filter_items'][] = [ | ||
'label' => (string) $filterItem->getLabel(), | ||
'value_string' => $filterItem->getValueString(), | ||
'items_count' => $filterItem->getCount(), | ||
]; | ||
} | ||
|
||
$filtersData[] = $filterGroup; | ||
} | ||
} | ||
|
@@ -104,17 +82,31 @@ public function getData(string $layerType): array | |
} | ||
|
||
/** | ||
* Checks whether filter attribute is present in products | ||
* Check for adding filter to the list | ||
* | ||
* @param AbstractFilter $filter | ||
* @return boolean | ||
* @param $attributesToFilter | ||
* @return bool | ||
* @throws LocalizedException | ||
*/ | ||
protected function hasFilterContents(AbstractFilter $filter) | ||
private function isNeedToAddFilter(AbstractFilter $filter, $attributesToFilter): bool | ||
{ | ||
if (count($this->requiredAttributes) <= 0) { | ||
return true; | ||
if ($attributesToFilter === null) { | ||
$result = (bool)$filter->getItemsCount(); | ||
} else { | ||
if ($filter->hasAttributeModel()) { | ||
$filterAttribute = $filter->getAttributeModel(); | ||
$result = in_array($filterAttribute->getAttributeCode(), $attributesToFilter); | ||
} else { | ||
$name = (string)$filter->getName(); | ||
if (array_key_exists($name, $this->mappings)) { | ||
$result = in_array($this->mappings[$name], $attributesToFilter); | ||
} else { | ||
$result = true; | ||
} | ||
} | ||
} | ||
|
||
return in_array($filter->getRequestVar(), $this->requiredAttributes); | ||
return $result; | ||
} | ||
} |
Oops, something went wrong.