This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Product Image Gallery
- Loading branch information
Showing
6 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
assets/js/atomic/blocks/product-elements/product-image-gallery/block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "woocommerce/product-image-gallery", | ||
"version": "1.0.0", | ||
"title": "Product image gallery", | ||
"description": "", | ||
"category": "woocommerce", | ||
"keywords": [ "WooCommerce" ], | ||
"usesContext": [ "postId", "postType", "queryId" ], | ||
"textdomain": "woo-gutenberg-products-block", | ||
"apiVersion": 2, | ||
"$schema": "https://schemas.wp.org/trunk/block.json" | ||
} |
3 changes: 3 additions & 0 deletions
3
assets/js/atomic/blocks/product-elements/product-image-gallery/edit.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const ProductImageGalleryEdit = ( props ) => { | ||
return <span>placeholder</span>; | ||
}; |
15 changes: 15 additions & 0 deletions
15
assets/js/atomic/blocks/product-elements/product-image-gallery/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { registerBlockType } from '@wordpress/blocks'; | ||
import metadata from './block.json'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { ProductImageGalleryEdit } from './edit'; | ||
|
||
registerBlockType( metadata, { | ||
icon: 'tickets', | ||
edit: ProductImageGalleryEdit, | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
namespace Automattic\WooCommerce\Blocks\BlockTypes; | ||
|
||
/** | ||
* ProductImageGallery class. | ||
*/ | ||
class ProductImageGallery extends AbstractBlock { | ||
/** | ||
* Block name. | ||
* | ||
* @var string | ||
*/ | ||
protected $block_name = 'product-image-gallery'; | ||
|
||
/** | ||
* Register the context | ||
* | ||
* @var string | ||
*/ | ||
protected function get_block_type_uses_context() { | ||
return [ 'query', 'queryId', 'postId' ]; | ||
} | ||
|
||
/** | ||
* Include and render the block. | ||
* | ||
* @param array $attributes Block attributes. Default empty array. | ||
* @param string $content Block content. Default empty string. | ||
* @param WP_Block $block Block instance. | ||
* @return string Rendered block type output. | ||
*/ | ||
protected function render( $attributes, $content, $block ) { | ||
|
||
$post_id = $block->context['postId']; | ||
global $product; | ||
$product = wc_get_product( $post_id ); | ||
|
||
if ( class_exists( 'WC_Frontend_Scripts' ) ) { | ||
$frontend_scripts = new \WC_Frontend_Scripts(); | ||
$frontend_scripts::load_scripts(); | ||
} | ||
|
||
ob_start(); | ||
woocommerce_show_product_images(); | ||
$product_image_gallery_html = ob_get_clean(); | ||
|
||
return $product_image_gallery_html; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters