Plugin Directory

Changeset 3257859


Ignore:
Timestamp:
03/18/2025 01:44:00 PM (11 months ago)
Author:
wpengine
Message:

Tagging version 0.2.74

Location:
atlas-search
Files:
14 added
16 deleted
26 edited
1 copied

Legend:

Unmodified
Added
Removed
  • atlas-search/tags/0.2.74/README.txt

    r3247243 r3257859  
    33Tested up to: 6.7.1
    44Requires PHP: 7.4
    5 Stable tag: 0.2.72
     5Stable tag: 0.2.74
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5656
    5757== Changelog ==
     58= 0.2.74 =
     59* **Updated:** Drop search facet in favour of the built in search inputs for WordPress and WooCommerce
     60* **Fixed:** Support for gravitysmtp plugin
     61
     62= 0.2.73 =
     63* **Updated:** Removed Feature Flag for Recommendations Block
     64* **Fixed:** Dont send woo attributes with empty name
     65* **Updated:** Update header logos
     66
    5867= 0.2.72 =
    5968* **Added:** Checkbox Facet
  • atlas-search/tags/0.2.74/atlas-search.php

    r3247243 r3257859  
    1616 * Plugin URI:        https://developers.wpengine.com/
    1717 * Description:       Searching WordPress data with WP Engine Smart Search.
    18  * Version:           0.2.72
     18 * Version:           0.2.74
    1919 * Author:            WP Engine
    2020 * Author URI:        https://wpengine.com/
     
    4141 * Rename this for your plugin and update it as you release new versions.
    4242 */
    43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.72' );
     43define( 'WPE_SMART_SEARCH_VERSION', '0.2.74' );
    4444
    4545/**
  • atlas-search/tags/0.2.74/build/blocks-callbacks.php

    r3247243 r3257859  
    22
    33namespace AtlasSearch\Blocks\WordPress;
     4
     5use WP_HTML_Tag_Processor;
    46
    57/**
     
    2022        $this->loader->add_action( 'init', $this, 'register_facet_blocks' );
    2123        $this->loader->add_filter( 'block_categories_all', $this, 'register_block_categories', 10, 2 );
     24        $this->loader->add_filter( 'render_block', $this, 'core_search', 10, 2 );
     25    }
     26
     27    public function core_search( $block_content, $block ) {
     28        if ( 'core/search' !== $block['blockName'] ) {
     29            return $block_content;
     30        }
     31
     32        // Use WP_HTML_Tag_Processor to modify the button's HTML output.
     33        $p = new WP_HTML_Tag_Processor( $block_content );
     34        $p->next_tag(); // Move to the first tag in block_content (should be <form>).
     35
     36        // Attach Interactivity API directives.
     37        $p->set_attribute( 'data-wp-interactive', '{ "namespace": "wpengine-smart-search-facets__store" }' );
     38        $p->set_attribute( 'data-wp-on--submit', 'actions.performSearch' );
     39        $p->set_attribute( 'data-wp-init', 'actions.initFacets' );
     40
     41        $p->next_tag( array( 'tag_name' => 'input' ) );
     42        $p->set_attribute( 'data-wp-on--input', 'actions.setSearchValue' );
     43
     44        // Return the modified button block content.
     45        return $p->get_updated_html();
    2246    }
    2347
    2448    public function register_facet_blocks() {
    2549        if ( ! get_option( self::SMART_SEARCH_BLOCKS_SUPPORT_ENABLED_OPTION, false ) ) {
    26             return;
     50            $blocks = array(
     51                'recommendations-block',
     52            );
     53        } else {
     54            $blocks = array(
     55                'filter-facet',
     56                'recommendations-block',
     57            );
    2758        }
    28 
    29         $blocks = array(
    30             'search-facet',
    31             'filter-facet',
    32             'recommendations-block',
    33         );
    3459
    3560        foreach ( $blocks as $block ) {
  • atlas-search/tags/0.2.74/build/filter-facet/view.asset.php

    r3247243 r3257859  
    1 <?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '743cba50d4149080fcc1', 'type' => 'module');
     1<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '0f28e1b1e27b7252eae1', 'type' => 'module');
  • atlas-search/tags/0.2.74/build/filter-facet/view.js

    r3247243 r3257859  
    1 import*as e from"@wordpress/interactivity";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},r={};t.d(r,{o:()=>b,w:()=>m});const n=(a={getContext:()=>e.getContext,getElement:()=>e.getElement,store:()=>e.store},c={},t.d(c,a),c),o="wpengine-smart-search-facets__store";var a,c;function i(e){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i(e)}function s(e,t,r){return(t=function(e){var t=function(e){if("object"!=i(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==i(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){s(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const f="__wpengine-smart-search_FacetsStoreInstance__";function p(){return globalThis[f]}var y;p()||(y=(0,n.store)(o,{state:{filters:[],get allFilters(){return p().state.filters}},actions:{updateFilter(e){let{filterName:t,value:r}=e;""===r?delete p().state.filters[t]:p().state.filters[t]=r},setSearchValue(){const{ref:e}=(0,n.getElement)(),{value:t}=e;p().state.searchValue=t},*performSearch(e){e.preventDefault();const t=u(u({},p().state.filters),{},{s:p().state.searchValue});yield(async e=>{const t="".concat(window.location.origin,"/"),r=new URL(t);Object.keys(e).forEach((t=>{void 0!==e[t]&&null!==e[t]&&r.searchParams.set(t,e[t])})),window.location.assign(r.toString())})(t)}}}),globalThis[f]=y),p();const{actions:b,state:m}=(0,n.store)(o,{actions:{initDropdownFacet:function(){const e=(0,n.getContext)(),t=function(){const e={};return new URLSearchParams(window.location.search).forEach(((t,r)=>{t.includes(",")&&(t=t.split(",")),e[r]=t})),e}();t[e.selected_data_source_mapped]&&!Array.isArray(t[e.selected_data_source_mapped])&&(e.value=t[e.selected_data_source_mapped])},setDropdownValue:function(e){e.preventDefault();const{value:t,name:r}=e.target;b.updateFilter({filterName:r,value:t})},setCheckboxValue:function(e){e.preventDefault();const{value:t,name:r,checked:n}=e.target,o=[].concat(m.allFilters[r]||[]);n?o.includes(t)||o.push(t):o.splice(o.indexOf(t),1),b.updateFilter({filterName:r,value:o})}}});var d=r.o,v=r.w;export{d as actions,v as state};
     1import*as e from"@wordpress/interactivity";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},r={};t.d(r,{o:()=>b,w:()=>d});const n=(a={getContext:()=>e.getContext,getElement:()=>e.getElement,store:()=>e.store},c={},t.d(c,a),c),o="wpengine-smart-search-facets__store";var a,c;function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function i(e,t,r){return(t=function(e){var t=function(e){if("object"!=s(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=s(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==s(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function f(){const e={};return new URLSearchParams(window.location.search).forEach(((t,r)=>{t.includes(",")&&(t=t.split(",")),e[r]=t})),e}const p="__wpengine-smart-search_FacetsStoreInstance__";function y(){return globalThis[p]}var m;y()||(m=(0,n.store)(o,{state:{filters:[],get allFilters(){return y().state.filters}},actions:{initFacets:function(){const{actions:e,state:t}=y(),r=f();for(const n in r)if(r[n]){const o=r[n];"s"===n&&(t.searchValue=o),e.updateFilter({filterName:n,value:o})}},updateFilter(e){let{filterName:t,value:r}=e;""===r?delete y().state.filters[t]:y().state.filters[t]=r},setSearchValue(){const{ref:e}=(0,n.getElement)(),{value:t}=e;y().state.searchValue=t},*performSearch(e){e.preventDefault();const t=e.target.querySelectorAll('input[type="hidden"]'),r={};t.forEach((e=>{r[e.name]=e.value}));const n=u(u({},y().state.filters),{},{s:y().state.searchValue},r);yield(async e=>{const t=new URL(window.location.href);Object.keys(e).forEach((r=>{void 0!==e[r]&&null!==e[r]&&t.searchParams.set(r,e[r])})),window.location.assign(t.toString())})(n)}}}),globalThis[p]=m),y();const{actions:b,state:d}=(0,n.store)(o,{actions:{initDropdownFacet:function(){const e=(0,n.getContext)(),t=f();t[e.selected_data_source_mapped]&&!Array.isArray(t[e.selected_data_source_mapped])&&(e.value=t[e.selected_data_source_mapped])},setDropdownValue:function(e){e.preventDefault();const{value:t,name:r}=e.target;b.updateFilter({filterName:r,value:t})},setCheckboxValue:function(e){e.preventDefault();const{value:t,name:r,checked:n}=e.target,o=[].concat(d.allFilters[r]||[]);n?o.includes(t)||o.push(t):o.splice(o.indexOf(t),1),b.updateFilter({filterName:r,value:o})}}});var v=r.o,g=r.w;export{v as actions,g as state};
  • atlas-search/tags/0.2.74/includes/class-wpe-content-engine.php

    r3247243 r3257859  
    228228        require_once plugin_dir_path( __DIR__ ) . 'src/support/woocommerce/queries.php';
    229229        require_once plugin_dir_path( __DIR__ ) . 'src/support/fusion/filters.php';
     230        require_once plugin_dir_path( __DIR__ ) . 'src/support/gravitysmtp/filters.php';
    230231    }
    231232
  • atlas-search/tags/0.2.74/includes/smart-search-settings/build/asset-manifest.json

    r3239389 r3257859  
    22  "files": {
    33    "main.css": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.4b9ef208.css",
    4     "main.js": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.b72487ed.js",
    5     "static/media/wpengine-logo.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/wpengine-logo.40f3a1215fbea4708a6a4bff9624fece.svg",
     4    "main.js": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.56be2d56.js",
     5    "static/media/wpengine-logo.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/wpengine-logo.f4b93ff2e9c94a93817d81f14e73235a.svg",
     6    "static/media/search-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/search-icon.553693483eece21ac1f02866dbcf436b.svg",
    67    "static/media/content-copy.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/content-copy.e50f17791e757794684afc63d5d4cb00.svg",
    78    "static/media/delete-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/delete-icon.8fe170c40cab65513a25239b397ceb99.svg",
     
    1213    "static/media/info-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/info-icon.30042d2143dbaf9927d68a3c375ea5e2.svg",
    1314    "static/media/success-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/success-icon.1fbd8c959e7200e8770179c3482d0471.svg",
    14     "static/media/search-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/search-icon.553693483eece21ac1f02866dbcf436b.svg",
    1515    "static/media/reload-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/reload-icon.ce27213a21c8637e2aff195d52baa50f.svg",
    1616    "static/media/expand-more.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/expand-more.a67cb7a584a759832f8e699e45b044f5.svg",
     
    1818    "index.html": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/index.html",
    1919    "main.4b9ef208.css.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.4b9ef208.css.map",
    20     "main.b72487ed.js.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.b72487ed.js.map"
     20    "main.56be2d56.js.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.56be2d56.js.map"
    2121  },
    2222  "entrypoints": [
    2323    "static/css/main.4b9ef208.css",
    24     "static/js/main.b72487ed.js"
     24    "static/js/main.56be2d56.js"
    2525  ]
    2626}
  • atlas-search/tags/0.2.74/includes/smart-search-settings/build/index.html

    r3239389 r3257859  
    1 <head><script defer="defer" src="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.b72487ed.js"></script><link href="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.4b9ef208.css" rel="stylesheet"></head>
     1<head><script defer="defer" src="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.56be2d56.js"></script><link href="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.4b9ef208.css" rel="stylesheet"></head>
  • atlas-search/tags/0.2.74/src/blocks/blocks-callbacks.php

    r3247243 r3257859  
    22
    33namespace AtlasSearch\Blocks\WordPress;
     4
     5use WP_HTML_Tag_Processor;
    46
    57/**
     
    2022        $this->loader->add_action( 'init', $this, 'register_facet_blocks' );
    2123        $this->loader->add_filter( 'block_categories_all', $this, 'register_block_categories', 10, 2 );
     24        $this->loader->add_filter( 'render_block', $this, 'core_search', 10, 2 );
     25    }
     26
     27    public function core_search( $block_content, $block ) {
     28        if ( 'core/search' !== $block['blockName'] ) {
     29            return $block_content;
     30        }
     31
     32        // Use WP_HTML_Tag_Processor to modify the button's HTML output.
     33        $p = new WP_HTML_Tag_Processor( $block_content );
     34        $p->next_tag(); // Move to the first tag in block_content (should be <form>).
     35
     36        // Attach Interactivity API directives.
     37        $p->set_attribute( 'data-wp-interactive', '{ "namespace": "wpengine-smart-search-facets__store" }' );
     38        $p->set_attribute( 'data-wp-on--submit', 'actions.performSearch' );
     39        $p->set_attribute( 'data-wp-init', 'actions.initFacets' );
     40
     41        $p->next_tag( array( 'tag_name' => 'input' ) );
     42        $p->set_attribute( 'data-wp-on--input', 'actions.setSearchValue' );
     43
     44        // Return the modified button block content.
     45        return $p->get_updated_html();
    2246    }
    2347
    2448    public function register_facet_blocks() {
    2549        if ( ! get_option( self::SMART_SEARCH_BLOCKS_SUPPORT_ENABLED_OPTION, false ) ) {
    26             return;
     50            $blocks = array(
     51                'recommendations-block',
     52            );
     53        } else {
     54            $blocks = array(
     55                'filter-facet',
     56                'recommendations-block',
     57            );
    2758        }
    28 
    29         $blocks = array(
    30             'search-facet',
    31             'filter-facet',
    32             'recommendations-block',
    33         );
    3459
    3560        foreach ( $blocks as $block ) {
  • atlas-search/tags/0.2.74/src/blocks/stores/facets.store.js

    r3247243 r3257859  
    11import { store, getElement } from '@wordpress/interactivity';
    22import { config } from '../config';
     3import { getFiltersFromURL } from '../utils/getFiltersFromURL';
    34
    45export const updateURL = async (params) => {
    5   const baseUrl = `${window.location.origin}/`;
    6   const url = new URL(baseUrl);
     6  const url = new URL(window.location.href);
    77
    88  // Set search parameters
     
    1515};
    1616
    17 const FACETS_STORE_KEY = '__wpengine-smart-search_FacetsStoreInstance__';
     17export const FACETS_STORE_KEY = '__wpengine-smart-search_FacetsStoreInstance__';
    1818
    1919// Method to get the singleton instance
     
    3838        },
    3939        actions: {
     40          initFacets: function () {
     41            const { actions, state } = getInstance();
     42            const filters = getFiltersFromURL();
     43            for (const key in filters) {
     44              if (filters[key]) {
     45                const value = filters[key];
     46                if (key === 's') {
     47                  state.searchValue = value; // Set the state to the search query
     48                }
     49                actions.updateFilter({ filterName: key, value });
     50              }
     51            }
     52          },
    4053          updateFilter({ filterName, value }) {
    4154            if (value === '') {
     
    5265          *performSearch(e) {
    5366            e.preventDefault();
     67            const hiddenInputs = e.target.querySelectorAll(
     68              'input[type="hidden"]'
     69            );
     70            const hiddenParams = {};
     71            hiddenInputs.forEach((input) => {
     72              hiddenParams[input.name] = input.value;
     73            });
     74
    5475            const params = {
    5576              ...getInstance().state.filters,
    5677              s: getInstance().state.searchValue,
     78              ...hiddenParams,
    5779            };
    5880            yield updateURL(params);
  • atlas-search/tags/0.2.74/src/blocks/stores/facets.store.test.js

    r3139847 r3257859  
    1 import { updateURL } from './facets.store';
     1import { describe } from 'node:test';
     2import { FACETS_STORE_KEY, getFacetsStore, updateURL } from './facets.store';
     3import { store } from '@wordpress/interactivity';
    24// Mocking @wordpress/interactivity module
    35jest.mock('@wordpress/interactivity', () => ({
    4   store: () => ({ state: jest.fn() }),
    5   getElement: jest.fn(),
     6  store: jest.fn(),
     7  getElement: jest.fn(() => ({ ref: { value: 'test search value' } })),
    68}));
    79
    8 describe('updateURL function', () => {
    9   beforeEach(() => {
    10     // Mock window.location.origin and window.location.assign
    11     delete window.location;
    12     window.location = {
    13       origin: 'http://localhost:8000',
    14       assign: jest.fn(),
    15     };
     10jest.mock('../config', () => ({
     11  config: { facetsStoreName: 'testFacetsStore' },
     12}));
     13
     14jest.mock('../utils/getFiltersFromURL', () => ({
     15  getFiltersFromURL: jest.fn(() => ({ s: 'test', category: 'test-category' })),
     16}));
     17
     18describe('facets.store.js', () => {
     19  describe('initFacets', () => {
     20    beforeEach(() => {
     21      globalThis[FACETS_STORE_KEY] = undefined;
     22      store.mockImplementation((name, storeConfig) => {
     23        return {
     24          state: storeConfig.state,
     25          actions: storeConfig.actions,
     26        };
     27      });
     28    });
     29
     30    it('should initialize facets with filters from URL', () => {
     31      const facetsStore = getFacetsStore();
     32      facetsStore.actions.initFacets();
     33
     34      const filters = facetsStore.state.filters;
     35
     36      expect(filters['s']).toEqual('test');
     37      expect(filters['category']).toEqual('test-category');
     38      expect(facetsStore.state.searchValue).toBe('test');
     39    });
    1640  });
    1741
    18   afterEach(() => {
    19     jest.clearAllMocks();
    20   });
     42  describe('updateURL function', () => {
     43    beforeEach(() => {
     44      // Mock window.location.origin and window.location.assign
     45      delete window.location;
     46      window.location = {
     47        origin: 'http://localhost:8000',
     48        href: 'http://localhost:8000',
     49        assign: jest.fn(),
     50      };
     51    });
    2152
    22   it('should update the URL with given parameters', async () => {
    23     const params = {
    24       category_name: 'uncategorized',
    25       search: 'example',
    26     };
     53    afterEach(() => {
     54      jest.clearAllMocks();
     55    });
    2756
    28     await updateURL(params);
     57    it('should update the URL with given parameters', async () => {
     58      const params = {
     59        category_name: 'uncategorized',
     60        search: 'example',
     61      };
    2962
    30     expect(window.location.assign).toHaveBeenCalledWith(
    31       'http://localhost:8000/?category_name=uncategorized&search=example'
    32     );
    33   });
     63      await updateURL(params);
    3464
    35   it('should handle undefined and null values in parameters', async () => {
    36     const params = {
    37       category_name: 'uncategorized',
    38       search: null,
    39       anotherParam: undefined,
    40     };
     65      expect(window.location.assign).toHaveBeenCalledWith(
     66        'http://localhost:8000/?category_name=uncategorized&search=example'
     67      );
     68    });
    4169
    42     await updateURL(params);
     70    it('should handle undefined and null values in parameters', async () => {
     71      const params = {
     72        category_name: 'uncategorized',
     73        search: null,
     74        anotherParam: undefined,
     75      };
    4376
    44     // Should only include 'category_name' in the URL
    45     expect(window.location.assign).toHaveBeenCalledWith(
    46       'http://localhost:8000/?category_name=uncategorized'
    47     );
    48   });
     77      await updateURL(params);
    4978
    50   it('should handle empty parameters', async () => {
    51     await updateURL({});
     79      // Should only include 'category_name' in the URL
     80      expect(window.location.assign).toHaveBeenCalledWith(
     81        'http://localhost:8000/?category_name=uncategorized'
     82      );
     83    });
    5284
    53     expect(window.location.assign).toHaveBeenCalledWith(
    54       'http://localhost:8000/'
    55     );
    56   });
     85    it('should handle empty parameters', async () => {
     86      await updateURL({});
    5787
    58   it('should handle parameters with empty strings', async () => {
    59     const params = {
    60       category_name: '',
    61       search: 'test',
    62     };
     88      expect(window.location.assign).toHaveBeenCalledWith(
     89        'http://localhost:8000/'
     90      );
     91    });
    6392
    64     await updateURL(params);
     93    it('should handle parameters with empty strings', async () => {
     94      const params = {
     95        category_name: '',
     96        search: 'test',
     97      };
    6598
    66     // Should set category_name to an empty string and include 'search' in the URL
    67     expect(window.location.assign).toHaveBeenCalledWith(
    68       'http://localhost:8000/?category_name=&search=test'
    69     );
     99      await updateURL(params);
     100
     101      // Should set category_name to an empty string and include 'search' in the URL
     102      expect(window.location.assign).toHaveBeenCalledWith(
     103        'http://localhost:8000/?category_name=&search=test'
     104      );
     105    });
    70106  });
    71107});
  • atlas-search/tags/0.2.74/src/blocks/utils/getFiltersFromURL.test.js

    r3139847 r3257859  
    77    window.location = {
    88      origin: 'http://localhost:8000',
     9      href: 'http://localhost:8000',
    910      search: '',
    1011    };
  • atlas-search/tags/0.2.74/src/support/woocommerce/fields.php

    r3239389 r3257859  
    6060        $attributes = array();
    6161        foreach ( $data['attributes'] as $attribute ) {
    62             if ( isset( $attribute['name'] ) && taxonomy_exists( $attribute['name'] ) ) {
     62            if ( ! empty( $attribute['name'] ) && taxonomy_exists( $attribute['name'] ) ) {
    6363                // Fetch terms for the attribute.
    6464                // We need to treat these as taxonomies.
     
    7070                    wp_get_post_terms( $wc_product->get_id(), $attribute['name'] )
    7171                );
    72             } elseif ( isset( $attribute['name'], $attribute['options'] ) ) {
     72            } elseif ( ! empty( $attribute['name'] ) && isset( $attribute['options'] ) ) {
    7373                $attributes[ $attribute['name'] ] = $attribute['options'];
    7474            }
  • atlas-search/trunk/README.txt

    r3247243 r3257859  
    33Tested up to: 6.7.1
    44Requires PHP: 7.4
    5 Stable tag: 0.2.72
     5Stable tag: 0.2.74
    66License: GPLv2 or later
    77License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5656
    5757== Changelog ==
     58= 0.2.74 =
     59* **Updated:** Drop search facet in favour of the built in search inputs for WordPress and WooCommerce
     60* **Fixed:** Support for gravitysmtp plugin
     61
     62= 0.2.73 =
     63* **Updated:** Removed Feature Flag for Recommendations Block
     64* **Fixed:** Dont send woo attributes with empty name
     65* **Updated:** Update header logos
     66
    5867= 0.2.72 =
    5968* **Added:** Checkbox Facet
  • atlas-search/trunk/atlas-search.php

    r3247243 r3257859  
    1616 * Plugin URI:        https://developers.wpengine.com/
    1717 * Description:       Searching WordPress data with WP Engine Smart Search.
    18  * Version:           0.2.72
     18 * Version:           0.2.74
    1919 * Author:            WP Engine
    2020 * Author URI:        https://wpengine.com/
     
    4141 * Rename this for your plugin and update it as you release new versions.
    4242 */
    43 define( 'WPE_SMART_SEARCH_VERSION', '0.2.72' );
     43define( 'WPE_SMART_SEARCH_VERSION', '0.2.74' );
    4444
    4545/**
  • atlas-search/trunk/build/blocks-callbacks.php

    r3247243 r3257859  
    22
    33namespace AtlasSearch\Blocks\WordPress;
     4
     5use WP_HTML_Tag_Processor;
    46
    57/**
     
    2022        $this->loader->add_action( 'init', $this, 'register_facet_blocks' );
    2123        $this->loader->add_filter( 'block_categories_all', $this, 'register_block_categories', 10, 2 );
     24        $this->loader->add_filter( 'render_block', $this, 'core_search', 10, 2 );
     25    }
     26
     27    public function core_search( $block_content, $block ) {
     28        if ( 'core/search' !== $block['blockName'] ) {
     29            return $block_content;
     30        }
     31
     32        // Use WP_HTML_Tag_Processor to modify the button's HTML output.
     33        $p = new WP_HTML_Tag_Processor( $block_content );
     34        $p->next_tag(); // Move to the first tag in block_content (should be <form>).
     35
     36        // Attach Interactivity API directives.
     37        $p->set_attribute( 'data-wp-interactive', '{ "namespace": "wpengine-smart-search-facets__store" }' );
     38        $p->set_attribute( 'data-wp-on--submit', 'actions.performSearch' );
     39        $p->set_attribute( 'data-wp-init', 'actions.initFacets' );
     40
     41        $p->next_tag( array( 'tag_name' => 'input' ) );
     42        $p->set_attribute( 'data-wp-on--input', 'actions.setSearchValue' );
     43
     44        // Return the modified button block content.
     45        return $p->get_updated_html();
    2246    }
    2347
    2448    public function register_facet_blocks() {
    2549        if ( ! get_option( self::SMART_SEARCH_BLOCKS_SUPPORT_ENABLED_OPTION, false ) ) {
    26             return;
     50            $blocks = array(
     51                'recommendations-block',
     52            );
     53        } else {
     54            $blocks = array(
     55                'filter-facet',
     56                'recommendations-block',
     57            );
    2758        }
    28 
    29         $blocks = array(
    30             'search-facet',
    31             'filter-facet',
    32             'recommendations-block',
    33         );
    3459
    3560        foreach ( $blocks as $block ) {
  • atlas-search/trunk/build/filter-facet/view.asset.php

    r3247243 r3257859  
    1 <?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '743cba50d4149080fcc1', 'type' => 'module');
     1<?php return array('dependencies' => array('@wordpress/interactivity'), 'version' => '0f28e1b1e27b7252eae1', 'type' => 'module');
  • atlas-search/trunk/build/filter-facet/view.js

    r3247243 r3257859  
    1 import*as e from"@wordpress/interactivity";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},r={};t.d(r,{o:()=>b,w:()=>m});const n=(a={getContext:()=>e.getContext,getElement:()=>e.getElement,store:()=>e.store},c={},t.d(c,a),c),o="wpengine-smart-search-facets__store";var a,c;function i(e){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},i(e)}function s(e,t,r){return(t=function(e){var t=function(e){if("object"!=i(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==i(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){s(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}const f="__wpengine-smart-search_FacetsStoreInstance__";function p(){return globalThis[f]}var y;p()||(y=(0,n.store)(o,{state:{filters:[],get allFilters(){return p().state.filters}},actions:{updateFilter(e){let{filterName:t,value:r}=e;""===r?delete p().state.filters[t]:p().state.filters[t]=r},setSearchValue(){const{ref:e}=(0,n.getElement)(),{value:t}=e;p().state.searchValue=t},*performSearch(e){e.preventDefault();const t=u(u({},p().state.filters),{},{s:p().state.searchValue});yield(async e=>{const t="".concat(window.location.origin,"/"),r=new URL(t);Object.keys(e).forEach((t=>{void 0!==e[t]&&null!==e[t]&&r.searchParams.set(t,e[t])})),window.location.assign(r.toString())})(t)}}}),globalThis[f]=y),p();const{actions:b,state:m}=(0,n.store)(o,{actions:{initDropdownFacet:function(){const e=(0,n.getContext)(),t=function(){const e={};return new URLSearchParams(window.location.search).forEach(((t,r)=>{t.includes(",")&&(t=t.split(",")),e[r]=t})),e}();t[e.selected_data_source_mapped]&&!Array.isArray(t[e.selected_data_source_mapped])&&(e.value=t[e.selected_data_source_mapped])},setDropdownValue:function(e){e.preventDefault();const{value:t,name:r}=e.target;b.updateFilter({filterName:r,value:t})},setCheckboxValue:function(e){e.preventDefault();const{value:t,name:r,checked:n}=e.target,o=[].concat(m.allFilters[r]||[]);n?o.includes(t)||o.push(t):o.splice(o.indexOf(t),1),b.updateFilter({filterName:r,value:o})}}});var d=r.o,v=r.w;export{d as actions,v as state};
     1import*as e from"@wordpress/interactivity";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},r={};t.d(r,{o:()=>b,w:()=>d});const n=(a={getContext:()=>e.getContext,getElement:()=>e.getElement,store:()=>e.store},c={},t.d(c,a),c),o="wpengine-smart-search-facets__store";var a,c;function s(e){return s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},s(e)}function i(e,t,r){return(t=function(e){var t=function(e){if("object"!=s(e)||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var r=t.call(e,"string");if("object"!=s(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==s(t)?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach((function(t){i(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function f(){const e={};return new URLSearchParams(window.location.search).forEach(((t,r)=>{t.includes(",")&&(t=t.split(",")),e[r]=t})),e}const p="__wpengine-smart-search_FacetsStoreInstance__";function y(){return globalThis[p]}var m;y()||(m=(0,n.store)(o,{state:{filters:[],get allFilters(){return y().state.filters}},actions:{initFacets:function(){const{actions:e,state:t}=y(),r=f();for(const n in r)if(r[n]){const o=r[n];"s"===n&&(t.searchValue=o),e.updateFilter({filterName:n,value:o})}},updateFilter(e){let{filterName:t,value:r}=e;""===r?delete y().state.filters[t]:y().state.filters[t]=r},setSearchValue(){const{ref:e}=(0,n.getElement)(),{value:t}=e;y().state.searchValue=t},*performSearch(e){e.preventDefault();const t=e.target.querySelectorAll('input[type="hidden"]'),r={};t.forEach((e=>{r[e.name]=e.value}));const n=u(u({},y().state.filters),{},{s:y().state.searchValue},r);yield(async e=>{const t=new URL(window.location.href);Object.keys(e).forEach((r=>{void 0!==e[r]&&null!==e[r]&&t.searchParams.set(r,e[r])})),window.location.assign(t.toString())})(n)}}}),globalThis[p]=m),y();const{actions:b,state:d}=(0,n.store)(o,{actions:{initDropdownFacet:function(){const e=(0,n.getContext)(),t=f();t[e.selected_data_source_mapped]&&!Array.isArray(t[e.selected_data_source_mapped])&&(e.value=t[e.selected_data_source_mapped])},setDropdownValue:function(e){e.preventDefault();const{value:t,name:r}=e.target;b.updateFilter({filterName:r,value:t})},setCheckboxValue:function(e){e.preventDefault();const{value:t,name:r,checked:n}=e.target,o=[].concat(d.allFilters[r]||[]);n?o.includes(t)||o.push(t):o.splice(o.indexOf(t),1),b.updateFilter({filterName:r,value:o})}}});var v=r.o,g=r.w;export{v as actions,g as state};
  • atlas-search/trunk/includes/class-wpe-content-engine.php

    r3247243 r3257859  
    228228        require_once plugin_dir_path( __DIR__ ) . 'src/support/woocommerce/queries.php';
    229229        require_once plugin_dir_path( __DIR__ ) . 'src/support/fusion/filters.php';
     230        require_once plugin_dir_path( __DIR__ ) . 'src/support/gravitysmtp/filters.php';
    230231    }
    231232
  • atlas-search/trunk/includes/smart-search-settings/build/asset-manifest.json

    r3239389 r3257859  
    22  "files": {
    33    "main.css": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.4b9ef208.css",
    4     "main.js": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.b72487ed.js",
    5     "static/media/wpengine-logo.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/wpengine-logo.40f3a1215fbea4708a6a4bff9624fece.svg",
     4    "main.js": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.56be2d56.js",
     5    "static/media/wpengine-logo.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/wpengine-logo.f4b93ff2e9c94a93817d81f14e73235a.svg",
     6    "static/media/search-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/search-icon.553693483eece21ac1f02866dbcf436b.svg",
    67    "static/media/content-copy.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/content-copy.e50f17791e757794684afc63d5d4cb00.svg",
    78    "static/media/delete-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/delete-icon.8fe170c40cab65513a25239b397ceb99.svg",
     
    1213    "static/media/info-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/info-icon.30042d2143dbaf9927d68a3c375ea5e2.svg",
    1314    "static/media/success-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/success-icon.1fbd8c959e7200e8770179c3482d0471.svg",
    14     "static/media/search-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/search-icon.553693483eece21ac1f02866dbcf436b.svg",
    1515    "static/media/reload-icon.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/reload-icon.ce27213a21c8637e2aff195d52baa50f.svg",
    1616    "static/media/expand-more.svg": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/media/expand-more.a67cb7a584a759832f8e699e45b044f5.svg",
     
    1818    "index.html": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/index.html",
    1919    "main.4b9ef208.css.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.4b9ef208.css.map",
    20     "main.b72487ed.js.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.b72487ed.js.map"
     20    "main.56be2d56.js.map": "/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.56be2d56.js.map"
    2121  },
    2222  "entrypoints": [
    2323    "static/css/main.4b9ef208.css",
    24     "static/js/main.b72487ed.js"
     24    "static/js/main.56be2d56.js"
    2525  ]
    2626}
  • atlas-search/trunk/includes/smart-search-settings/build/index.html

    r3239389 r3257859  
    1 <head><script defer="defer" src="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.b72487ed.js"></script><link href="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.4b9ef208.css" rel="stylesheet"></head>
     1<head><script defer="defer" src="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/js/main.56be2d56.js"></script><link href="/wp-content/plugins/atlas-search/includes/smart-search-settings/build/static/css/main.4b9ef208.css" rel="stylesheet"></head>
  • atlas-search/trunk/src/blocks/blocks-callbacks.php

    r3247243 r3257859  
    22
    33namespace AtlasSearch\Blocks\WordPress;
     4
     5use WP_HTML_Tag_Processor;
    46
    57/**
     
    2022        $this->loader->add_action( 'init', $this, 'register_facet_blocks' );
    2123        $this->loader->add_filter( 'block_categories_all', $this, 'register_block_categories', 10, 2 );
     24        $this->loader->add_filter( 'render_block', $this, 'core_search', 10, 2 );
     25    }
     26
     27    public function core_search( $block_content, $block ) {
     28        if ( 'core/search' !== $block['blockName'] ) {
     29            return $block_content;
     30        }
     31
     32        // Use WP_HTML_Tag_Processor to modify the button's HTML output.
     33        $p = new WP_HTML_Tag_Processor( $block_content );
     34        $p->next_tag(); // Move to the first tag in block_content (should be <form>).
     35
     36        // Attach Interactivity API directives.
     37        $p->set_attribute( 'data-wp-interactive', '{ "namespace": "wpengine-smart-search-facets__store" }' );
     38        $p->set_attribute( 'data-wp-on--submit', 'actions.performSearch' );
     39        $p->set_attribute( 'data-wp-init', 'actions.initFacets' );
     40
     41        $p->next_tag( array( 'tag_name' => 'input' ) );
     42        $p->set_attribute( 'data-wp-on--input', 'actions.setSearchValue' );
     43
     44        // Return the modified button block content.
     45        return $p->get_updated_html();
    2246    }
    2347
    2448    public function register_facet_blocks() {
    2549        if ( ! get_option( self::SMART_SEARCH_BLOCKS_SUPPORT_ENABLED_OPTION, false ) ) {
    26             return;
     50            $blocks = array(
     51                'recommendations-block',
     52            );
     53        } else {
     54            $blocks = array(
     55                'filter-facet',
     56                'recommendations-block',
     57            );
    2758        }
    28 
    29         $blocks = array(
    30             'search-facet',
    31             'filter-facet',
    32             'recommendations-block',
    33         );
    3459
    3560        foreach ( $blocks as $block ) {
  • atlas-search/trunk/src/blocks/stores/facets.store.js

    r3247243 r3257859  
    11import { store, getElement } from '@wordpress/interactivity';
    22import { config } from '../config';
     3import { getFiltersFromURL } from '../utils/getFiltersFromURL';
    34
    45export const updateURL = async (params) => {
    5   const baseUrl = `${window.location.origin}/`;
    6   const url = new URL(baseUrl);
     6  const url = new URL(window.location.href);
    77
    88  // Set search parameters
     
    1515};
    1616
    17 const FACETS_STORE_KEY = '__wpengine-smart-search_FacetsStoreInstance__';
     17export const FACETS_STORE_KEY = '__wpengine-smart-search_FacetsStoreInstance__';
    1818
    1919// Method to get the singleton instance
     
    3838        },
    3939        actions: {
     40          initFacets: function () {
     41            const { actions, state } = getInstance();
     42            const filters = getFiltersFromURL();
     43            for (const key in filters) {
     44              if (filters[key]) {
     45                const value = filters[key];
     46                if (key === 's') {
     47                  state.searchValue = value; // Set the state to the search query
     48                }
     49                actions.updateFilter({ filterName: key, value });
     50              }
     51            }
     52          },
    4053          updateFilter({ filterName, value }) {
    4154            if (value === '') {
     
    5265          *performSearch(e) {
    5366            e.preventDefault();
     67            const hiddenInputs = e.target.querySelectorAll(
     68              'input[type="hidden"]'
     69            );
     70            const hiddenParams = {};
     71            hiddenInputs.forEach((input) => {
     72              hiddenParams[input.name] = input.value;
     73            });
     74
    5475            const params = {
    5576              ...getInstance().state.filters,
    5677              s: getInstance().state.searchValue,
     78              ...hiddenParams,
    5779            };
    5880            yield updateURL(params);
  • atlas-search/trunk/src/blocks/stores/facets.store.test.js

    r3139847 r3257859  
    1 import { updateURL } from './facets.store';
     1import { describe } from 'node:test';
     2import { FACETS_STORE_KEY, getFacetsStore, updateURL } from './facets.store';
     3import { store } from '@wordpress/interactivity';
    24// Mocking @wordpress/interactivity module
    35jest.mock('@wordpress/interactivity', () => ({
    4   store: () => ({ state: jest.fn() }),
    5   getElement: jest.fn(),
     6  store: jest.fn(),
     7  getElement: jest.fn(() => ({ ref: { value: 'test search value' } })),
    68}));
    79
    8 describe('updateURL function', () => {
    9   beforeEach(() => {
    10     // Mock window.location.origin and window.location.assign
    11     delete window.location;
    12     window.location = {
    13       origin: 'http://localhost:8000',
    14       assign: jest.fn(),
    15     };
     10jest.mock('../config', () => ({
     11  config: { facetsStoreName: 'testFacetsStore' },
     12}));
     13
     14jest.mock('../utils/getFiltersFromURL', () => ({
     15  getFiltersFromURL: jest.fn(() => ({ s: 'test', category: 'test-category' })),
     16}));
     17
     18describe('facets.store.js', () => {
     19  describe('initFacets', () => {
     20    beforeEach(() => {
     21      globalThis[FACETS_STORE_KEY] = undefined;
     22      store.mockImplementation((name, storeConfig) => {
     23        return {
     24          state: storeConfig.state,
     25          actions: storeConfig.actions,
     26        };
     27      });
     28    });
     29
     30    it('should initialize facets with filters from URL', () => {
     31      const facetsStore = getFacetsStore();
     32      facetsStore.actions.initFacets();
     33
     34      const filters = facetsStore.state.filters;
     35
     36      expect(filters['s']).toEqual('test');
     37      expect(filters['category']).toEqual('test-category');
     38      expect(facetsStore.state.searchValue).toBe('test');
     39    });
    1640  });
    1741
    18   afterEach(() => {
    19     jest.clearAllMocks();
    20   });
     42  describe('updateURL function', () => {
     43    beforeEach(() => {
     44      // Mock window.location.origin and window.location.assign
     45      delete window.location;
     46      window.location = {
     47        origin: 'http://localhost:8000',
     48        href: 'http://localhost:8000',
     49        assign: jest.fn(),
     50      };
     51    });
    2152
    22   it('should update the URL with given parameters', async () => {
    23     const params = {
    24       category_name: 'uncategorized',
    25       search: 'example',
    26     };
     53    afterEach(() => {
     54      jest.clearAllMocks();
     55    });
    2756
    28     await updateURL(params);
     57    it('should update the URL with given parameters', async () => {
     58      const params = {
     59        category_name: 'uncategorized',
     60        search: 'example',
     61      };
    2962
    30     expect(window.location.assign).toHaveBeenCalledWith(
    31       'http://localhost:8000/?category_name=uncategorized&search=example'
    32     );
    33   });
     63      await updateURL(params);
    3464
    35   it('should handle undefined and null values in parameters', async () => {
    36     const params = {
    37       category_name: 'uncategorized',
    38       search: null,
    39       anotherParam: undefined,
    40     };
     65      expect(window.location.assign).toHaveBeenCalledWith(
     66        'http://localhost:8000/?category_name=uncategorized&search=example'
     67      );
     68    });
    4169
    42     await updateURL(params);
     70    it('should handle undefined and null values in parameters', async () => {
     71      const params = {
     72        category_name: 'uncategorized',
     73        search: null,
     74        anotherParam: undefined,
     75      };
    4376
    44     // Should only include 'category_name' in the URL
    45     expect(window.location.assign).toHaveBeenCalledWith(
    46       'http://localhost:8000/?category_name=uncategorized'
    47     );
    48   });
     77      await updateURL(params);
    4978
    50   it('should handle empty parameters', async () => {
    51     await updateURL({});
     79      // Should only include 'category_name' in the URL
     80      expect(window.location.assign).toHaveBeenCalledWith(
     81        'http://localhost:8000/?category_name=uncategorized'
     82      );
     83    });
    5284
    53     expect(window.location.assign).toHaveBeenCalledWith(
    54       'http://localhost:8000/'
    55     );
    56   });
     85    it('should handle empty parameters', async () => {
     86      await updateURL({});
    5787
    58   it('should handle parameters with empty strings', async () => {
    59     const params = {
    60       category_name: '',
    61       search: 'test',
    62     };
     88      expect(window.location.assign).toHaveBeenCalledWith(
     89        'http://localhost:8000/'
     90      );
     91    });
    6392
    64     await updateURL(params);
     93    it('should handle parameters with empty strings', async () => {
     94      const params = {
     95        category_name: '',
     96        search: 'test',
     97      };
    6598
    66     // Should set category_name to an empty string and include 'search' in the URL
    67     expect(window.location.assign).toHaveBeenCalledWith(
    68       'http://localhost:8000/?category_name=&search=test'
    69     );
     99      await updateURL(params);
     100
     101      // Should set category_name to an empty string and include 'search' in the URL
     102      expect(window.location.assign).toHaveBeenCalledWith(
     103        'http://localhost:8000/?category_name=&search=test'
     104      );
     105    });
    70106  });
    71107});
  • atlas-search/trunk/src/blocks/utils/getFiltersFromURL.test.js

    r3139847 r3257859  
    77    window.location = {
    88      origin: 'http://localhost:8000',
     9      href: 'http://localhost:8000',
    910      search: '',
    1011    };
  • atlas-search/trunk/src/support/woocommerce/fields.php

    r3239389 r3257859  
    6060        $attributes = array();
    6161        foreach ( $data['attributes'] as $attribute ) {
    62             if ( isset( $attribute['name'] ) && taxonomy_exists( $attribute['name'] ) ) {
     62            if ( ! empty( $attribute['name'] ) && taxonomy_exists( $attribute['name'] ) ) {
    6363                // Fetch terms for the attribute.
    6464                // We need to treat these as taxonomies.
     
    7070                    wp_get_post_terms( $wc_product->get_id(), $attribute['name'] )
    7171                );
    72             } elseif ( isset( $attribute['name'], $attribute['options'] ) ) {
     72            } elseif ( ! empty( $attribute['name'] ) && isset( $attribute['options'] ) ) {
    7373                $attributes[ $attribute['name'] ] = $attribute['options'];
    7474            }
Note: See TracChangeset for help on using the changeset viewer.