Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce PHP endpoints for product filters #1714

Conversation

Quetzacoalt91
Copy link
Contributor

@Quetzacoalt91 Quetzacoalt91 commented Mar 26, 2024

Todo

  • Implement condition Does not contain
  • Implement product selection from filters with Features

Retrieve possible options of product filters

  • {"action":"getProductFilterOptions", "kind": "category"}

Response

[
    {
        "id": "1",
        "value": "Root"
    },
    {
        "id": "2",
        "value": "Catalogue"
    },
    {
        "id": "845",
        "value": "Books"
    }
]
  • {"action":"getProductFilterOptions", "kind": "brand"}

Response

[
    {
        "id": "1",
        "value": "International Company"
    }
]
  • {"action":"getProductFilterOptions", "kind": "attribute"}

Response

[
    [
        "id": "2",
        "key": "Form",
        "values": [
            ["id": "4", "key": "Form", "value": "Classique", "language": "fr"],
            ["id": "4", "key": "Form", "value": "Classic", "language": "en_gb"],
            ["id": "4", "key": "Form", "value": "Chromatique", "language": "fr"],
            ["id": "4", "key": "Form", "value": "Shiny", "language": "en_gb"],
        ],
    ],
    [
        "id": "1",
        "key": "Gender",
        "values": [
            ["id": "3", "key": "Gender", "value": "Femmes", "language": "fr"],
            ["id": "3", "key": "Gender", "value": "Women", "language": "en_gb"],
            ["id": "3", "key": "Gender", "value": "Hommes", "language": "fr"],
            ["id": "3", "key": "Gender", "value": "Men", "language": "en_gb"],
        ]
    ]
]
  • {"action":"getProductFilterOptions", "kind": "feature"}

Response

[
    {
        "id": "25",
        "key": "Bio",
        "values": [
            {
                "id": "3776",
                "key": "Bio",
                "value": "Non",
                "language": "fr"
            },
            {
                "id": "3776",
                "key": "Bio",
                "value": "Nope",
                "language": "gb"
            },
            {
                "id": "3780",
                "key": "Bio",
                "value": "Oui",
                "language": "fr"
            },
            {
                "id": "3780",
                "key": "Bio",
                "value": "Yep",
                "language": "gb"
            }
        ]
    }
]

Count products matching provided filters

Request

{
    "action":"countMatchingProductsFromFilters",
    "filters": [
        {
            "attribute": "id",
            "condition": "contains",
            "value": "79"
        },
        {
            "attribute": "id",
            "condition": "lower",
            "value": "7938"
        },
        {
            "attribute": "price",
            "condition": "greater",
            "value": "0"
        }
    ]
}

Response

{
    "numberOfProducts": 1
}

List products matching provided filters

Request

{
    "action":"listMatchingProductsFromFilters",
    "filters": [
        {
            "attribute": "id",
            "condition": "contains",
            "value": "79"
        },
        {
            "attribute": "id",
            "condition": "lower",
            "value": "7938"
        },
        {
            "attribute": "price",
            "condition": "greater",
            "value": "0"
        }
    ]
}

Response

[
    {
        "id_product": "7937",
        // ...
    },
    {
        // ...
    }
]

@Quetzacoalt91 Quetzacoalt91 added Feature Type: New Feature PHP Tech: PHP labels Mar 26, 2024
@Quetzacoalt91 Quetzacoalt91 self-assigned this Mar 26, 2024
@Quetzacoalt91 Quetzacoalt91 force-pushed the product-filters-php-routes branch 3 times, most recently from e7c390b to 0db143c Compare March 26, 2024 17:49

use PrestaShop\Module\PsxMarketingWithGoogle\Repository\ManufacturerRepository;

class BrandOptionsProvider implements OptionsProviderInterface

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can call it ManufacturerOptionsProvider ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I originally thought. But as we're dealing with Brands on the product filter UI, I wanted to put this name inside the Product Filter namespace

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double checking on the back office shows "Brands" on the interface, only Manufacturer is used on the database, probably for backward compatibility.

@Quetzacoalt91 Quetzacoalt91 changed the title Introduce PHP endpoints for product filters Introduce PHP endpoints for product filters, part 1 (List options for product filters form) Apr 4, 2024
@Quetzacoalt91 Quetzacoalt91 changed the title Introduce PHP endpoints for product filters, part 1 (List options for product filters form) Introduce PHP endpoints for product filters Apr 5, 2024
@ga-devfront ga-devfront changed the base branch from master to feature/product-filter April 24, 2024 15:08
@ga-devfront ga-devfront marked this pull request as ready for review April 24, 2024 15:09
@ga-devfront ga-devfront requested a review from a team as a code owner April 24, 2024 15:09
@ga-devfront ga-devfront requested a review from kktos April 26, 2024 13:43
Copy link
Contributor

@tberger-prestashop tberger-prestashop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grâce à mes grandes connaissances PHP & Core, je te donne une bonne étoile pour ce merveilleux travail:
🌟

Toutes mes félicitations 🎉

@ga-devfront ga-devfront requested a review from kktos April 30, 2024 08:46
$checkValueIsNumber($value);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    $isSingleValue = isset($filter['value']);

    if($isSingleValue) {
        $checkValueIsNumber($filter['value']);
    } else {
        foreach ($filter['values'] as $value) {
            $checkValueIsNumber($value);
        }    
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current version seems more appropriate to me. Before handling each key, we should check it exists first.
The else would make the code less readable as we don't understand easily that we can rely on values if value is not set.

@ga-devfront ga-devfront merged commit 26d1de9 into PrestaShopCorp:feature/product-filter Apr 30, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Type: New Feature PHP Tech: PHP
Projects
None yet
6 participants