Commit Graph

156 Commits

Author SHA1 Message Date
Nestor Soriano 9583d57d26
Fix option names used by the product attributes lookup table feature
The feature was using option names prefixed with
"woocommerce_attribute_lookup__". That double underscore breaks WP
standards for option names. The option names have been changed
so that they use a single underscore instead.
2021-07-30 11:16:05 +02:00
Nestor Soriano 48f3adcb32
Fix attributes lookup table creation and usage option name
Fix two bugs related to the product attributes lookup table:

1. The DataRegenerator::check_can_do_lookup_table_regeneration method
   was incorrectly throwing an exception when invoked with no product id
   (this method will always be called without method id in order to
   create the table, and by then the table will not exist).
2. The products - advanced settings page was using the wrong option
   name to enable the feature.
2021-07-26 16:11:37 +02:00
Roy Ho 95abba7eeb
Merge pull request #30041 from woocommerce/add/29609
Sync the product attributes lookup table on product creation/change/deletion
2021-07-16 15:03:54 +01:00
Nestor Soriano 9017c953bd
Remove the metabox for regenerating attribute lookup data for single product
Instead, a product selector has been added to the "Regenerate
product attributes lookup table" entry in the tools page. If a product
is selected, the tool regenerates the data only for that product;
otherwise, it regenerates the entire table.

This has forced a change on how the tools page is rendered. Now,
instead of each tool being just a description and a trigger link,
a form with GET method is rendered for each tool. The forms are rendered
first and then the tools, since HTML doesn't allow to include forms
inside tables; each button is associated to its form with a "form"
attribute.

Additionally, now the tools array returned by the woocommerce_debug_tools`
hook can have a 'selector' array with the details needed to render a
selector, which will also be part of the form for the tool.
2021-07-14 12:01:42 +02:00
Nestor Soriano aa967cab4f
Optimize the query to count products using the attributes lookup table.
The query to count products using the attributes lookup table for the
filter by attribute widget was adding an "AND term_ids in (...)"-type
subquery for each attribute participating in the filtering. Now at most
two such subqueries are generated, one for attributes configured for
OR type filtering and another one for the ones configured as AND; this
speeds up the query significantly when many attributes are used
simultaneously for the filtering.
2021-07-12 10:32:14 +02:00
Nestor Soriano 4b4f9a2b5d
Add missing JOIN parts from tax meta and meta queries.
The SQL query used to calculate the product counts using the product
attributes lookup table for the attribute filtering widget was missing
the JOIN parts coming from the tax meta and meta queries. The WHERE
parts however were being used, so the enitre query could fail if there
was a tax or meta query in place.
2021-07-12 10:23:59 +02:00
Nestor Soriano 70431ead2b
Small adjustments to the per-product lookup data regeneration metabox. 2021-07-01 12:50:30 +02:00
Nestor Soriano 2fe8cce9b0
Fix unit tests for the LookupDataStore class 2021-07-01 12:01:07 +02:00
Nestor Soriano b97e792f40
Move the UI to set/unset product attribute lookup table usage to settings.
The UI was previously in the tools page, it's now a setting under
products - advanced.
2021-06-30 15:14:14 +02:00
Nestor Soriano cf7d96d867
Add a lookup data regeneration for single product mechanism.
A new "Lookup data" metabox has been added to the product page
with a "Renegerate" button that regenerates the attributes lookup
data for that product.
2021-06-30 10:38:20 +02:00
Fitim Vata 3e17c0b618 [Rest] Refunds add api_restock param to restock items 2021-06-30 00:19:23 +02:00
Nestor Soriano 38897a42e2
Add tests for product changes changes in LookupDataStore. 2021-06-28 12:25:48 +02:00
Nestor Soriano 48c44a6128
Add tests for product deletion in LookupDataStoreTest. 2021-06-17 15:31:23 +02:00
Nestor Soriano 0192ed0b93
Change LookupDataStore to allow updates being done in a scheduled action.
There's a new option, 'woocommerce_attribute_lookup__direct_updates'.
When set to 'yes', updates to the lookup table are performed as soon
as the change happen; otherwise, a scheduled action will do it,
the hook name is 'woocommerce_run_product_attribute_lookup_update_callback'
(the existing hook in the DataRegenerator class is renamed to
'woocommerce_run_product_attribute_lookup_update_callback')

Also, the settings page has a new "Advanced" section with a checkbox
to control the value of that new option; the section is visible only
when the feature has been enabled via LookupDataStore::show_feature.
2021-06-15 16:33:29 +02:00
Nestor Soriano 6dbcd64a21
Disable attributes lookup table usage before initiating regeneration. 2021-06-11 11:59:30 +02:00
Nestor Soriano 7c9137698b
Implement handling of changesets in the LookupDataStore class. 2021-06-11 11:44:57 +02:00
Nestor Soriano 13ed3b80e0
Merge branch 'trunk' into add/29609 2021-06-10 12:35:34 +02:00
Nestor Soriano 039f81ea50
Implement the product attributes lookup table data creation.
Lookup entries for a product or a variation are created whenever
the product is created, including untrashing and duplication
(not yet when an existing product is modified).
2021-06-08 17:53:45 +02:00
Barry Hughes c503f5d637
Merge pull request #29896 from woocommerce/add/29610
Filter catalog products by attribute using the new lookup table
2021-06-08 07:37:06 -07:00
Nestor Soriano ef9145de86
Small improvements in the filtering by attribute lookup table.
- Use 'absint' instead of an '(int)' in an anonymous function.
2021-06-08 15:47:04 +02:00
Nestor Soriano 0b1158cf5c
Small improvements in the filtering by attribute lookup table.
- Combined two 'if's in one
- Added extra santitization of term ids in the Filterer class
2021-06-08 10:18:35 +02:00
Nestor Soriano e54ff461f9
Implement the product attributes lookup table data deletion.
Lookup entries for a product or a variation are deleted whenever
the product is deleted or trashed.
2021-06-07 16:54:08 +02:00
Nestor Soriano c6dff96c0f
Undo a wrong change in filtering logic. 2021-06-01 11:25:57 +02:00
Nestor Soriano 9878aa37aa
Add unit tests for the Filterer class (simple products only for now)
Also fix a small issue in the product counters when using "or" filter.
2021-05-28 17:27:03 +02:00
Christopher Allford 070954c888 Revert #28187
The default functionality within the `ThemeSupport` class has an unintended
side-effect of breaking the existing default functionality within the
`wc_get_theme_support()` function. Since the default set in the support
class is prioritized over the one given to `ThemeSupport::get_option()`,
the WordPress options set in the Customizer are never used for images.
2021-05-21 12:10:15 -07:00
roykho 65bbb719b9
Clean up code and update version 2021-05-21 06:32:29 -07:00
Roy Ho 20a73762c5
Update src/Internal/RestockRefundedItemsAdjuster.php
Co-authored-by: Vedanshu Jain <vedanshu.jain.2012@gmail.com>
2021-05-20 13:14:42 -07:00
Roy Ho 41f44578c7
Update src/Internal/RestockRefundedItemsAdjuster.php
Co-authored-by: Vedanshu Jain <vedanshu.jain.2012@gmail.com>
2021-05-20 13:14:35 -07:00
Nestor Soriano e085898fc4
Use the product attributes lookup table for the filter by attribute widget when enabled. 2021-05-14 17:04:25 +02:00
Nestor Soriano 32cce6032d
Add Filterer class and use it when filtering by attributes lookup table usage is enabled. 2021-05-13 12:29:23 +02:00
roykho b808d9a24f
Fix merge conflicts 2021-05-11 08:53:03 -07:00
roykho 8c3e90b3ce
Initialize _restock_refunded_items meta on order update 2021-05-11 08:35:48 -07:00
Nestor Soriano eb2e67d17d
Make the debug tools page entries for attribute filtering hidden by default.
To show the entries the following needs to be run:

wc_get_container()
->get(\Automattic\WooCommerce\Internal\ProductAttributesLookup\LookupDataStore::class)
->show_feature();
2021-05-10 11:32:39 +02:00
Nestor Soriano cdc55bf846
Fix typos in comments 2021-05-07 09:16:45 +02:00
Nestor Soriano f53f959d03
Fix the usage of FakeQueue in DataRegeneratorTest.
Also update the doc comment of FakeQueue itself on how to use it.
2021-05-05 11:11:36 +02:00
Nestor Soriano c4e7074c70
Add unit tests for the DataRegenerator class 2021-05-04 16:15:16 +02:00
Nestor Soriano 4d13b0ca07
ExtendedContainer::replace now allows registering anonymous classes. 2021-05-04 16:14:34 +02:00
Nestor Soriano 42245ed92a
Add unit tests for LookupDataStore::update_data_for_product (variable products) 2021-05-03 11:14:33 +02:00
Nestor Soriano 467af94b1d
Add unit tests for LookupDataStore::update_data_for_product (simple products)
Also:

- Add the FakeQueue class
- Fix LookupDataStore, it was using a hardcoded "wp_" lookup table name
2021-04-30 12:10:25 +02:00
Nestor Soriano e58d26f377
Fix: using "current" on a possibly "false" value. 2021-04-29 16:46:41 +02:00
Nestor Soriano 44cf1648d5
DataRegenerator: show lookup table filling process in tools page.
The status is displayed in the disabled "Regenerate table" button
as follows: "Filling in progress (X)", where X is the number of
products processed so far.
2021-04-29 11:49:43 +02:00
Nestor Soriano eb7fb42888
Add a new debug tools page entry to delete the lookup table.
Also, use $wpdb->prefix instead of hardcoded "wp_" for the table name.
2021-04-29 10:57:31 +02:00
Nestor Soriano 83fed1eab5
Implement the LookupDataStore::create_lookup_table_entries_for_variable_product method. 2021-04-28 16:57:47 +02:00
Nestor Soriano 94f5dfaa11
Make the DataRegenerator::delete_all_attributes_lookup_data method public. 2021-04-28 16:56:29 +02:00
Nestor Soriano 21053afec1
Partially implement LookupDataStore::update_data_for_product
For now it only creates data for non-variable products.
2021-04-28 12:25:56 +02:00
Nestor Soriano d1744ac99a
Add the ProductAttributesLookup\DataRegenerator class.
This class creates and fills the product attributes lookup table
from the existing products. It does so by in small chunks by using
Action Scheduler; it handles all the batches and the scheduling
by itself.

It also adds two entries to the debug tools menu:

- Initiate lookup table regeneration (deleting the existing table first)
- Enable or disable the actual usage of the lookup table
  for product filtering

The first one is the only way to generate the lookup table for now
(there's no explicit data migration).

The actual filling of the table is delegated to a LookupDataStore class
that is not implemented yet, so for now the table isn't actually filled.
Also enabling/disabling the lookup table usage has no real effect yet.
2021-04-28 10:30:11 +02:00
Nestor Soriano 10adec6b88
Improvements in the engine behind the debug tools page.
Two new optional keys have been added to the tool definition array:

- 'disabled': when true the tool button will appear disabled.
- 'needs_refresh': when running a tool, by default the tool definitions
  are retrieved first, then the selected tool is executed,
  then the definitions previously retrieved are rendered.
  When this key is true the tool definitions are retrieved again
  after execution, useful for cases where the tool description
  or button enable/disable state changes after the tool execution.

Also now if a tool execution throws an exception a notice will be
shown with the execption message, previously the exception
was unhandled.
2021-04-28 10:24:23 +02:00
Nestor Soriano 3a895c9eed
Move ThemeSupport class to Internal namespace, and use in 2021 theme. 2021-04-21 12:57:56 +02:00
Nestor Soriano d11a20b5b4
Merge branch 'trunk' into fix/25900-take-2 2021-04-20 16:08:45 +02:00
roykho 78a57e53ec
Update to use closure per review comment 2021-04-20 06:17:50 -07:00