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

Add isSelectableByUser attribute to product templates #46394

Merged
merged 9 commits into from
Apr 10, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Use isSelectableByUser product template attribute
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be useful to say why the attribute is being used.

Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ export function ProductDetailsSectionDescriptionBlockEdit( {
const [ supportedProductTemplates, unsupportedProductTemplates ] =
productTemplates.reduce< [ ProductTemplate[], ProductTemplate[] ] >(
( [ supported, unsupported ], productTemplate ) => {
if ( productTemplate.layoutTemplateId ) {
supported.push( productTemplate );
} else {
unsupported.push( productTemplate );
if ( productTemplate.isSelectableByUser ) {
if ( productTemplate.layoutTemplateId ) {
supported.push( productTemplate );
} else {
unsupported.push( productTemplate );
}
}
return [ supported, unsupported ];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe( 'useProductTemplate', () => {
icon: 'icon',
order: 1,
layoutTemplateId: 'layout-template-1',
isSelectableByUser: true,
productData: {
type: 'simple',
},
Expand All @@ -32,6 +33,7 @@ describe( 'useProductTemplate', () => {
description: 'Template 2 description',
icon: 'icon',
layoutTemplateId: 'layout-template-2',
isSelectableByUser: true,
order: 2,
productData: {
type: 'grouped',
Expand All @@ -43,6 +45,7 @@ describe( 'useProductTemplate', () => {
description: 'Template 3 description',
icon: 'icon',
layoutTemplateId: 'layout-template-3',
isSelectableByUser: true,
order: 3,
productData: {
type: 'simple',
Expand All @@ -54,6 +57,7 @@ describe( 'useProductTemplate', () => {
description: 'Standard Product Template description',
icon: 'icon',
layoutTemplateId: 'layout-template-4',
isSelectableByUser: true,
order: 4,
productData: {
type: 'simple',
Expand All @@ -65,6 +69,7 @@ describe( 'useProductTemplate', () => {
description: 'Gift CardProduct Template description',
icon: 'icon',
layoutTemplateId: 'layout-template-5',
isSelectableByUser: true,
order: 5,
productData: {
type: 'simple',
Expand Down
1 change: 1 addition & 0 deletions packages/js/product-editor/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ProductTemplate = {
icon: string | null;
order: number;
layoutTemplateId: string;
isSelectableByUser: boolean;
productData: Partial< Product >;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Add isSelectableByUser attribute to product templates
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ class ProductTemplate {
*/
private $icon = null;

/**
* If the template is directly selectable through the UI.
*
* @var boolean
*/
private $is_selectable_by_user = true;

/**
* ProductTemplate constructor
*
Expand All @@ -86,6 +93,10 @@ public function __construct( array $data ) {
if ( isset( $data['icon'] ) ) {
$this->icon = $data['icon'];
}

if ( isset( $data['is_selectable_by_user'] ) ) {
$this->is_selectable_by_user = $data['is_selectable_by_user'];
}
}

/**
Expand Down Expand Up @@ -180,6 +191,15 @@ public function get_order() {
return $this->order;
}

/**
* Get the selectable attribute.
*
* @return boolean Selectable.
*/
public function get_is_selectable_by_user() {
return $this->is_selectable_by_user;
}

/**
* Set the template order.
*
Expand All @@ -196,13 +216,14 @@ public function set_order( int $order ) {
*/
public function to_json() {
return array(
'id' => $this->get_id(),
'title' => $this->get_title(),
'description' => $this->get_description(),
'icon' => $this->get_icon(),
'order' => $this->get_order(),
'layoutTemplateId' => $this->get_layout_template_id(),
'productData' => $this->get_product_data(),
'id' => $this->get_id(),
'title' => $this->get_title(),
'description' => $this->get_description(),
'icon' => $this->get_icon(),
'order' => $this->get_order(),
'layoutTemplateId' => $this->get_layout_template_id(),
'productData' => $this->get_product_data(),
'isSelectableByUser' => $this->get_is_selectable_by_user(),
);
}
}