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

Commit

Permalink
Add Product Image Gallery #8233
Browse files Browse the repository at this point in the history
Add Product Image Gallery
  • Loading branch information
gigitux committed Jan 18, 2023
1 parent 486a7f8 commit 38fcacb
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/js/atomic/blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ import './product-elements/category-list';
import './product-elements/tag-list';
import './product-elements/stock-indicator';
import './product-elements/add-to-cart';
import './product-elements/product-image-gallery';
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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const ProductImageGalleryEdit = ( props ) => {
return <span>placeholder</span>;
};
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,
} );
49 changes: 49 additions & 0 deletions src/BlockTypes/ProductImageGallery.php
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;
}
}
1 change: 1 addition & 0 deletions src/BlockTypesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ protected function get_block_types() {
'ProductCategory',
'ProductCategoryList',
'ProductImage',
'ProductImageGallery',
'ProductNew',
'ProductOnSale',
'ProductPrice',
Expand Down

0 comments on commit 38fcacb

Please sign in to comment.