EmicoEcommerce / Magento2Tweakwise

Magento 2 module for Tweakwise integration
Other
4 stars 16 forks source link

Add setting to enable/disable showing parent category in layered navigation. #175

Closed leonhelmus closed 2 months ago

leonhelmus commented 2 months ago

Issue Brief

Feature request: In \Tweakwise\Magento2Tweakwise\Model\Client\Request::addCategoryFilter it is expected that everyone wants to show all the parent categories, but not all clients would want that. By adding a setting like "show_parent_category_filter" and if disabled don't add the parent categories in the category filter.

    public function addCategoryFilter($category)
    {
        $ids = [];
        if (is_numeric($category)) {
            $ids[] = $category;
            return $this->addCategoryPathFilter($ids);
        }
        /** @var Category $category */
        $parentIsRoot = in_array(
            (int) $category->getParentId(),
            [
                0,
                1,
                (int) $category->getStore()->getRootCategoryId()
            ],
            true
        );
        if (!$parentIsRoot) {
            // Parent category is added so that category menu is retained on the deepest category level
            $ids[] = (int) $category->getParentId();
        }
        $ids[] = (int) $category->getId();

        return $this->addCategoryPathFilter($ids);
    }

This function could change to something like this:

    public function addCategoryFilter($category)
    {
        $ids = [];
        if (is_numeric($category)) {
            $ids[] = $category;
            return $this->addCategoryPathFilter($ids);
        }
        /** @var Category $category */
        $parentIsRoot = in_array(
            (int) $category->getParentId(),
            [
                0,
                1,
                (int) $category->getStore()->getRootCategoryId()
            ],
            true
        );
        if (!$parentIsRoot && $this->scopeConfig->getValue(self::XML_SHOW_PARENT_CATEGORY_IN_FILTER)) {
            // Parent category is added so that category menu is retained on the deepest category level
            $ids[] = (int) $category->getParentId();
        }
        $ids[] = (int) $category->getId();

        return $this->addCategoryPathFilter($ids);
    }

This way clients can decide themselves if they want to show the parent categories.

Environment

Steps to reproduce

  1. Install Magento from master branch.
  2. [Example] Export configurable product with multiple children and 2 configurable attributes to Tweakwise.
  3. [Example] Configure color filter in Tweakwise
  4. ...

Actual result

  1. [Example] Error message appears: "Cannot save quote".
  2. [Screenshot, logs]
  3. ...

Expected result

List the expected results as a bullet list of expectations

ah-net commented 2 months ago

@leonhelmus Do you mean showing the parent categories in the categorie filter? If you don't want to show the parent categorie in the categorie filter, you can set the categorie filter in Tweakwise to link. Then no parent categories are shown.

leonhelmus commented 2 months ago

Ah really, i did not know that thanks for mentioning it.