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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
4dd1262
Adds a gutenberg block with the cart
alexmigf Mar 8, 2022
91f7c9d
Generate minified JS and CSS files
alexmigf Mar 8, 2022
8f051f1
Update wpmenucart-block.js
alexmigf Mar 8, 2022
064e37c
Update wpmenucart-block.js
alexmigf Mar 8, 2022
924694a
Update wpmenucart-block.js
alexmigf Mar 8, 2022
4c9a652
Improvements on block
alexmigf Mar 9, 2022
77c47f5
Generate minified JS and CSS files
alexmigf Mar 9, 2022
5ff39b6
Some improvements
alexmigf Mar 9, 2022
dfce03a
Merge branch 'gutenberg-block' of github.com:wpovernight/wp-menu-cart…
alexmigf Mar 9, 2022
c27e50e
Generate minified JS and CSS files
alexmigf Mar 9, 2022
91ada7b
Update wp-menu-cart.php
alexmigf Mar 9, 2022
939a10f
Merge branch 'gutenberg-block' of github.com:wpovernight/wp-menu-cart…
alexmigf Mar 9, 2022
32c568c
Inject block font inline
alexmigf Mar 9, 2022
884b95b
Generate minified JS and CSS files
alexmigf Mar 9, 2022
e0b658c
Adds main css to block editor
alexmigf Mar 9, 2022
4f06aa3
Merge branch 'gutenberg-block' of github.com:wpovernight/wp-menu-cart…
alexmigf Mar 9, 2022
2e84276
Update comment
alexmigf Mar 9, 2022
026743f
Instead of injecting the font in the menu item we could attach inline…
alexmigf Mar 9, 2022
5d630c1
Generate minified JS and CSS files
alexmigf Mar 9, 2022
626d8d6
WPCS
alexmigf Mar 9, 2022
d1a3c35
Merge branch 'gutenberg-block' of github.com:wpovernight/wp-menu-cart…
alexmigf Mar 9, 2022
d9793af
Update wpmenucart-block.js
alexmigf Mar 9, 2022
7f52b0e
Generate minified JS and CSS files
alexmigf Mar 9, 2022
2e98f29
Apply cart block to core navigation as link transform
alexmigf Mar 10, 2022
27c3c29
Generate minified JS and CSS files
alexmigf Mar 10, 2022
76e16f4
Load menu item as JS dependency
alexmigf Mar 10, 2022
766c484
Generate minified JS and CSS files
alexmigf Mar 10, 2022
372df08
Update wpmenucart-block.js
alexmigf Mar 10, 2022
f57f119
Generate minified JS and CSS files
alexmigf Mar 10, 2022
4b52fdd
Replace static for dynamic block with server side rendering
alexmigf Mar 10, 2022
ddad7ba
Generate minified JS and CSS files
alexmigf Mar 10, 2022
907d762
Update wpmenucart-block.js
alexmigf Mar 10, 2022
6a3c563
Renames block. Fixes issues retrieving cart totals. Improves block re…
alexmigf Mar 11, 2022
ff03c8e
Generate minified JS and CSS files
alexmigf Mar 11, 2022
ee65916
Rename script file
alexmigf Mar 11, 2022
08bf373
Generate minified JS and CSS files
alexmigf Mar 11, 2022
3c38264
Small improvements
alexmigf Mar 11, 2022
93d281b
Generate minified JS and CSS files
alexmigf Mar 11, 2022
85e916a
Improvements on menu item load in block editor iframe
alexmigf Mar 15, 2022
7ce141b
New approach to load our styles inside the block editor iframe header
alexmigf Mar 16, 2022
10cc1dc
Update wp-menu-cart.php
alexmigf Mar 16, 2022
4c2de76
Update wp-menu-cart.php
alexmigf Mar 16, 2022
9207493
Use 'wp-edit-blocks' instead of 'wc-blocks-style'
alexmigf Mar 16, 2022
9ef9fd1
Fix cart block render styles with Gutenberg plugin installed.
alexmigf Mar 16, 2022
25b6f8f
Always display the cart on block editor
alexmigf Mar 16, 2022
e9a6d41
Update wp-menu-cart.php
alexmigf Mar 16, 2022
1860eee
Improvements on PR comments
alexmigf Mar 16, 2022
cd80ca4
Fix: can't save or load navigation block
Spreeuw Mar 16, 2022
56d3b76
Fix: function name
Spreeuw Mar 16, 2022
4539519
load session & customer for all rest requests
Spreeuw Mar 17, 2022
35456e5
only remove links when in block editor
Spreeuw Mar 17, 2022
2e59ecb
indentation
Spreeuw Mar 17, 2022
1f46b2a
use wc_load_cart() to load cart in rest requests
Spreeuw Mar 17, 2022
207a8cb
Hide block item on cart/checkout pages on setting
alexmigf Mar 18, 2022
4235d05
Small fix
alexmigf Mar 18, 2022
074a2aa
Tweaks
alexmigf Mar 18, 2022
f5a1311
Fix cart/checkout hide on setting
alexmigf Mar 18, 2022
dec7d8e
Update wp-menu-cart.php
alexmigf Mar 18, 2022
69a19f4
Separates the <li> menu item from menu itself. Applies frontend <li> …
alexmigf Mar 18, 2022
7b580c5
Minor tweaks
alexmigf Mar 18, 2022
1481ad6
Update wp-menu-cart.php
alexmigf Mar 18, 2022
e9de51e
Minor tweak
alexmigf Mar 18, 2022
b5367b6
Indentation
alexmigf Mar 22, 2022
e4d07d5
Rename function to match pro
alexmigf Mar 22, 2022
48787f6
Small tweaks to block JS
alexmigf Mar 22, 2022
6dadbb9
Generate minified JS and CSS files
alexmigf Mar 22, 2022
8a427e4
v2.11.0-beta-1
alexmigf Mar 22, 2022
810ea94
Merge branch 'gutenberg-block' of github.com:wpovernight/wp-menu-cart…
alexmigf Mar 22, 2022
66ec2fa
Function check
alexmigf Mar 24, 2022
38adf38
Hide menu selection setting on block themes
alexmigf Mar 25, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions assets/js/wpmenucart-navigation-block.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
( function( blocks, element, i18n, serverSideRender ) {

let __ = i18n.__;
let el = element.createElement;
let registerBlockType = blocks.registerBlockType;
let createBlock = blocks.createBlock;

// svg icon
let iconCart = el(
'svg',
{
width: 20,
height: 20,
},
el( 'path',
{
d: "M15.55 13c.75 0 1.41-.41 1.75-1.03l3.58-6.49c.37-.66-.11-1.48-.87-1.48H5.21l-.94-2H1v2h2l3.6 7.59-1.35 2.44C4.52 15.37 5.48 17 7 17h12v-2H7l1.1-2h7.45zM6.16 6h12.15l-2.76 5H8.53L6.16 6zM7 18c-1.1 0-1.99.9-1.99 2S5.9 22 7 22s2-.9 2-2-.9-2-2-2zm10 0c-1.1 0-1.99.9-1.99 2s.89 2 1.99 2 2-.9 2-2-.9-2-2-2z"
}
)
);

// navigation block
let navigationBlockSettings = {
title: __( 'Cart', 'wp-menu-cart' ),
icon: iconCart,
parent: [ 'core/navigation' ],
keywords: [ 'cart' ],
support: {
html: true,
},
transforms: {
from: [
{
type: 'block',
blocks: [ 'core/navigation-link' ],
transform: () => createBlock( 'wpo/wpmenucart-navigation' )
}
]
},
edit: function( props ) {
return el(
serverSideRender,
{
block: 'wpo/wpmenucart-navigation',
className: 'wpmenucart-navigation-block',
attributes: props.attributes,
}
);
},
save: function() {
// return null to render from php
return null;
},
}
registerBlockType( 'wpo/wpmenucart-navigation', navigationBlockSettings );

} )(
window.wp.blocks,
window.wp.element,
window.wp.i18n,
window.wp.serverSideRender,
);
1 change: 1 addition & 0 deletions assets/js/wpmenucart-navigation-block.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 15 additions & 13 deletions includes/wpmenucart-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class WpMenuCart_Settings {
public function __construct() {
add_action( 'admin_init', array( &$this, 'init_settings' ) ); // Registers settings
add_action( 'admin_menu', array( &$this, 'wpmenucart_add_page' ) );
add_filter( 'plugin_action_links_'.WpMenuCart::$plugin_basename, array( &$this, 'wpmenucart_add_settings_link' ) );
add_filter( 'plugin_action_links_'.WPO_Menu_Cart()->plugin_basename, array( &$this, 'wpmenucart_add_settings_link' ) );

//Menu admin, not using for now (very complex ajax structure...)
//add_action( 'admin_init', array( &$this, 'wpmenucart_add_meta_box' ) );
Expand Down Expand Up @@ -58,18 +58,20 @@ public function init_settings() {
}
}

add_settings_field(
'menu_slugs',
__( 'Select the menu(s) in which you want to display the Menu Cart', 'wp-menu-cart' ),
array( &$this, 'menus_select_element_callback' ),
$option,
'plugin_settings',
array(
'menu' => $option,
'id' => 'menu_slugs',
'options' => (array) $this->get_menu_array(),
)
);
if ( ! WPO_Menu_Cart()->is_block_theme() ) {
add_settings_field(
'menu_slugs',
__( 'Select the menu(s) in which you want to display the Menu Cart', 'wp-menu-cart' ),
array( &$this, 'menus_select_element_callback' ),
$option,
'plugin_settings',
array(
'menu' => $option,
'id' => 'menu_slugs',
'options' => (array) $this->get_menu_array(),
)
);
}

add_settings_field(
'always_display',
Expand Down
24 changes: 14 additions & 10 deletions includes/wpmenucart-woocommerce.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
<?php
if ( ! class_exists( 'WPMenuCart_WooCommerce' ) ) {
class WPMenuCart_WooCommerce {

/**
* Construct.
*/
public function __construct() {
}
public function __construct() {}

public function menu_item() {
// make sure cart is loaded! https://wordpress.org/support/topic/activation-breaks-customise?replies=10#post-7908988
$this->maybe_load_cart();
$this->maybe_load_cart(); // make sure cart is loaded! https://wordpress.org/support/topic/activation-breaks-customise?replies=10#post-7908988

$menu_item = array(
'cart_url' => $this->cart_url(),
'shop_page_url' => $this->shop_url(),
'cart_total' => strip_tags( $this->get_cart_total() ),
'cart_contents_count' => $this->get_cart_contents_count(),
'cart_url' => $this->cart_url(),
'shop_page_url' => $this->shop_url(),
'cart_total' => strip_tags( $this->get_cart_total() ),
'cart_contents_count' => $this->get_cart_contents_count(),
);

return apply_filters( 'wpmenucart_menu_item_data', $menu_item );
}

public function maybe_load_cart() {
if ( function_exists( 'WC' ) ) {
if ( empty( WC()->cart ) ) {
WC()->cart = new WC_Cart();
if ( function_exists( 'wc_load_cart' ) && did_action( 'before_woocommerce_init' ) ) {
wc_load_cart(); // loads session, customer & cart - WC 3.6.4+
} else {
if ( empty( WC()->cart ) ) {
WC()->cart = new WC_Cart();
}
}
WC()->cart->get_cart(); // force cart contents refresh
} else {
global $woocommerce;
if ( empty( $woocommerce->cart ) ) {
Expand Down
Loading