BlockHooksTrait.php
4 weeks ago
BlockTemplateUtils.php
2 months ago
BlocksSharedState.php
3 months ago
BlocksWpQuery.php
2 years ago
CartCheckoutUtils.php
4 weeks ago
MiniCartUtils.php
1 year ago
ProductAvailabilityUtils.php
11 months ago
ProductDataUtils.php
1 year ago
ProductGalleryUtils.php
4 weeks ago
StyleAttributesUtils.php
1 year ago
Utils.php
2 years ago
MiniCartUtils.php
61 lines
| 1 | <?php |
| 2 | namespace Automattic\WooCommerce\Blocks\Utils; |
| 3 | |
| 4 | /** |
| 5 | * Utility methods used for the Mini Cart block. |
| 6 | */ |
| 7 | class MiniCartUtils { |
| 8 | /** |
| 9 | * Migrate attributes to color panel component format. |
| 10 | * |
| 11 | * @param array $attributes Any attributes that currently are available from the block. |
| 12 | * @return array Reformatted attributes that are compatible with the color panel component. |
| 13 | */ |
| 14 | public static function migrate_attributes_to_color_panel( $attributes ) { |
| 15 | if ( isset( $attributes['priceColorValue'] ) && ! isset( $attributes['priceColor'] ) ) { |
| 16 | $attributes['priceColor'] = array( |
| 17 | 'color' => $attributes['priceColorValue'], |
| 18 | ); |
| 19 | unset( $attributes['priceColorValue'] ); |
| 20 | } |
| 21 | |
| 22 | if ( isset( $attributes['iconColorValue'] ) && ! isset( $attributes['iconColor'] ) ) { |
| 23 | $attributes['iconColor'] = array( |
| 24 | 'color' => $attributes['iconColorValue'], |
| 25 | ); |
| 26 | unset( $attributes['iconColorValue'] ); |
| 27 | } |
| 28 | |
| 29 | if ( isset( $attributes['productCountColorValue'] ) && ! isset( $attributes['productCountColor'] ) ) { |
| 30 | $attributes['productCountColor'] = array( |
| 31 | 'color' => $attributes['productCountColorValue'], |
| 32 | ); |
| 33 | unset( $attributes['productCountColorValue'] ); |
| 34 | } |
| 35 | |
| 36 | return $attributes; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get the SVG icon for the mini cart. |
| 41 | * |
| 42 | * @param string $icon_name The name of the icon. |
| 43 | * @param string $icon_color The color of the icon. |
| 44 | * @return string The SVG icon. |
| 45 | */ |
| 46 | public static function get_svg_icon( $icon_name, $icon_color = 'currentColor' ) { |
| 47 | // Default "Cart" icon. |
| 48 | $icon = '<svg xmlns="http://www.w3.org/2000/svg" fill="' . esc_attr( $icon_color ) . '" class="wc-block-mini-cart__icon" viewBox="0 0 32 32"><circle cx="12.667" cy="24.667" r="2"/><circle cx="23.333" cy="24.667" r="2"/><path fill-rule="evenodd" d="M9.285 10.036a1 1 0 0 1 .776-.37h15.272a1 1 0 0 1 .99 1.142l-1.333 9.333A1 1 0 0 1 24 21H12a1 1 0 0 1-.98-.797L9.083 10.87a1 1 0 0 1 .203-.834m2.005 1.63L12.814 19h10.319l1.047-7.333z" clip-rule="evenodd"/><path fill-rule="evenodd" d="M5.667 6.667a1 1 0 0 1 1-1h2.666a1 1 0 0 1 .984.82l.727 4a1 1 0 1 1-1.967.359l-.578-3.18H6.667a1 1 0 0 1-1-1" clip-rule="evenodd"/></svg>'; |
| 49 | |
| 50 | if ( isset( $icon_name ) ) { |
| 51 | if ( 'bag' === $icon_name ) { |
| 52 | $icon = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" class="wc-block-mini-cart__icon" viewBox="0 0 32 32"><path fill="' . esc_attr( $icon_color ) . '" fill-rule="evenodd" d="M12.444 14.222a.89.89 0 0 1 .89.89 2.667 2.667 0 0 0 5.333 0 .889.889 0 1 1 1.777 0 4.444 4.444 0 1 1-8.888 0c0-.492.398-.89.888-.89M11.24 6.683a1 1 0 0 1 .76-.35h8a1 1 0 0 1 .76.35l4 4.666A1 1 0 0 1 24 13H8a1 1 0 0 1-.76-1.65zm1.22 1.65L10.174 11h11.652L19.54 8.333z" clip-rule="evenodd"/><path fill="' . esc_attr( $icon_color ) . '" fill-rule="evenodd" d="M7 12a1 1 0 0 1 1-1h16a1 1 0 0 1 1 1v13.333a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1zm2 1v11.333h14V13z" clip-rule="evenodd"/></svg>'; |
| 53 | } elseif ( 'bag-alt' === $icon_name ) { |
| 54 | $icon = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" class="wc-block-mini-cart__icon" viewBox="0 0 32 32"><path fill="' . esc_attr( $icon_color ) . '" fill-rule="evenodd" d="M19.556 12.333a.89.89 0 0 1-.89-.889c0-.707-.28-3.385-.78-3.885a2.667 2.667 0 0 0-3.772 0c-.5.5-.78 3.178-.78 3.885a.889.889 0 1 1-1.778 0c0-1.178.468-4.309 1.301-5.142a4.445 4.445 0 0 1 6.286 0c.833.833 1.302 3.964 1.302 5.142a.89.89 0 0 1-.89.89" clip-rule="evenodd"/><path fill="' . esc_attr( $icon_color ) . '" fill-rule="evenodd" d="M7.5 12a1 1 0 0 1 1-1h15a1 1 0 0 1 1 1v13.333a1 1 0 0 1-1 1h-15a1 1 0 0 1-1-1zm2 1v11.333h13V13z" clip-rule="evenodd"/></svg>'; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | return $icon; |
| 59 | } |
| 60 | } |
| 61 |