I failed to create a filter for products on sale with WPSOLR+WooCommerce

Tagged:
  • Murat
    Participant
    3 years, 10 months ago #23134

    I want to create a page on WordPress, that is dedicated to show all product ‘on sale’ from my woocommerce products catalogue.
    so far, I failed to do that with WPSOLR.

    Can you please advise how to achieve that with a small tutorial?

    Thanks for the great plugin

    wpsolr
    Keymaster
    3 years, 10 months ago #23135

    WPSOLR is meant to replace archive queries. It cannot display custom queries on custom pages.

    Murat
    Participant
    3 years, 10 months ago #23136

    So, afterall let us skip my idea of creating a new page dedicated for filtering on-sale
    and let us focus on understanding how can I enable a filter to show products on sale on the main shop page (no more custom pages)

    wpsolr
    Keymaster
    3 years, 10 months ago #23137

    If “on sale” is an attribute or a custom field, just select it in screen 2.2, then add it to filters in screen 2.4, and reindex all your products.

    Murat
    Participant
    3 years, 10 months ago #23138

    it is an attribute – that i can see through json API, if you use postman to execute an HTTP GET on woocommerce REST API – you would see as this extract below

     {
            "id": 249988,
            "name": "703 violet",
            "slug": "703-violet",
            "permalink": "https://..........",
            "date_created": "2020-12-17T18:03:33",
            "date_created_gmt": "2020-12-17T18:03:33",
            "date_modified": "2020-12-17T18:03:33",
            "date_modified_gmt": "2020-12-17T18:03:33",
            "type": "simple",
            "status": "publish",
            "featured": false,
            "catalog_visibility": "visible",
            "description": "...........",
            "short_description": "",
            "sku": "s568108",
            "price": "320",
            "regular_price": "320",
            "sale_price": "",
            "date_on_sale_from": null,
            "date_on_sale_from_gmt": null,
            "date_on_sale_to": null,
            "date_on_sale_to_gmt": null,
            "price_html": ".......",
            "on_sale": false,   // <<<<<<<<<<<<<<<<<<<
            "purchasable": true,
            "total_sales": 0,
            "virtual": false,
            "downloadable": false,
            "downloads": [],
            "download_limit": -1,
            "download_expiry": -1,
            "external_url": "",
            "button_text": "",
            "tax_status": "taxable",
            "tax_class": "",
            "manage_stock": false,
            "stock_quantity": null,
            "stock_status": "instock",
            "backorders": "no",
            "backorders_allowed": false,
            "backordered": false,
            "sold_individually": false,
            "weight": "",
            "dimensions": {
                "length": "",
                "width": "",
                "height": ""
            },

    the exact limitation I am facing with WPSOLR is that it does NOT expose the boolean property ‘ON_SALE’
    thus depriving me of being able to filter against it as a whole.
    I used before woobeewoo filters, and it has that feature.
    but when I enable WPSOLR , it takes over the search engine, and even woobeewoo does not work anymore… as all the searches against the woocommerce products are piped through WPSOLR.

    i suggest if you could advise of a suitable PHP snipper to be added for the time being to the functions.php to enable exposing the ON_SALE property in the filters of WPSOLR

    • This reply was modified 3 years, 10 months ago by Murat.
    • This reply was modified 3 years, 10 months ago by Murat.
    wpsolr
    Keymaster
    3 years, 10 months ago #23141

    If “on sale” is an attribute or a custom field, just select it in screen 2.2, then add it to filters in screen 2.4, and reindex all your products.

    Did you apply my recommendation? You should now see the onsale filter on WPSOLR filters widget.

    I used before woobeewoo filters,

    WPSOLR provides its own widget filters. You cannot power WPSOLR queries with another filter plugin.

    Murat
    Participant
    3 years, 10 months ago #23142

    i am not using the WPSOLR solely on my site – all filters configured, and having more than 60,000 products
    these are fed into the wooCommerce site through REST API
    yes, I am having all my filters successfully configured , an I understand your explanation.
    However, my point is, it would be a redundancy to create an attribute and/or custom field to capture the boolean flag of the product as being either on sale or not on sale, especially that this property is already found in the woocommerce system.
    The ration is, from a cleaner setup point of view, redundancy of properties/attributes should be avoided.
    I could see on the filters

    WPSOLR only identities the following fields, and skips the internal on_sale property, which I believe should be also hard-coded in WPSOLR – as this is a very standard usage common usage scenario
    ==============

     Camera_Date
     forsage_id
     _price
     _regular_price
     _sale_price
     _sku
     _supplier_name
     sale_currency
     sale_currency_rate_USD_UAH
     sale_min_qty_price
     total_sales
     _backorders
     _downloadable
     _download_expiry
     _download_limit
     _edit_lock
     _manage_stock
     _product_attributes
     _product_version
     _sold_individually
     _stock
     _stock_status
     _supplier_address
     _supplier_email
     _supplier_min_price
     _supplier_phone
     _tax_class
     _tax_status
     _thumbnail_id
     _virtual
     _wcmmq_s_min_quantity
     _wcmmq_s_product_step
     _wc_average_rating
     _wc_review_count
    wpsolr
    Keymaster
    3 years, 10 months ago #23143

    I now understand that you cannot see your field “on_sale” in screen 2.2, neither as a product taxonomy, nor as a product custom field.
    How did you custom build this field in the system?

    Murat
    Participant
    3 years, 10 months ago #23155

    Yes true that I have it shown neither as taxonomy nor as field property like you have noticed.
    Keep in mind also that I did not custom build it, as it is available out of the box.
    you can see it yourself by following these steps on a sandbox as follows:
    – install WordPress + woocommerce with dummy products that come with any theme builder, or you add a few standard products manually.
    – enable woocommerce REST API and generate the API keys from within the woocommerce app
    – install postman (https://www.postman.com/downloads/)
    – try to make a simple a simple HTTP GET request through postman
    https://stackoverflow.com/questions/47675850/how-to-authorize-android-app-to-communicate-with-woocommerce-site-using-postman
    see for yourself that the property “on_sale” is available out of the box.
    I strongly believe that WPSOLR must somehow regard that very important field boolean property to serve day to day mainstream use cases of having to filter products on sale – as this is a global requirement each website must provide as part of the out-of-the-box experience.
    already other product search filter addons do support mapping to the in-built on_sale boolean property:
    – annasta filters
    – woobeewoo
    – etc…

    wpsolr
    Keymaster
    3 years, 10 months ago #23157

    Thanks, I understand now.
    “On sale” is not a data stored anywhere, hence you cannot find it in screen 2.2.
    The On sale is a calculation based on regular price, sale price, and sale price dates.

    wpsolr
    Keymaster
    wpsolr
    Keymaster
    3 years, 9 months ago #23326

    This “on sale” facet is in tests.

    The solution requires to re-index all the products every day (WPSOLR provides a cron API for that), for performance reasons: when indexing a product, a new custom field “wpsolr_on_sale” is filled with “yes/no” depending on the product’s sale amount and sale dates (and also all its variations’ sale amount and sale dates).

    This is time consuming during indexing, but lightning fast at query time. But as sale dates are stored at indexing time, re-indexing is necessary every day to update the on sale field when sale dates are no more valid.

    wpsolr
    Keymaster
    3 years, 9 months ago #23339

    You can download the new feature on https://trello.com/c/HrF5cnIU/120-add-woocommerce-on-sale-filter

    Instructions:
    – Select the new product custom field “wpsolr_on_sale” on screen 2.2
    – Configure the new field on your facets in screen 2.4
    – Reindex your products

    Features:
    – Use the cron extension https://www.wpsolr.com/guide/configuration-step-by-step-schematic/activate-extensions/cron-scheduling/ to reindex your data every day to keep the “on sale” dates up to date
    – Adds a new “on sale” facet
    – Hide variation attributes that are not on sale (if at least one product’s variation has a blue color on sale, the blue color facet will be shown).

    wpsolr
    Keymaster
    mcl7
    Participant
    2 years, 9 months ago #28726

    Im trying to get this exact thing to work but when I follow the instructions above I get the following error:

    Error on line 794 of file /www/mysite/public/wp-content/plugins/wpsolr-pro/wpsolr/pro/extensions/woocommerce/class-wpsolr-plugin-woocommerce.php: Trying to get property ‘name’ of non-object

Viewing 15 posts - 1 through 15 (of 21 total)

You must be logged in to reply to this topic.