Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gutenberg Cart block #20

Merged
merged 70 commits into from
Apr 7, 2022
Merged

Gutenberg Cart block #20

merged 70 commits into from
Apr 7, 2022

Conversation

alexmigf
Copy link
Member

@alexmigf alexmigf commented Mar 9, 2022

closes #19

Steps to add the cart to the navigation block

  1. On the navigation block click the + button to add a new link:

Captura de ecrã de 2022-03-11 11-01-11

  1. Click the custom link button and select Cart:

Group 1

  1. The link should be converted to the Cart navigation block:

Captura de ecrã de 2022-03-11 11-03-02

Technical considerations

I needed to change the block type from static to dynamic because when the cart contents change the block triggers an error in the editor (image below), content can't be changed using static blocks.

image

Gutenberg knows this is dynamic block by returning null on the save function:

save: function() {
	// return null to render from php
	return null;
},

I discover also that dynamic blocks can be rendered from PHP using ServerSideRender.

This block is a children from parent: [ 'core/navigation' ], and has a transform property that converts from core/navigation-link to our block:

transforms: {
	from: [
		{
			type:      'block',
			blocks:    [ 'core/navigation-link' ],
			transform: () => createBlock( 'wpo/wpmenucart-navigation' )
		}
	]
},

I have also fixed an issue loading the cart on the full site editor, where the session was returning null.

@alexmigf alexmigf requested a review from Spreeuw March 9, 2022 15:06
@alexmigf alexmigf requested a review from Spreeuw March 18, 2022 11:36
Copy link
Contributor

@Spreeuw Spreeuw left a comment

Choose a reason for hiding this comment

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

Great work, just one minor comment! 💪

wp-menu-cart.php Outdated Show resolved Hide resolved
@alexmigf alexmigf requested a review from Spreeuw March 18, 2022 13:48
Copy link
Contributor

@dpeyou dpeyou left a comment

Choose a reason for hiding this comment

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

No new issues to report!

@dwalkerpriv
Copy link

Same here. prior fatal errors about regarding Session are gone. cart loads and behaves normally on it's pages

Copy link
Contributor

@YordanSoares YordanSoares left a comment

Choose a reason for hiding this comment

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

✔️ Looks good to me! Now the menu cart follows the Show on cart & checkout page setting, as well as the Always display cart, even if it's empty and Display shopping cart icon settings.

@Spreeuw Spreeuw merged commit 1aa8ee0 into main Apr 7, 2022
@Spreeuw Spreeuw deleted the gutenberg-block branch April 7, 2022 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement compatibility with full site editing
5 participants