Commit Graph

20265 Commits

Author SHA1 Message Date
Nestor Soriano 9de1306c21 Fix counters in nav filtering widgets for variable products.
After the change that registers variation attributes as terms
(in addition to reigstering them as post meta) it is now time
to modify the get_filtered_term_product_counts methods in
WC_Widget_Layered_Nav so that it works consistently for both
variable and non-variable products. The logic for the counters
is now as follows:

with OR operator:
- Simple products: count the attributes of all visible products
  (unchanged behavior).
- Variable products: count attributes corresponding to
  visible variations.

with AND operator:
- Simple products: count the attributes of visible products but only
  for products that have all the selected (unchanged behavior).
- Variable products: find all the products for which all the variations
  corresponding to the selected attributes exist and are visible,
  then count the attributes corresponding to the visible variations
  of those products.

A product is "visible" if it's published, not excluded for catalog,
and has stock. Additionally, a variable product will not be considered
visible if the parent product is not.
2020-07-28 08:55:55 +02:00
Nestor Soriano 9c6c0d73d8 Record attribute terms for product variations in wp_term_relationships.
Product attributes are currently recorded as terms in
wp_term_relationships (product attributes are actually taxonomies).
In the case of variable products this is true for the main product,
but not for the variations. The attributes used to define variations
are stored as post meta, but nothing is recorded in the term
relationships table.

This is a problem when using the layered nav filtering plugin,
since the attribute counters displayed are calculated based solely
on the contents of the term relationships table. Adding meta queries
would be really messy (especially when the widget is configured
with AND operator) and would probably also hurt performance.

This commit adds a change to store the attributes for variations
as term relationships, additionally to storing them as post meta.
Terms are stored on variation creation, and updated/deleted together
with the variation as appropriate. "Any" variations (stored in meta
as empty values) are not stored as terms.

Additionally, a database upgrade is included in order to backfill
terms for already existing products.
2020-07-28 08:55:55 +02:00
Nestor Soriano 752b47513d Fix code sniffer errors in some files.
Fixed files:

includes/data-stores/class-wc-product-variable-data-store-cpt.php
includes/wc-update-functions.php
2020-07-28 08:55:55 +02:00
Nestor Soriano 50e8f27bc7 Fix visibility of variable products with layered nav filtering.
The layered nav filtering doesn't work well with variable products
when some variations have stock and other don't. When a term is
selected in the widget, a variable product having no stock for
the variation corresponding to that term but having stock for
other variations will be displayed, but it shouldn't.

This commit fixes that by introducing two changes:

- A new override of "is_visible" for WC_Product_Variable that
  looks at the supplied filters, compares them against the corresponding
  available variations and calculates the visibility based on
  the query type (OR or AND).

- A hook on the "found_posts" filter in WC_Query, that adjusts
  the posts count based on the found products visibility
  when there are filters available; this is needed to sync the
  "displaying X posts" messages and the paging when variable
  products are hidden due to stock status.

Additionally, the visibility calculated in "found_posts" is cached
as loop variables so that it isn't calculated again when actually
displaying the products.
2020-07-28 08:55:52 +02:00
Nestor Soriano c27283dffe Fix code sniffer errors in some files.
Fixed files:

includes/abstracts/abstract-wc-product.php
includes/class-wc-query.php
includes/wc-template-functions.php
includes/widgets/class-wc-widget-layered-nav.php
templates/loop/result-count.php
tests/unit-tests/util/class-wc-tests-wc-query.php
2020-07-28 08:47:29 +02:00
Christopher Allford c84f2b987b
Merge pull request #26750 from woocommerce/implement/core-language-packs-updates
Add language packs automatic delivery code.
2020-07-27 12:45:58 -07:00
Matt Harrison 9f8be6e2d8
Switch to use WordPress' shutdown action instead of register_shutdown_function 2020-07-27 12:11:40 -04:00
Matt Harrison e696ac7824
Queue all webhooks on shutdown.
It is possible for a later duplicate webhook to be fired too early if
the same webhook triggers in one request more than once with the updated
changes from the second one missing if it happens too quickly.
This queues all webhook to be register on shutdown instead of just
syncronous ones to make sure all data from the request is updated first
before the webhook gets queued.
2020-07-27 12:11:40 -04:00
Néstor Soriano de73ec027c
Merge pull request #26303 from netzstrategen/feature/prevent-unnecessary-available-variations-render
Allows avoiding performance bottlenecks caused by get_available_variation().
2020-07-27 08:46:24 +02:00
Claudio Sanches 7bd34e3545
Merge branch 'master' into fix/25843 2020-07-24 17:04:28 -03:00
Ron Rennick 3c6cff4b1c
Merge pull request #26961 from LeGaS/patch-1
Extend BACS accounts filter with order ID
2020-07-24 16:27:57 -03:00
vedanshujain cd09e91817 Applied coding standards 2020-07-24 19:12:25 +05:30
vedanshujain fc6ae313e3 Do not use `wc_round_tax_total` in shipping tax for accuracy.
`wc_round_tax_total` is for when prices are inclusive of taxes, however, shipping taxes can never include taxes so they should always use `round( $price, wc_price_get_decimals() )` instead.
2020-07-24 19:12:25 +05:30
vedanshujain a413952784 Use round_item_subtotal for shipping because shipping prices never include taxes so no need to wc_round_tax_total. 2020-07-24 19:12:25 +05:30
vedanshujain 57c105a3fe Remove wc_round_tax_total calls because lines would have already been rounded appropriately before reaching here. 2020-07-24 19:12:24 +05:30
vedanshujain 853539df12 Remove wc_round_tax_total from shipping item because shipping price are never inclusive of taxes 2020-07-24 19:12:24 +05:30
vedanshujain 541d9ca483 Remove individual rounding because lines would have already rounded.
When rounding at subtotal is enabled, line items are already rounded where they need to, so we only should do any further rounding when displaying values and no where else.

This is part of our larger attempt to remove individual rounding as much as possible.
2020-07-24 19:09:59 +05:30
Néstor Soriano 8c2412ea7d
Merge pull request #26731 from woocommerce/feature/introduce-dependency-injection
Introduce a dependency injection framework
2020-07-24 15:12:16 +02:00
Peter Fabian 03230ecf01
Merge pull request #26642 from woocommerce/fix/26607
Limit stock changes for order items to status methods for consistency.
2020-07-24 13:23:53 +02:00
Nestor Soriano e55ef052a2 Add documentation about the container and good coding practices.
- src/README.md largely expanded
- tests/README.md expanded
- includes/README.md added
- src/Internal/REAMDE.md added

src/README.md and includes/README.md have TODO placeholders to add
guidelines regarding to actions and filters.
2020-07-24 09:25:12 +02:00
Nestor Soriano 71462e33f3 Improevements on ExtendedContainer and LegacyProxy documentation.
Also, remove a not really needed `try` block in LegacyProxy::get_instance_of.
2020-07-24 09:25:11 +02:00
Nestor Soriano 6fd84a0401 Add shortcut methods for the LegacyProxy in the WooCommerce class.
The following methods are added and can be invoked using `WC()`,
they just redirect to the same methods in LegacyProxy:

call_function
call_static
get_instance_of
2020-07-24 09:25:11 +02:00
Nestor Soriano 29cf161415 Small changes after review feedback:
- Method and class renames.
- Removed unnecessary autoloader registration.
- Add a unit test for classes with non-object type hints
  in constructor arguments.
2020-07-24 09:24:06 +02:00
Nestor Soriano d5d02a7175 Fix code sniffer errors in wc-core-functions.php 2020-07-24 09:23:05 +02:00
Nestor Soriano 064ae558ab Changes in the overall organization of the dependency injection:
- The `Container` class now implements `Psr\Container\ContainerInterface`
  (and registers itself as such), holding a private instance of the
  real container. This way it's a read-only container from the point
  of view of plugins (which should use their own containers, but
  can still use this to get WooCommerce classes).
- All registrations are now done in the `Container` constructor via
  service providers.
- The container instance is now held in a global variable, set in
  `woocommerce.php`
- Added the `wc_get_container` function for old code.
- Added the `AbstractServiceProvider` class, which inherits with the
  corresponding League's class and adds some utility methods,
  most notably `add/shareWithAutoArguments`.
- Added the `ActionsProxy` and `LegacyProxy` classes, they are
  registered via a dedicated service provider.
- `WC_Queue_Interface` is no longer resolvable via the container
  (which is for classes inside `src` only).
- All the method names in the new classes have the format `fooBarFizz`
  to be PSR4 compliant, so the MethodNameInvalid error has been
  disabled in phpcs.xml for the `src` directory.
- Introduced the `@public` annotation for public API classes
  (classes that plugins can use and whose backwards compatibility
  we guarantee), applied to `ActionsProxy` and to `LegacyProxy` for now.
- Removed the hack for the autoloader as now it doesn't work anyway.
  For the changes in this branch to work, now WP_DEBUG must be false.
2020-07-24 09:23:01 +02:00
Nestor Soriano 23df8a4d17 Revert a couple of files to its original content after a messed rebase 2020-07-24 09:20:24 +02:00
Nestor Soriano a7829525eb Changes in the dependency injection container:
- Renamed from `ObjectContainer` to `Container`.
- It now inherits from PHP League's `Container`.
- It has now a `defineAsSharedAutowired` method.
- Initialization moved to the `WooCommerce::init_container` method.
- The static method for object resolution is now `WooCommerce::get_instance_of`.
2020-07-24 09:20:24 +02:00
Nestor Soriano 281ec18158 Undo the registration of old singletons in the DI container.
The container will in principle be used only to register classes
in the `src` directory.

Also, CustomerProvider class removed.
2020-07-24 09:20:24 +02:00
Nestor Soriano 312383ae47 First steps towards introducing a dependency injection framework.
- Add PHP League's Container package via Composer.
- Add an ObjectContainer class that encapsulates all the configuration
  and insulates the codebase from the concrete DI engine used.
- Add an improved ReflectionContainer class that will allow to
  register individual classes as singletons while autowiring.
- Use ObjectContainer to resolve the WooCommerce class, everything
  instantiated with "new" inside it, and all singletons that are
  usually obtained via WC() function.
- Introduce the CustomerProvider class.
- Introduce a service provider to resolve WC_Queue_Interface,
  this replaces the WC_Queue class.
- Mark as obsolete all the replaced "instance()" methods,
  and the entire WC_Queue class.
2020-07-24 09:20:21 +02:00
budzanowski 7bc30512a4 Remove extra tab. 2020-07-23 23:22:16 +02:00
budzanowski 623363ba50 Check for if new locale has language pack installed. 2020-07-23 22:52:59 +02:00
budzanowski 70c65f60f2 Don't process if there are no plugins to check. 2020-07-22 12:16:20 +02:00
budzanowski ed1a181eca Update api url. 2020-07-22 10:56:04 +02:00
budzanowski 2d8f308a08 Remove redundant check. 2020-07-21 18:41:34 +02:00
Christopher Allford 840554d788
Merge pull request #27017 from woocommerce/fix/25480
Fixed the `shipping_zone_method` CLI command's instance_id parameter
2020-07-20 11:00:08 -07:00
budzanowski 0a10d64394 Update code to the new server setup. 2020-07-20 17:16:18 +02:00
Claudio Sanches 86311a9903
Merge pull request #27046 from woocommerce/fix/26860
[Importer/Exporter] Fixed the value display of "Published" for children of draft variable products
2020-07-16 13:15:31 -03:00
Ron Rennick dbf3e99292
Merge pull request #26964 from woocommerce/fix/24604
add rating count to order by rating clause
2020-07-16 10:51:20 -03:00
Néstor Soriano 24bd19c517
Merge pull request #27038 from woocommerce/add/26192
Add existing meta keys to woocommerce_duplicate_product_exclude_meta filter
2020-07-16 11:02:09 +02:00
Claudio Sanches 37777432d4 [Importer/Exporter] Fix "Published" column values
While variations only uses "published" and "private" statuses when
exporting we should display the variations as "draft" in case the parent
product it's also a draft.
2020-07-15 21:45:51 -03:00
Vedanshu Jain a34835e489
Merge pull request #26932 from woocommerce/fix/25442
Show community forum link if wccom is not connected
2020-07-16 00:14:52 +05:30
vedanshujain 4500e86198 Shorten class and method names to reduce redundancy in naming. 2020-07-15 15:20:18 +05:30
Christopher Allford c9f754f5a3 Added the existing meta keys to the `woocommerce_duplicate_product_exclude_meta` filter 2020-07-14 13:57:21 -07:00
vedanshujain 1e68ce5dc9 Move function to src for better code architecture 2020-07-14 23:31:56 +05:30
Christopher Allford 9c492853b5
Merge pull request #26998 from woocommerce/fix/is-tax-displayed-private
Fixed the accessibility of WC_Cart::is_tax_displayed()
2020-07-14 09:05:19 -07:00
Nestor Soriano d2787818e3 Rename `quick-edit-warning` style with `wc-` prefix, and add styling. 2020-07-14 16:02:59 +02:00
Nestor Soriano c53d6daed1 Fix error when `screen` not set in request, remove redundand `round`s. 2020-07-14 11:42:22 +02:00
Nestor Soriano a39e15f92b Small adjustments in WC_Admin_Post_Types
- Remove no longer needed phpcs disablers.
- Rename method.
- Remove no longer needed logic.
- Simplify some logic.
2020-07-14 11:42:21 +02:00
Nestor Soriano fc0be07e0f Add unit test for WC_Admin_Post_Types::bulk_and_quick_edit_save_post.
The test added checks that the new regular or sale price is
appropriately set when bulk saving.
2020-07-14 11:42:21 +02:00
Nestor Soriano 4531af3382 Small fix in WC_Tests_Admin_Post_Types::bulk_and_quick_edit_stock_status_for_variable_product.
At some point the 'change_stock' key is assumed to be present
in the request data, but it might not. Fixed to test for existence
before using the value.
2020-07-14 11:42:21 +02:00