ConverterProvider.php
137 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Block\Convert; |
| 4 | |
| 5 | use WCML\Block\Convert\Converter\ProductsByAttributes; |
| 6 | use WPML\PB\Gutenberg\ConvertIdsInBlock\Base; |
| 7 | use WPML\PB\Gutenberg\ConvertIdsInBlock\Composite; |
| 8 | use WPML\PB\Gutenberg\ConvertIdsInBlock\NullConvert; |
| 9 | use WPML\PB\Gutenberg\ConvertIdsInBlock\BlockAttributes; |
| 10 | use WPML\PB\Gutenberg\ConvertIdsInBlock\TagAttributes; |
| 11 | |
| 12 | class ConverterProvider { |
| 13 | |
| 14 | public static function get( $blockName ) { |
| 15 | switch ( $blockName ) { |
| 16 | case 'woocommerce/product-category': |
| 17 | $converter = new BlockAttributes( |
| 18 | [ |
| 19 | [ |
| 20 | 'name' => 'categories', |
| 21 | 'slug' => 'product_cat', |
| 22 | 'type' => 'taxonomy', |
| 23 | ], |
| 24 | ] |
| 25 | ); |
| 26 | break; |
| 27 | |
| 28 | case 'woocommerce/featured-category': |
| 29 | $converter = new BlockAttributes( |
| 30 | [ |
| 31 | [ |
| 32 | 'name' => 'categoryId', |
| 33 | 'slug' => 'product_cat', |
| 34 | 'type' => 'taxonomy', |
| 35 | ], |
| 36 | ] |
| 37 | ); |
| 38 | break; |
| 39 | |
| 40 | case 'woocommerce/featured-product': |
| 41 | $converter = new BlockAttributes( |
| 42 | [ |
| 43 | [ |
| 44 | 'name' => 'productId', |
| 45 | 'slug' => 'product', |
| 46 | 'type' => 'post' |
| 47 | ], |
| 48 | ] |
| 49 | ); |
| 50 | break; |
| 51 | |
| 52 | case 'woocommerce/handpicked-products': |
| 53 | $converter = new BlockAttributes( |
| 54 | [ |
| 55 | [ |
| 56 | 'name' => 'products', |
| 57 | 'slug' => 'product', |
| 58 | 'type' => 'post', |
| 59 | ], |
| 60 | ] |
| 61 | ); |
| 62 | break; |
| 63 | |
| 64 | case 'woocommerce/product-tag': |
| 65 | $converter = new BlockAttributes( |
| 66 | [ |
| 67 | [ |
| 68 | 'name' => 'tags', |
| 69 | 'slug' => 'product_tag', |
| 70 | 'type' => 'taxonomy', |
| 71 | ], |
| 72 | ] |
| 73 | ); |
| 74 | break; |
| 75 | |
| 76 | case 'woocommerce/reviews-by-product': |
| 77 | $converter = new Composite( |
| 78 | [ |
| 79 | new BlockAttributes( |
| 80 | [ |
| 81 | [ |
| 82 | 'name' => 'productId', |
| 83 | 'slug' => 'product', |
| 84 | 'type' => 'post', |
| 85 | ], |
| 86 | ] |
| 87 | ), |
| 88 | new TagAttributes( |
| 89 | [ |
| 90 | [ |
| 91 | 'xpath' => '//*[contains(@class, "wp-block-woocommerce-reviews-by-product")]/@data-product-id', |
| 92 | 'slug' => 'product', |
| 93 | 'type' => 'post', |
| 94 | ], |
| 95 | ] |
| 96 | ), |
| 97 | ] |
| 98 | ); |
| 99 | break; |
| 100 | |
| 101 | case 'woocommerce/reviews-by-category': |
| 102 | $converter = new Composite( |
| 103 | [ |
| 104 | new BlockAttributes( |
| 105 | [ |
| 106 | [ |
| 107 | 'name' => 'categoryIds', |
| 108 | 'slug' => 'product_cat', |
| 109 | 'type' => 'taxonomy', |
| 110 | ], |
| 111 | ] |
| 112 | ), |
| 113 | new TagAttributes( |
| 114 | [ |
| 115 | [ |
| 116 | 'xpath' => '//*[contains(@class, "wp-block-woocommerce-reviews-by-category")]/@data-category-ids', |
| 117 | 'slug' => 'product_cat', |
| 118 | 'type' => 'taxonomy', |
| 119 | ], |
| 120 | ] |
| 121 | ), |
| 122 | ] |
| 123 | ); |
| 124 | break; |
| 125 | |
| 126 | case 'woocommerce/products-by-attribute': |
| 127 | $converter = new ProductsByAttributes(); |
| 128 | break; |
| 129 | |
| 130 | default: |
| 131 | $converter = new Base(); |
| 132 | } |
| 133 | |
| 134 | return $converter; |
| 135 | } |
| 136 | } |
| 137 |