Closed nerrad closed 4 years ago
Thanks for taking the time to report this issue Kathy!
While it may appear this is a bug, the filter you used is not expected to affect the behaviour of the All Products block. The "Products by Category" block is a server side rendered block and thus it's html
layout etc is rendered on the server before being served to the client. The "All Products" block is a new type of block that is completely rendered client side and gets products (and other data) over the wire via the REST API.
I'm going to close this issue but feel free to add additional feedback and/or comments.
I wrote the following post in the WooCommerce community slack and I'm copying here for others that might stumble on this issue:
For those using All Products block, it works a bit differently than server side rendered blocks in a few key areas:
Each element for a product in the grid is actually a “inner block”. So product title, product description, product image etc are all blocks themselves (which allows for merchants to use the block editor to control the layout of the elements for each product in the grid). Down the road we’ll be adding some additional controls etc for these “atomic” blocks that give flexibility and immediate feedback for how things change when the blocks are modified. The products are supplied via REST api to power the block components on the frontend. We do have some basic extensibility for developers in place right now but do plan on adding more as we iterate and get feedback from developers on what they’d like to see. However, for the most part, with this new style of block the extensibility will not be found php side. Currently, you can use the registerInnerBlock api for registering additional blocks to be available for using in the product grid. You can see an example of this in use here.
Admittedly, there is sparse documentation for this currently because we’re wanting the interface to percolate a bit before we document it fully.
@nerrad There are two features that are sorely lacking. 1) Allow block pre-filtering all products based on one / attributes / categories. There is example of shunk to your API REST ` add_action('wp_loaded', 'test_rest_api_init', 10, 1); function test_rest_api_init( $rest_server ){
if( isset($_GET["orderby"]) ){
if( isset($_GET["attributes"]) ){
$finded_brand = false;
foreach($_GET["attributes"] as $key => $attribute){
if( $attribute["attribute"] == "pa_beer_brand" ){
$finded_brand = true;
}
}
if( !$finded_brand ){
$_GET["attributes"][] = array(
"attribute" => "pa_beer_brand",
"operator" => "in",
"slug" => array(
"bofferding"
)
);
}
}else{
$_GET["attributes"] = array();
$_GET["attributes"][] = array(
"attribute" => "pa_beer_brand",
"operator" => "in",
"slug" => array(
"bofferding"
)
);
}
}
}`
2) As explained above, I find it surprising that there is no way to display special field of product like color attributes (for example) for me the addition of a shortcode would have solved a lot of problems, but still to do with the return of the rest API which returns a very specific data schema => which I fully understand, but filter hooks on diagrams and data returns would have helped (I think easy) to solve the problem.
I am available if you want to discuss these two features.
Hi Yann,
Is the issue in #1705 the same request as what you've asked for? If so, then ya we've seen your request (it just hasn't been triaged yet because our team has been away on a team meetup). I appreciate you expanding on your request with more details here, but it'd be good if you add your above comment to that issue to keep all the details in one issue so we don't miss things when we evaluate potential new enhancements for the blocks.
Hi @nerrad Thanks for the explanation about the different types of blocks. So you are saying there is NO way to modify the content of the inner block? If not a bug, could that be considered at least a feature request? It's in a grid and it seems logical that the filter I mentioned would work there. From my point of view, that you can modify the template of the shop archive loop everywhere or per-term, but not do the same with blocks seems pretty odd.
So you are saying there is NO way to modify the content of the inner block?
Currently no. The block does not pull its rendered html content from php, it comes from a new (experimental) store/products
api.
It's in a grid and it seems logical that the filter I mentioned would work there. From my point of view, that you can modify the template of the shop archive loop everywhere or per-term, but not do the same with blocks seems pretty odd.
I agree it may seem logical from the perspective of this is how WordPress and WooCommerce html content has been modified for a number of years. However, these particular blocks (All Products, the atomic inner blocks, and the filter blocks) which are not using server side rendering (but are rendered entirely client side) is implementing a new way of rendering content. Over time, the inner-blocks will be enhanced (or can be replaced or new ones added by developers introducing alternatives) so that merchants can (optionally) have direct control over the looks and layout of wherever the block is used. This could include additional controls for affecting style/layout (eg. list vs grid), or new blocks for inserting/displaying additional content (attribute terms etc).
The big idea here is that it allows merchants to more easily adjust their content without having to dive into theme or plugin code and see changes applied immediately. While developers can focus on building the blocks or pieces offering additional options to merchants.
Forward looking, these new atomic blocks will also work well with a potential new templating system in Gutenberg where the blocks might be added to templates.
@helgatheviking commented on Fri Feb 07 2020
Describe the bug A clear and concise description of what the bug is. Please be as descriptive as possible; issues lacking detail, or for any other reason than to report a bug, may be closed without action.
To Reproduce Steps to reproduce the behavior: Add this snippet to
functions.php
And then create two blocks on a page. One "Products by category" block and then the "All products" block.
Save and view the page on the front end.
"Tacos are great!" should appear underneath the product title in the "Products from Category" block, but not in the "All Products" block.
Screenshots ![front end display of both blocks…]()
Expected behavior I expect the
woocommerce_blocks_product_grid_item_html
filtered content to appear in the All products block.Isolating the problem (mark completed items with an [x]):
WordPress Environment
@nerrad commented on Fri Feb 07 2020
This belongs in the blocks repo so I'll move there and it will be addressed there as well.