fa11141726
* Expose registerProductCollection in @woocommerce/blocks-registry Package This commit exposes the `registerProductCollection` function as part of the `@woocommerce/blocks-registry` package. This enhancement facilitates the registration of new product collections by 3PDs, promoting better modularity and extensibility within the WooCommerce Blocks ecosystem. Changes include: - Migration of `register-product-collection.tsx` to `packages/checkout/blocks-registry`. - Export `registerProductCollection` from `@woocommerce/blocks-registry/index.ts`. - Updated related imports and references to the new path. This update enables 3PDs to register product collections more seamlessly, enhancing the extensibility of Product Collection block. * Replace @woocommerce/blocks-checkout with @woocommerce/blocks-registry * Add __experimental prefix * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Improve registerproductcollection for 3pds * Set isDefault value to false * Don't export all the types * Update changelog * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Add plugin to test __experimentalRegisterProductCollection * Add E2E tests * Fix Lint errors * Improve E2E tests for __experimentalRegisterProductCollection - Reduced preview timeout from 2000ms to 1000ms. - Expanded E2E tests to cover new attributes and preview functionalities. * Refactor code to improve readability and maintainability - Added a warning comment to indicate that `__experimentalRegisterProductCollection` is an experimental API. - Refactored variable names and imports in `register-product-collection.tsx` and `index.tsx` for clarity. - Simplified and reorganized type definitions and imports in `types.ts` and `utils.tsx`. - Renamed function in `register-product-collection-tester.php` for consistency. * E2E: Also test the Frontend * Use alias for import statement * Don't pass isActive to registerProductCollection Now it's handle by registerProductCollection itself. * Update registerproductcollection API structure Refactored the product collection block to enhance attribute management and ensure consistency in query defaults. This change includes: - Importing `DEFAULT_QUERY` from constants and using it to set default query attributes. - Removing `DEFAULT_ATTRIBUTES` from specific collections and directly defining required attributes. - Ensuring `postType` and `isProductCollectionBlock` are set to default values in the query object. - Setting `inherit` attribute to `false` by default in all collections. * Hide inherit control in collections Ensure the "inherit" control is always hidden, as collections should not be able to change this attribute. This includes: - Adding `CoreFilterNames.INHERIT` to the `hideControls` set in `register-product-collection.tsx`. - Adjusting the `hideControls` attribute in individual collection files to remove redundant hiding of the `INHERIT` control. * Fix: Filters not showing in inspector controls * Set inherit to false for all collections * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Product Collection: Add validation for `__experimentalRegisterProductCollection` arguments (#48513) * Add validation for `__experimentalRegisterProductCollection` arguments Introduced comprehensive validation for the `ProductCollectionConfig` object in `__experimentalRegisterProductCollection` to ensure correct data types and values, enhancing error handling and robustness. - Added a new function `isValidProductCollectionConfig` to perform various checks on the `ProductCollectionConfig` object. - Validates properties such as `name`, `title`, `description`, `category`, `keywords`, `icon`, `isDefault`, `innerBlocks`, `example`, `scope`, `isActive`, `attributes`, and `preview`. - Ensures correct data types and provides detailed console error messages for invalid configurations. - Updated `__experimentalRegisterProductCollection` to use the validation function before proceeding with the registration process. **Impact** - Improves stability and prevents invalid configurations from causing runtime errors. - Provides clearer error messages for developers, aiding in quicker debugging and development. * Fix typo * Refactor: Replace console.error with console.warn Updated the error logging in the isValidProductCollectionConfig function to use console.warn instead of console.error for invalid configuration properties. This address the feedback from the PR review. - Replaced console.error with console.warn for various validation checks in isValidProductCollectionConfig. - Removed redundant return statements after console.warn calls. - Improved logging messages to better inform about invalid configuration properties without treating them as critical errors. - Simplified the logic in __experimentalRegisterProductCollection by combining query and attribute properties and ensuring defaults are set properly. * Refactor: Rename isValidProductCollectionConfig to isValidCollectionConfig Updated the function name from isValidProductCollectionConfig to isValidCollectionConfig for better clarity and consistency. Also, renamed related variables for improved readability. * Add validation for name property * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Title is required for new collection * Update comments * Fix E2E tests * Address PR feedback --------- Co-authored-by: github-actions <github-actions@github.com> * Add README file for __experimentalRegisterProductCollection * Add screenshots in README file * Try to fix lint issue * Docs: add example for collection with inner blocks Enhanced the documentation for `__experimentalRegisterProductCollection` to include an example demonstrating how to define a collection with inner blocks. This example shows how to create a custom collection with nested blocks, including a heading and product elements, providing a clear guide for developers. New content added: - Example 4: Collection with inner blocks - Sample code for defining a collection with inner blocks - Tips and links to further resources on inner blocks and core collection definitions * Fix Lint errors * Address PR feedback * Reduce number of JS files on /shop page **Problem:** There was increase in number of JS files on /shop page after exposing `registerProductCollection` function in `@woocommerce/blocks-registry` package. This package is loaded on the frontend. For example, previously 45 JS files were loaded on /shop page but now 55 JS files are loaded on /shop page. **Solution:** 1. After a bit of debugging I found out that constant file which we are importing i.e. `plugins/woocommerce-blocks/assets/js/blocks/product-collection/constants.ts` contain some heavy dependencies & it's not pure. Therefore, I decided to split this file into two files. I moved all the constants that are used in `registerProductCollection` function to a new file i.e. `plugins/woocommerce-blocks/assets/js/blocks/product-collection/constants-register-product-collection.ts`. This way, we don't need to load all the constants on the frontend i.e. /shop page. - This reduced 4 JS files i.e. 51 JS files are loaded on /shop page. 2. After some more investigation, I found out that importing `registerBlockVariation` function is increasing number of JS files on Frontend. Therefore, I decided to use global `wp` object to call `registerBlockVariation` function. This way, we don't need to import it. This reduced last 6 files i.e. 45 JS files are loaded on /shop page. This way, I was able to reduce number of JS files on /shop page from 55 to 45, which is same as before this PR. * Refactor: product collection constants - Moved constants from `constants-register-product-collection.ts` to `constants.ts` - Deleted `constants-register-product-collection.ts` - Updated import paths in relevant files to reflect the changes - Moved utility functions to `utils.ts` --------- Co-authored-by: github-actions <github-actions@github.com> |
||
---|---|---|
.github | ||
.husky | ||
bin | ||
changelog | ||
docs | ||
packages | ||
plugins | ||
tools | ||
.codecov.yml | ||
.editorconfig | ||
.eslintignore | ||
.eslintrc.js | ||
.gitattributes | ||
.gitignore | ||
.markdownlint.json | ||
.markdownlintignore | ||
.npmrc | ||
.nvmrc | ||
.pnpmfile.cjs | ||
.prettierrc.js | ||
.stylelintrc | ||
.syncpackrc | ||
CODEOWNERS | ||
CODE_OF_CONDUCT.md | ||
DEVELOPMENT.md | ||
README.md | ||
SECURITY.md | ||
changelog.txt | ||
package.json | ||
phpcs.xml | ||
pnpm-lock.yaml | ||
pnpm-workspace.yaml | ||
renovate.json | ||
tsconfig.base.json |
README.md
WooCommerce Monorepo
Welcome to the WooCommerce Monorepo on GitHub. Here you can find all of the plugins, packages, and tools used in the development of the core WooCommerce plugin as well as WooCommerce extensions. You can browse the source, look at open issues, contribute code, and keep tracking of ongoing development.
We recommend all developers to follow the WooCommerce development blog to stay up to date about everything happening in the project. You can also follow @DevelopWC on Twitter for the latest development updates.
Getting Started
To get up and running within the WooCommerce Monorepo, you will need to make sure that you have installed all of the prerequisites.
Prerequisites
- NVM: While you can always install Node through other means, we recommend using NVM to ensure you're aligned with the version used by our development teams. Our repository contains an
.nvmrc
file which helps ensure you are using the correct version of Node. - PNPM: Our repository utilizes PNPM to manage project dependencies and run various scripts involved in building and testing projects.
- PHP 7.4+: WooCommerce Core currently features a minimum PHP version of 7.4. It is also needed to run Composer and various project build scripts. See troubleshooting for troubleshooting problems installing PHP.
- Composer: We use Composer to manage all of the dependencies for PHP packages and plugins.
Once you've installed all of the prerequisites, you can run the following commands to get everything working.
# Ensure that you're using the correct version of Node
nvm use
# Install the PHP and Composer dependencies for all of the plugins, packages, and tools
pnpm install
# Build all of the plugins, packages, and tools in the monorepo
pnpm build
At this point you are now ready to begin developing and testing. All of the build outputs are cached running pnpm build
again will only build the plugins, packages, and tools that have changed since the last time you ran the command.
Check out our development guide if you would like a more comprehensive look at working in our repository.
Repository Structure
- Plugins: Our repository contains plugins that relate to or otherwise aid in the development of WooCommerce.
- WooCommerce Core: The core WooCommerce plugin is available in the plugins directory.
- Packages: Contained within the packages directory are all of the PHP and JavaScript provided for the community. Some of these are internal dependencies and are marked with an
internal-
prefix. - Tools: We also have a growing number of tools within our repository. Many of these are intended to be utilities and scripts for use in the monorepo, but, this directory may also contain external tools.
Reporting Security Issues
To disclose a security issue to our team, please submit a report via HackerOne here.
Support
This repository is not suitable for support. Please don't use our issue tracker for support requests, but for core WooCommerce issues only. Support can take place through the appropriate channels:
- If you have a problem, you may want to start with the self help guide.
- The WooCommerce.com premium support portal for customers who have purchased themes or extensions.
- Our community forum on wp.org which is available for all WooCommerce users.
- The Official WooCommerce Facebook Group.
- For customizations, you may want to check our list of WooExperts or Codeable.
NOTE: Unfortunately, we are unable to honor support requests in issues on this repository; as a result, any requests submitted in this manner will be closed.
Community
For peer to peer support, real-time announcements, and office hours, please join our slack community!
Contributing to WooCommerce
As an open source project, we rely on community contributions to continue to improve WooCommerce. To contribute, please follow the pre-requisites above and visit our Contributing to Woo doc for more links and contribution guidelines.