Skip to content

Commit

Permalink
Category URL key giving variants as null in GraphQL #483 (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
immuhammad authored and alfredsgenkins committed Jan 7, 2020
1 parent f8ff09d commit 81c234d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
use Magento\Framework\Data\Collection\AbstractDb;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Registry;

/**
* Category filter allows to filter products collection using custom defined filters from search criteria.
Expand Down Expand Up @@ -50,13 +49,11 @@ class CategoryFilter implements CustomFilterInterface
public function __construct(
CategoryFactory $categoryFactory,
CategoryResourceModel $categoryResourceModel,
CategoryResourceCollection $categoryResourceCollection,
Registry $registry
CategoryResourceCollection $categoryResourceCollection
) {
$this->categoryFactory = $categoryFactory;
$this->categoryResourceModel = $categoryResourceModel;
$this->categoryResourceCollection = $categoryResourceCollection;
$this->registry = $registry;
}

/**
Expand Down Expand Up @@ -88,7 +85,6 @@ public function apply(Filter $filter, AbstractDb $collection)
->addAttributeToSelect(['entity_id'])->getFirstItem()->getEntityId();

$this->categoryResourceModel->load($category, $categoryId);
$this->registry->register('current_category', $category);

$collection->addCategoryFilter($category);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,42 @@
*/
class ConfigurableProductAttributeFilter implements CustomFilterInterface
{
/**
* @var Configurable
*/
protected $configurable;
/**
* @var CollectionFactory
*/
protected $collectionFactory;
protected $registry;

/**
* ConfigurableProductAttributeFilter constructor.
* @param Configurable $configurable
* @param CollectionFactory $collectionFactory
*/
public function __construct(
Configurable $configurable,
CollectionFactory $collectionFactory,
Registry $registry
CollectionFactory $collectionFactory
) {
$this->registry = $registry;
$this->configurable = $configurable;
$this->collectionFactory = $collectionFactory;
}

/**
* @param Filter $filter
* @param AbstractDb $collection
* @return bool
*/
public function apply(Filter $filter, AbstractDb $collection)
{
$attributeName = $filter->getField();
$attributeValue = $filter->getValue();
$conditionType = $filter->getConditionType();
$category = $this->registry->registry('current_category');

$simpleSelect = $this->collectionFactory->create()
->addAttributeToFilter($attributeName, [$conditionType => $attributeValue])
->addAttributeToFilter('status', Status::STATUS_ENABLED);
if ($category) {
$simpleSelect->addCategoriesFilter(['in' => (int)$category->getId()]);
}


$simpleSelect->getSelect()
Expand Down

0 comments on commit 81c234d

Please sign in to comment.