Skip to content

feat(Sku): support disable_status field to filter disabled SKU options #13520

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

Merged
merged 4 commits into from
Jun 22, 2025

Conversation

Yvan0423-code
Copy link

🎯 Overview

Add support for disable_status field in SKU component to automatically filter disabled SKU options and improve user experience.

✨ Features

  • Auto filter disabled SKUs: Hide SKU options with disable_status: 1
  • Smart cascading filter: Filter out options that would result in all disabled combinations
  • Initialization check: Validate initialSku to ensure valid selection on component init

🔧 Implementation

Filtering Rules

  1. Hide spec values if all related SKUs are disabled
  2. Filter out spec values that create only disabled combinations when selected
  3. Hide spec categories with no available values
  4. Check initialSku validity during initialization

Core Changes

  • Add filterDisabledSkuTree function for filtering logic
  • Enhance isSkuChoosable to check non-disabled SKU stock
  • Update resetSelectedSku with disabled status validation
  • Add checkInitialSkuDisabled method for initial validation

📝 Data Structure

New disable_status field in SKU list:

{
  id: 2258,
  s1: '1', 
  s2: '2',
  price: 100,
  stock_num: 6,
  disable_status: 1  // 0: available, 1: disabled
}

📚 Documentation

Updated README.md with "Disabled SKU" section explaining the filtering mechanism and rules.

🔄 Backward Compatibility

Fully backward compatible - SKUs without disable_status or with value 0 maintain original behavior.

This feature is ideal for e-commerce scenarios requiring dynamic spec filtering, such as seasonal or limited products.

@chenjiahan chenjiahan merged commit 5c8addb into youzan:2.x Jun 22, 2025
3 checks passed
@chenjiahan
Copy link
Member

released: https://www.npmjs.com/package/vant/v/2.13.9-beta.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants