Skip to content

Handle Amazon PA-API 403 errors with fallback display#50

Merged
fumikito merged 5 commits intomasterfrom
bugfix/amazon-restriction
Dec 18, 2025
Merged

Handle Amazon PA-API 403 errors with fallback display#50
fumikito merged 5 commits intomasterfrom
bugfix/amazon-restriction

Conversation

@fumikito
Copy link
Member

Summary

  • Add fallback display when Amazon PA-API returns 403 error (due to policy change requiring 10 sales in 30 days)
  • Add direct ASIN input UI in block editor sidebar for manual product entry
  • Scrape Amazon product page to get title when API is unavailable
  • Use 7-day transient cache for fallback data to reduce network requests
  • External callers of get_item_by_asin() automatically get fallback data by default

Changes

  • hamazon-block.jsx: Added InspectorControls with service dropdown and ASIN text field
  • AmazonConstants.php: Added get_fallback_item(), scrape_amazon_title(), and fallback parameter to get_item_by_asin()
  • AmazonLocales.php: Added get_product_domain() and get_product_url() for URL generation from ASIN
  • amazon-fallback.php: New template for fallback display
  • phpcs.ruleset.xml: Added exclusions for short ternary and short array syntax

Test plan

  • Verify direct ASIN input works in block editor sidebar
  • Verify fallback display shows when PA-API returns error
  • Verify scraped title appears in fallback display
  • Verify external callers (like hametuha repo) get fallback data automatically
  • Verify normal PA-API flow still works when API is available

Closes #49

🤖 Generated with Claude Code

fumikito and others added 5 commits December 19, 2025 00:27
…r later)

closes #44

Co-authored-by: Claude <noreply@anthropic.com>
- Add Direct Input UI in block editor sidebar for ASIN entry
- Add fallback template when PA-API is unavailable
- Scrape Amazon product page to get title for fallback display
- Cache fallback data with transients (7 days)
- Add URL generation methods to AmazonLocales
- Allow short ternary operators and short array syntax in phpcs rules

refs #49

Co-authored-by: Claude <noreply@anthropic.com>
- Add $fallback parameter (default: true) to get_item_by_asin()
- Return fallback data instead of WP_Error when API fails
- All existing users automatically get fallback support

refs #49

Co-authored-by: Claude <noreply@anthropic.com>
- Internal block rendering uses explicit fallback handling
- External API calls still get fallback by default

refs #49

Co-authored-by: Claude <noreply@anthropic.com>
@fumikito fumikito enabled auto-merge December 18, 2025 17:03
@fumikito fumikito merged commit d15c5e0 into master Dec 18, 2025
3 of 14 checks passed
@fumikito fumikito deleted the bugfix/amazon-restriction branch December 18, 2025 17:06
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.

403エラーで商品が表示されない

1 participant