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

Track stock quantity for this product should be disabled when Enable stock management within settings is disabled, and enabled otherwise #37957

Merged
merged 2 commits into from Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/js/product-editor/changelog/add-37888
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Track stock quantity for this product should be disabled when Enable stock management within settings is disabled, and enabled otherwise
4 changes: 4 additions & 0 deletions packages/js/product-editor/src/blocks/toggle/block.json
Expand Up @@ -14,6 +14,10 @@
},
"property": {
"type": "string"
},
"disabled": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Good call!

"type": "boolean",
"default": false
}
},
"supports": {
Expand Down
3 changes: 2 additions & 1 deletion packages/js/product-editor/src/blocks/toggle/edit.tsx
Expand Up @@ -16,7 +16,7 @@ export function Edit( {
attributes,
}: BlockEditProps< ToggleBlockAttributes > ) {
const blockProps = useBlockProps();
const { label, property } = attributes;
const { label, property, disabled } = attributes;
const [ value, setValue ] = useEntityProp< boolean >(
'postType',
'product',
Expand All @@ -28,6 +28,7 @@ export function Edit( {
<ToggleControl
label={ label }
checked={ value }
disabled={ disabled }
onChange={ setValue }
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/js/product-editor/src/blocks/toggle/types.ts
Expand Up @@ -6,4 +6,5 @@ import { BlockAttributes } from '@wordpress/blocks';
export interface ToggleBlockAttributes extends BlockAttributes {
label: string;
property: string;
disabled?: boolean;
}
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/add-37888
@@ -0,0 +1,4 @@
Significance: minor
Type: add

Track stock quantity for this product should be disabled when Enable stock management within settings is disabled, and enabled otherwise
1 change: 1 addition & 0 deletions plugins/woocommerce/includes/class-wc-post-types.php
Expand Up @@ -625,6 +625,7 @@ public static function register_post_types() {
array(
'label' => __( 'Track stock quantity for this product', 'woocommerce' ),
'property' => 'manage_stock',
'disabled' => 'yes' !== get_option( 'woocommerce_manage_stock' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Just thinking about this in the future: once the settings screens are Reactified, we might want the ability to either:
a. Refetch this template (so we have the correct disabled property) OR
b. Move this setting check to the frontend

But this issue doesn't exist for the time being and I think punting it down the road is fine.

),
),
array(
Expand Down