2019-01-10 18:16:37 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { __ } from '@wordpress/i18n';
|
2019-02-26 05:31:25 +00:00
|
|
|
import { createBlock, registerBlockType } from '@wordpress/blocks';
|
|
|
|
import { without } from 'lodash';
|
2019-11-08 16:30:11 +00:00
|
|
|
import { IconProductOnSale } from '@woocommerce/block-components/icons';
|
2019-01-10 18:16:37 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import Block from './block';
|
2020-01-10 14:40:15 +00:00
|
|
|
import './editor.scss';
|
2019-05-16 13:03:11 +00:00
|
|
|
import { deprecatedConvertToShortcode } from '../../utils/deprecations';
|
|
|
|
import sharedAttributes, {
|
|
|
|
sharedAttributeBlockTypes,
|
|
|
|
} from '../../utils/shared-attributes';
|
2019-01-10 18:16:37 +00:00
|
|
|
|
|
|
|
registerBlockType( 'woocommerce/product-on-sale', {
|
|
|
|
title: __( 'On Sale Products', 'woo-gutenberg-products-block' ),
|
2019-05-28 10:18:07 +00:00
|
|
|
icon: {
|
2019-10-01 09:20:52 +00:00
|
|
|
src: <IconProductOnSale />,
|
2019-05-28 10:18:07 +00:00
|
|
|
foreground: '#96588a',
|
|
|
|
},
|
2019-01-10 18:16:37 +00:00
|
|
|
category: 'woocommerce',
|
|
|
|
keywords: [ __( 'WooCommerce', 'woo-gutenberg-products-block' ) ],
|
|
|
|
description: __(
|
|
|
|
'Display a grid of on sale products.',
|
|
|
|
'woo-gutenberg-products-block'
|
|
|
|
),
|
|
|
|
supports: {
|
|
|
|
align: [ 'wide', 'full' ],
|
2019-05-16 13:03:11 +00:00
|
|
|
html: false,
|
2019-01-10 18:16:37 +00:00
|
|
|
},
|
|
|
|
attributes: {
|
|
|
|
...sharedAttributes,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How to order the products: 'date', 'popularity', 'price_asc', 'price_desc' 'rating', 'title'.
|
|
|
|
*/
|
|
|
|
orderby: {
|
|
|
|
type: 'string',
|
|
|
|
default: 'date',
|
|
|
|
},
|
|
|
|
},
|
2019-11-15 15:16:18 +00:00
|
|
|
example: {
|
|
|
|
attributes: {
|
|
|
|
isPreview: true,
|
|
|
|
},
|
|
|
|
},
|
2019-02-26 05:31:25 +00:00
|
|
|
transforms: {
|
|
|
|
from: [
|
|
|
|
{
|
|
|
|
type: 'block',
|
2019-05-16 13:03:11 +00:00
|
|
|
blocks: without(
|
|
|
|
sharedAttributeBlockTypes,
|
|
|
|
'woocommerce/product-on-sale'
|
2019-02-26 05:31:25 +00:00
|
|
|
),
|
2019-05-16 13:03:11 +00:00
|
|
|
transform: ( attributes ) =>
|
|
|
|
createBlock( 'woocommerce/product-on-sale', attributes ),
|
2019-02-26 05:31:25 +00:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-01-10 18:16:37 +00:00
|
|
|
|
2019-05-16 13:03:11 +00:00
|
|
|
deprecated: [
|
|
|
|
{
|
|
|
|
// Deprecate shortcode save method in favor of dynamic rendering.
|
|
|
|
attributes: {
|
|
|
|
...sharedAttributes,
|
|
|
|
orderby: {
|
|
|
|
type: 'string',
|
|
|
|
default: 'date',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
save: deprecatedConvertToShortcode( 'woocommerce/product-on-sale' ),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
|
2019-01-10 18:16:37 +00:00
|
|
|
/**
|
|
|
|
* Renders and manages the block.
|
2019-12-10 17:17:46 +00:00
|
|
|
*
|
|
|
|
* @param {Object} props Props to pass to block.
|
2019-01-10 18:16:37 +00:00
|
|
|
*/
|
|
|
|
edit( props ) {
|
|
|
|
return <Block { ...props } />;
|
|
|
|
},
|
|
|
|
|
2019-05-16 13:03:11 +00:00
|
|
|
save() {
|
|
|
|
return null;
|
2019-01-10 18:16:37 +00:00
|
|
|
},
|
|
|
|
} );
|