jankx / woocommerce
WooCommerce integration for Jankx Post Layout
Installs: 113
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 4
pkg:composer/jankx/woocommerce
Requires
This package is auto-updated.
Last update: 2025-11-15 10:48:05 UTC
README
Package tích hợp WooCommerce với Jankx Post Layout system.
Kiến trúc
Code Isolation
- Core (
cheephub): Không biết về WooCommerce - Vendor (
cheephub-v1/vendor/jankx/woocommerce): WooCommerce-specific code - Kết nối qua WordPress Filters: Hook system để tách biệt concerns
Components
-
WooCommerceContentGenerator (
includes/PostLayout/WooCommerceContentGenerator.php)- Generator riêng cho WooCommerce products
- Sử dụng WC templates
-
WooCommercePostLayoutHook (
includes/Hooks/WooCommercePostLayoutHook.php)- Hook vào
jankx/post-layout/generatorfilter - Auto-detect và apply generator cho product post type
- Hook vào
-
WooCommerce (
includes/WooCommerce.php)- Main integration class
- Initialize hooks
Cách hoạt động
Flow
PostLayoutDecorator::withAttributes()
↓
apply_filters('jankx/post-layout/generator')
↓
WooCommercePostLayoutHook::provideGenerator() (in vendor)
↓
Returns WooCommerceContentGenerator instance
↓
PostLayoutDecorator applies generator to layout
Tự động apply
Khi Post Type Layout block có postType = 'product':
- WooCommercePostLayoutHook detect product post type
- Return WooCommerceContentGenerator
- Generator tự động được áp dụng
Lợi ích Code Isolation
✅ Core không phụ thuộc: cheephub core không import WooCommerce classes
✅ Vendor độc lập: WooCommerce code ở riêng trong vendor package
✅ Loosely coupled: Kết nối qua WordPress filters
✅ Easy to disable: Đơn giản tắt bằng cách remove filter
Sử dụng
Automatic (mặc định)
Tự động apply khi post type là product:
// Trong Gutenberg block $attributes['postType'] = 'product'; // WooCommerce generator tự động apply
Manual
use Jankx\WooCommerce\PostLayout\WooCommerceContentGenerator; $layout = new GridLayout(); $layout->setContentGenerator(new WooCommerceContentGenerator());
Customize
Để customize template, tạo file trong theme:
woocommerce/content-product.php- Product item template
Lưu ý
- WooCommerce phải active
- Hook tự động register khi
WooCommerce::init()được gọi - Code hoàn toàn tách biệt, không violate isolation