Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Create Cross-Sells product list #6645

Merged
merged 26 commits into from
Sep 21, 2022

Conversation

nielslange
Copy link
Member

@nielslange nielslange commented Jun 30, 2022

Fixes #6558

Accessibility

Other Checks

  • This PR adds/removes a feature flag & I've updated this doc.
  • This PR adds/removes an experimental interfaces and I've updated this doc.
  • I tagged two reviewers because this PR makes queries to the database or I think it might have some security impact.

Screenshots

Before:

6558-before

After:

6558-after

Testing

Test editor behaviour when adding Cart block

  1. Create a test page and add the Cart block to it.
  2. Verify that the Cart block contains the Cart Cross-Sells inner block.
  3. Verify that the Cart Cross-Sells inner block contains the Heading and Cart Cross-Sells products inner blocks.
  4. Select the Cart Cross-Sells products inner block and verify that the number of visible Cross-Sells products can be adjusted in the editor.

Test editor behaviour after removing Cross-Sells block

  1. Create a test page and add the Cart block to it.
  2. Verify that the Cart block contains the Cart Cross-Sells inner block.
  3. Delete the Cart Cross-Sells inner block.
  4. Verify that the Cart Cross-Sells inner block can be reinserted.

Test frontend behaviour if cart items does not have Cross-Sells products

  1. Visit the frontend.
  2. Add a product to the cart that does not Cross-Sells products.
  3. Go to the Cart page.
  4. Verify that the Cross-Sells product block is not visible.

Test frontend behaviour if cart items have Cross-Sells products

  1. Visit the frontend.
  2. Add a product to the cart that has Cross-Sells products.
  3. Go to the Cart page.
  4. Verify that the Cross-Sells product block is visible.
  5. Add one of the Cross-Sells products, which also has Cross-Sells products, to the cart.
  6. Verify that the added Cross-Sells product had been added to the cart and is no longer visible as a Cross-Sells product.
  7. Verify that the Cross-Sells products, of the product that had been added to the cart in step 6., are visible in the Cross-Sells block.

Test frontend behaviour if cart items have a Cross-Sells product that is out of stock

  1. Visit the frontend.
  2. Add a product to the cart that has a Cross-Sells product which is out of stock.
  3. Go to the Cart page.
  4. Verify that the Cross-Sells product block is visible.
  5. Verify that the Cross-Sells product, which is out of stock, does not show an Add to Cart button, but a Read More button, that links to the corresponding product page.

Test number of visible Cross-Sells products in the frontend.

  1. Ensure that you have one test product which has more than 6 Cross-Sells products.
  2. Open the cart page in the editor and set the number of visible Cross-Sells items to 1.
  3. Go to the frontend and add the test product from step 1 to the cart.
  4. Go to the cart and verify that only 1 Cross-Sells product is visible.
  5. Repeat steps 2 until 4 and set the number of visible Cross-Sells items to 2, 3, 4, 5 & 6.
  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Performance Impact

n/a

Changelog

Create Cross-Sells product list for showing the Cross-Sells products on the Cart block.

@nielslange nielslange added type: new block Applied to work that introduces a new block (typically used on an epic issue). block: cart Issues related to the cart block. labels Jun 30, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Jun 30, 2022

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

1 similar comment
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

github-actions bot commented Jun 30, 2022

Size Change: +18.8 kB (+2%)

Total Size: 893 kB

Filename Size Change
build/active-filters-frontend.js 7.62 kB -3 B (0%)
build/active-filters.js 8.29 kB +17 B (0%)
build/all-products-frontend.js 18.2 kB +59 B (0%)
build/all-products.js 34 kB +83 B (0%)
build/all-reviews.js 7.79 kB +3 B (0%)
build/attribute-filter-frontend.js 22.3 kB -8 B (0%)
build/attribute-filter.js 13.3 kB +43 B (0%)
build/blocks-checkout.js 17.5 kB +23 B (0%)
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.17 kB +2 B (0%)
build/cart-blocks/cart-express-payment-frontend.js 5.08 kB -3 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.25 kB +4 B (0%)
build/cart-blocks/cart-line-items-frontend.js 430 B +1 B (0%)
build/cart-blocks/cart-order-summary-frontend.js 1.1 kB -1 B (0%)
build/cart-blocks/empty-cart-frontend.js 344 B -2 B (-1%)
build/cart-blocks/filled-cart-frontend.js 782 B -1 B (0%)
build/cart-blocks/order-summary-coupon-form-frontend.js 2.64 kB -1 B (0%)
build/cart-blocks/order-summary-discount-frontend.js 2.15 kB -1 B (0%)
build/cart-blocks/order-summary-fee-frontend.js 273 B -1 B (0%)
build/cart-blocks/order-summary-shipping--checkout-blocks/order-summary-shipping-frontend.js 6.36 kB -7 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 427 B -1 B (0%)
build/cart-blocks/order-summary-taxes-frontend.js 434 B -1 B (0%)
build/cart-blocks/proceed-to-checkout-frontend.js 1.15 kB +3 B (0%)
build/cart-frontend.js 48 kB +909 B (+2%)
build/cart.js 50.3 kB +8.44 kB (+20%) 🚨
build/checkout-blocks/actions-frontend.js 1.42 kB -3 B (0%)
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.11 kB -10 B (0%)
build/checkout-blocks/billing-address-frontend.js 889 B +1 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.83 kB -1 B (0%)
build/checkout-blocks/express-payment-frontend.js 5.37 kB -8 B (0%)
build/checkout-blocks/fields-frontend.js 345 B +1 B (0%)
build/checkout-blocks/order-summary-cart-items-frontend.js 3.64 kB +3 B (0%)
build/checkout-blocks/order-summary-coupon-form-frontend.js 2.79 kB +1 B (0%)
build/checkout-blocks/order-summary-discount-frontend.js 2.27 kB -1 B (0%)
build/checkout-blocks/order-summary-frontend.js 1.1 kB -1 B (0%)
build/checkout-blocks/payment-frontend.js 7.68 kB -6 B (0%)
build/checkout-blocks/shipping-address-frontend.js 1.03 kB +1 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 4.75 kB +3 B (0%)
build/checkout-blocks/totals-frontend.js 325 B -1 B (0%)
build/checkout-frontend.js 49.9 kB +614 B (+1%)
build/checkout.js 43.7 kB +512 B (+1%)
build/featured-category.js 13.2 kB +20 B (0%)
build/featured-product.js 13.4 kB +23 B (0%)
build/handpicked-products.js 7.33 kB +47 B (+1%)
build/legacy-template.js 2.84 kB +3 B (0%)
build/mini-cart-component-frontend.js 16.9 kB +46 B (0%)
build/mini-cart-contents-block/filled-cart-frontend.js 229 B -1 B (0%)
build/mini-cart-contents-block/footer-frontend.js 7.39 kB +410 B (+6%) 🔍
build/mini-cart-contents-block/title-frontend.js 367 B -1 B (0%)
build/mini-cart-contents.js 23.4 kB +566 B (+2%)
build/mini-cart-frontend.js 1.72 kB +1 B (0%)
build/mini-cart.js 4.57 kB +12 B (0%)
build/price-filter-frontend.js 13.4 kB +14 B (0%)
build/price-filter.js 9.35 kB +15 B (0%)
build/product-add-to-cart--product-button--product-category-list--product-image--product-price--product-r--a0326d00.js 226 B +3 B (+1%)
build/product-add-to-cart--product-button--product-image--product-title.js 2.69 kB +35 B (+1%)
build/product-add-to-cart-frontend.js 2.6 kB -4.34 kB (-62%) 🏆
build/product-add-to-cart.js 6.87 kB -4 B (0%)
build/product-best-sellers.js 7.7 kB +79 B (+1%)
build/product-button--product-category-list--product-image--product-price--product-rating--product-sale-b--e17c7c01.js 432 B -3 B (-1%)
build/product-button--product-image--product-rating--product-sale-badge--product-title.js 302 B +2 B (+1%)
build/product-button-frontend.js 1.9 kB +23 B (+1%)
build/product-button.js 1.58 kB +13 B (+1%)
build/product-categories.js 2.36 kB -5 B (0%)
build/product-category-list-frontend.js 890 B +7 B (+1%)
build/product-category-list.js 503 B +1 B (0%)
build/product-category.js 8.69 kB +77 B (+1%)
build/product-image-frontend.js 1.92 kB +40 B (+2%)
build/product-image.js 1.61 kB +21 B (+1%)
build/product-new.js 7.69 kB +68 B (+1%)
build/product-on-sale.js 8.02 kB +77 B (+1%)
build/product-price-frontend.js 1.93 kB +28 B (+1%)
build/product-price.js 1.53 kB +14 B (+1%)
build/product-query.js 646 B -2 B (0%)
build/product-rating-frontend.js 1.19 kB +24 B (+2%)
build/product-rating.js 771 B +32 B (+4%)
build/product-sale-badge-frontend.js 1.15 kB +21 B (+2%)
build/product-sale-badge.js 816 B +15 B (+2%)
build/product-search.js 2.61 kB -7 B (0%)
build/product-sku.js 380 B +1 B (0%)
build/product-stock-indicator-frontend.js 1 kB +8 B (+1%)
build/product-summary-frontend.js 1.3 kB +9 B (+1%)
build/product-tag-list-frontend.js 883 B +7 B (+1%)
build/product-tag.js 8.05 kB +53 B (+1%)
build/product-title-frontend.js 1.35 kB +35 B (+3%)
build/product-title.js 938 B +17 B (+2%)
build/product-top-rated.js 7.93 kB +68 B (+1%)
build/products-by-attribute.js 8.62 kB +90 B (+1%)
build/reviews-by-category.js 11.3 kB +87 B (+1%)
build/reviews-by-product.js 12.4 kB +110 B (+1%)
build/reviews-frontend.js 7.01 kB -9 B (0%)
build/single-product-frontend.js 21.5 kB +62 B (0%)
build/single-product.js 10.1 kB +39 B (0%)
build/stock-filter-frontend.js 7.62 kB +4 B (0%)
build/stock-filter.js 7.55 kB +33 B (0%)
build/vendors--cart-blocks/cart-line-items--cart-blocks/cart-order-summary--cart-blocks/order-summary-shi--c02aad66-frontend.js 0 B -5.26 kB (removed) 🏆
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--5b8feb0b-frontend.js 4.85 kB +6 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 0 B -19.1 kB (removed) 🏆
build/vendors--mini-cart-contents-block/footer-frontend.js 6.86 kB +1 B (0%)
build/vendors--product-add-to-cart-frontend.js 0 B -7.53 kB (removed) 🏆
build/wc-blocks-data.js 9.9 kB +24 B (0%)
build/wc-blocks-editor-style-rtl.css 5.24 kB +136 B (+3%)
build/wc-blocks-editor-style.css 5.24 kB +136 B (+3%)
build/wc-blocks-shared-context.js 1.51 kB -12 B (-1%)
build/wc-blocks-shared-hocs.js 1.71 kB -1 B (0%)
build/wc-blocks-style-rtl.css 23.9 kB +73 B (0%)
build/wc-blocks-style.css 23.8 kB +79 B (0%)
build/wc-blocks-vendors.js 54.5 kB +14 B (0%)
build/cart-blocks/cart-cross-sells-frontend.js 253 B +253 B (new file) 🆕
build/cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 5.44 kB +5.44 kB (new file) 🆕
build/cart-blocks/cart-cross-sells-products-frontend.js 4.63 kB +4.63 kB (new file) 🆕
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--04fe80d1-frontend.js 5.26 kB +5.26 kB (new file) 🆕
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/order-summary-shipping--checkout-blocks--18f9376a-frontend.js 19.1 kB +19.1 kB (new file) 🆕
build/vendors--cart-blocks/cart-cross-sells-products--product-add-to-cart-frontend.js 6.92 kB +6.92 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/cart-blocks/cart-items-frontend.js 299 B
build/cart-blocks/cart-totals-frontend.js 322 B
build/cart-blocks/order-summary-heading-frontend.js 454 B
build/cart-blocks/order-summary-subtotal-frontend.js 274 B
build/checkout-blocks/order-note-frontend.js 1.08 kB
build/checkout-blocks/order-summary-fee-frontend.js 276 B
build/checkout-blocks/order-summary-shipping-frontend.js 602 B
build/checkout-blocks/order-summary-subtotal-frontend.js 274 B
build/checkout-blocks/order-summary-taxes-frontend.js 434 B
build/checkout-blocks/terms-frontend.js 1.23 kB
build/general-style-rtl.css 1.29 kB
build/general-style.css 1.29 kB
build/mini-cart-contents-block/empty-cart-frontend.js 366 B
build/mini-cart-contents-block/footer--mini-cart-contents-block/products-table-frontend.js 4.69 kB
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart-contents-block/products-table-frontend.js 290 B
build/mini-cart-contents-block/shopping-button-frontend.js 288 B
build/price-format.js 1.19 kB
build/product-sku-frontend.js 380 B
build/product-stock-indicator.js 623 B
build/product-summary.js 920 B
build/product-tag-list.js 497 B
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.14 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 931 B
build/wc-blocks-registry.js 2.7 kB
build/wc-blocks-vendors-style-rtl.css 1.95 kB
build/wc-blocks-vendors-style.css 1.95 kB
build/wc-blocks.js 2.63 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.6 kB

compressed-size-action

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@nielslange nielslange force-pushed the add/6558-create-cross-sells-product-list branch from c109c1b to ea612d6 Compare July 18, 2022 14:35
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

Copy link
Contributor

@tarhi-saad tarhi-saad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nielslange! You can find below the fix of the bug you reported on Slack!

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

8 similar comments
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@wavvves
Copy link
Contributor

wavvves commented Jul 21, 2022

One thing missing is support for products with options. See attached screenshots for differences between blocks and shortcode on cross-sells:

Block version
image

Shortcode version
image

We can make this an actionable item to work in our pairing session @nielslange

Also, empty cross-sells still display the heading
image

And we're missing the grey placeholder styles
image

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

7 similar comments
@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@github-actions
Copy link
Contributor

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
cart.js wc-blocks-shared-context, wc-blocks-shared-hocs ⚠️

This comment was automatically generated by the ./github/compare-assets action.

@woocommerce woocommerce deleted a comment from rubikuserbot Jul 29, 2022
@woocommerce woocommerce deleted a comment from rubikuserbot Jul 29, 2022
@woocommerce woocommerce deleted a comment from rubikuserbot Jul 29, 2022
Copy link
Contributor

@tarhi-saad tarhi-saad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @nielslange, for working on this great PR! 🙌

This is the first time I'm testing the PR, so I'm not sure if I did something wrong, but, I'm getting an error on the editor side of the Cart Block:

image

And on the front-end I'm getting the following error:

image

@nielslange
Copy link
Member Author

This is the first time I'm testing the PR, so I'm not sure if I did something wrong, but, I'm getting an error on the editor side of the Cart Block:

@tarhi-saad I double-checked the PR and noticed that the error occurred due to renaming variables in 8f1c545. I just resolved that problem. The Cross-Sells block should now appear, as expected, both in the editor and the frontend.

Copy link
Contributor

@opr opr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @nielslange I tested and it works great - I'll mention something I wondered about. When it comes to removing the block, if you remove the actual block and the heading above it the block still remains, is there anything we can do about this?

Also, the block reappeared once when I removed the product list and heading. Could you look into why this is happening? (You can see this on the video below)

https://www.loom.com/share/c09a3e36a5504cb9bbd26651ca27c5dc

@nielslange
Copy link
Member Author

Thanks @nielslange I tested and it works great - I'll mention something I wondered about. When it comes to removing the block, if you remove the actual block and the heading above it the block still remains, is there anything we can do about this?

Also, the block reappeared once when I removed the product list and heading. Could you look into why this is happening? (You can see this on the video below)

https://www.loom.com/share/c09a3e36a5504cb9bbd26651ca27c5dc

Thanks for your review and pointing this out, @opr.

When it comes to removing the block, if you remove the actual block and the heading above it the block still remains, is there anything we can do about this?

I looked into options, but cannot find anything for now. That said, I noticed that Gutenberg's Group block and our Product Query and Products on Sale blocks behave similar. When deleting inner blocks, both siblings and the parent block remain unaffected. In addition, the parent block does not get deleted if it has no more inner blocks. I agree that this is not ideal, but I'd rather look into this issue in a follow-up issue. Given that this problem also appears when using Gutenberg's Group block, this issue might be addressed in upstream.

Also, the block reappeared once when I removed the product list and heading. Could you look into why this is happening?
I'm unable to reproduce this issue on my end, both when using an existing site and a brand-new site.

@tarhi-saad tarhi-saad self-requested a review September 20, 2022 01:27
Copy link
Contributor

@tarhi-saad tarhi-saad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @nielslange, for working on this PR! I've gone through all the tests mentioned above, and everything is working as expected! 🙌

I looked into options, but cannot find anything for now. That said, I noticed that Gutenberg's Group block and our Product Query and Products on Sale blocks behave similar. When deleting inner blocks, both siblings and the parent block remain unaffected. In addition, the parent block does not get deleted if it has no more inner blocks. I agree that this is not ideal, but I'd rather look into this issue in a follow-up issue. Given that this problem also appears when using Gutenberg's Group block, this issue might be addressed in upstream.

I believe what makes the Cross-Sells different than some of Gutenberg's blocks, is that we prevent the user from adding the Cross-Sells product list block if the parent isn't deleted. This can be frustrating to the user wondering why he isn't allowed to add the block again after removing it using the Editor UI (see image below):

image

The image above shows that there is no Cross-Sells product lits block, nonetheless, we can't add one! The only way to fix the issue will be for the user to open the List View and notice the parent block is still there.

If there isn't an easy solution to remove the parent when removing its inner block, can we look into preventing removing the inner block itself, and only allowing removing the block by deleting the parent? I believe there is a Gutenberg block that works this way.

Also, the block reappeared once when I removed the product list and heading. Could you look into why this is happening? (You can see this on the video below)

I was able to replicate this bug on my end as well. It only happens once after a page refresh, so to reproduce the same bug you'll need to refresh the page and try again:

  1. Go to Cart with the Cross-sell block
  2. Remove the Cart Cross-Sells products inner block first (using the UI or through the List View).
  3. Then remove the Heading inner block. Both inner blocks will show up again!
  4. If the inner blocks were removed as expected, refresh the page and try again!

Lastly, I noticed that the Cart Cross-Sells block doesn't show for the existing Cart Blocks. We should remove our existing Cart and add it again to work. Is this an expected behavior? To reproduce:

  1. Checkout to the trunk branch
  2. Execute npm run build
  3. Create a new page and add a Cart Block
  4. Checkout to this branch (i.e., add/6558-create-cross-sells-product-list)
  5. Execute npm run build
  6. refresh the newly create Cart page. Check there isn't a Cart Cross-Sells block

@nielslange
Copy link
Member Author

Thanks for your review, @tarhi-saad!

If there isn't an easy solution to remove the parent when removing its inner block, can we look into preventing removing the inner block itself, and only allowing removing the block by deleting the parent? I believe there is a Gutenberg block that works this way.

I also had that solution in mind, but initially decided against it, as I found the usability too confusing. That said, I just locked the Cross-Sells products inner block. That way, a merchant can either delete the headline or the whole Cross-Sells block, but not the Cross-Sells products inner block.

I was able to replicate this bug on my end as well. It only happens once after a page refresh, so to reproduce the same bug you'll need to refresh the page and try again:

  1. Go to Cart with the Cross-sell block
  2. Remove the Cart Cross-Sells products inner block first (using the UI or through the List View).
  3. Then remove the Heading inner block. Both inner blocks will show up again!
  4. If the inner blocks were removed as expected, refresh the page and try again!

Apparently, by locking the Cross-Sells products inner block, this problem seems to have been solved as well. At least, I can no longer reproduce it, while I was able to reproduce it, using your steps, before the inner block was locked.

Lastly, I noticed that the Cart Cross-Sells block doesn't show for the existing Cart Blocks. We should remove our existing Cart and add it again to work. Is this an expected behavior? To reproduce:

  1. Checkout to the trunk branch
  2. Execute npm run build
  3. Create a new page and add a Cart Block
  4. Checkout to this branch (i.e., add/6558-create-cross-sells-product-list)
  5. Execute npm run build
  6. refresh the newly create Cart page. Check there isn't a Cart Cross-Sells block

That's intentional and was one of the project deliverables.

Would you mind reviewing this PR again, @tarhi-saad ?

Copy link
Contributor

@tarhi-saad tarhi-saad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification, @nielslange! I've left some comments below, but nothing crucial! It's just things good to have or debatable! So, feel free to merge the PR after this! 🙌

@github-actions github-actions bot added this to the 8.6.0 milestone Sep 20, 2022
@nielslange nielslange merged commit e7b4503 into trunk Sep 21, 2022
@nielslange nielslange deleted the add/6558-create-cross-sells-product-list branch September 21, 2022 06:04
@sunyatasattva sunyatasattva added the type: enhancement The issue is a request for an enhancement. label Sep 26, 2022
senadir pushed a commit to senadir/woocommerce-blocks that referenced this pull request Nov 12, 2022
* Create Cross-Sells product list

* Show “Read more” button for out-of-stock cross-sells products

* Update assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/block.tsx

Co-authored-by: Thomas Roberts <[email protected]>

* Update assets/js/blocks/cart/cart-cross-sells-product-list/index.tsx

Co-authored-by: Thomas Roberts <[email protected]>

* Remove obsolete isLoading and placeholderRows

* Fix TS errors

* Rename crossSellsProduct to product

* Fix critical error

* Lock “Cart Cross-Sells products” inner block

* Update assets/js/blocks/cart/inner-blocks/cart-cross-sells-products/block.json

Co-authored-by: Saad Tarhi <[email protected]>

* Prevent moving of the Cross-Sells block

Co-authored-by: Thomas Roberts <[email protected]>
Co-authored-by: Saad Tarhi <[email protected]>
@nielslange nielslange mentioned this pull request Dec 15, 2022
4 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: cart Issues related to the cart block. type: enhancement The issue is a request for an enhancement. type: new block Applied to work that introduces a new block (typically used on an epic issue).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create Cross-Sells product list
5 participants