woocommerce/plugins/woocommerce-blocks/patterns/banner.php

57 lines
3.7 KiB
PHP
Raw Normal View History

<?php
/**
* Title: Banner
* Slug: woocommerce-blocks/banner
* Categories: WooCommerce
*/
[Store Customization] Update patterns to use the AI selected verticals for images (https://github.com/woocommerce/woocommerce-blocks/pull/10796) * Add the Verticals API client * Add tests * Refactor error handling * Create first version of the prompt class * Improve Vertical selector and add tests * Remove testing code * Update class comment * Add PatternImages class * Pass the dictionary as param * Add tests * Add `get_pattern_images` function and use it on patterns * Add the Jetpack Connection Package as a dependency for WooCommerce Blocks. * Introduce the new Configuration Class for registering and enabling the Jetpack connection for sites and users. * Introduce the Connection class for making requests to the GPT AI API. * Update the get_jwt_token method. * Update the error messages for the get_jwt_token method. * Update the register_site method. * Update the Configuration class structure and add Dependency Injection. * Update structure for the Connection Class. * Update the return type for the get_jwt_token method. * Update method visibility for get_site_id * Update the name and params for methods within the Connection Class * Add tests for the Connecction class. * Update the Constructor for the Configuration class. * Add the Patterns class. * Move the get_image_url function to the PatternImages class and update the call in all patterns to address errors. * Remove the functions.php file * Update the VerticalsSelector class. * Update the constructor for PatternImages. * Update the Store API Route for Patterns. * Update the create_patterns_content method to ensure it returns the results of update_option. * Add the new Patterns route to the RoutesController class. * Update the route path and remove the business description validation as that is done via create_patterns_content * Introduce the PatternsSchema * Update the prompt, errors messages and output format for the Verticals Selector. * Fix the missing file error for the Patterns Dictionary. * Introduce the new get_patterns_dictionary method and update the create_patterns_content method to better handle errors. * Update the returned response for the endpoint. * Add the get_item_response method to the PatternsSchema class. * Update response for when allow_ai_connection option is not set. * Enable authentication for the endpoint. * Modify and temporarily remove some failing tests for the AI API: a separate PR will be opened to clear those out later. * Add validation to the verticals_id. * Remove reference to the src/Patterns/functions.php file. * Update `alt` to be more generic, since the displayed images will vary * Store Customization > Schedule an action to update the patterns content whenever the business description is changed (https://github.com/woocommerce/woocommerce-blocks/pull/10956) * Introduce the new OptionUpdate class. * Update the path to action schduler and add a file_exists check before attempting to schedule the action. * Update the content in patterns from the BlockPatterns class instead. * Remove return comment --------- Co-authored-by: Alba Rincón <alba.rincon@automattic.com> --------- Co-authored-by: Patricia Hillebrandt <patriciahillebrandt@gmail.com>
2023-09-19 07:05:44 +00:00
use Automattic\WooCommerce\Blocks\Patterns\PatternsHelper;
$banner_title = $content['titles'][0]['default'] ?? '';
$banner_button = $content['buttons'][0]['default'] ?? '';
$first_description = $content['descriptions'][0]['default'] ?? '';
$second_description = $content['descriptions'][1]['default'] ?? '';
?>
<!-- wp:columns {"verticalAlignment":null,"align":"wide","backgroundColor":"contrast"} -->
<div class="wp-block-columns alignwide has-contrast-background-color has-background">
<!-- wp:column {"verticalAlignment":"center","style":{"spacing":{"padding":{"top":"var:preset|spacing|30","right":"var:preset|spacing|30","bottom":"var:preset|spacing|30","left":"var:preset|spacing|30"}}}} -->
<div class="wp-block-column is-vertically-aligned-center" style="padding-top:var(--wp--preset--spacing--30);padding-right:var(--wp--preset--spacing--30);padding-bottom:var(--wp--preset--spacing--30);padding-left:var(--wp--preset--spacing--30)">
<!-- wp:paragraph {"style":{"typography":{"fontSize":"18px"},"spacing":{"margin":{"top":"0","right":"0","bottom":"0","left":"0"}}}, "textColor":"base"} -->
<p class="has-base-color has-text-color" style="margin-top:0;margin-right:0;margin-bottom:0;margin-left:0;font-size:18px"><strong><?php echo esc_html( $first_description ); ?></strong> </p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"style":{"typography":{"fontSize":"48px"},"spacing":{"margin":{"top":"0px","right":"0px","bottom":"0px","left":"0px"},"padding":{"top":"0","right":"0","bottom":"0","left":"0"}}}, "textColor":"base"} -->
<p class="has-base-color has-text-color" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;padding-top:0;padding-right:0;padding-bottom:0;padding-left:0;font-size:48px"><strong><?php echo esc_html( $banner_title ); ?></strong> </p>
<!-- /wp:paragraph -->
<!-- wp:paragraph {"style":{"typography":{"fontSize":"24px"},"spacing":{"margin":{"top":"0","right":"0","bottom":"0","left":"0"}}}, "textColor":"base"} -->
<p class="has-base-color has-text-color" style="margin-top:0;margin-right:0;margin-bottom:0;margin-left:0;font-size:24px"><?php echo esc_html( $second_description ); ?></p>
<!-- /wp:paragraph -->
<!-- wp:buttons {"style":{"spacing":{"blockGap":"0","margin":{"top":"20px","bottom":"0"}}}} -->
<div class="wp-block-buttons" style="margin-top:20px;margin-bottom:0">
<!-- wp:button {"style":{"typography":{"fontSize":"16px"},"color":{"text":"#000000","background":"#ffffff"},"border":{"width":"0px","style":"none"}},"className":"is-style-fill"} -->
<div class="wp-block-button has-custom-font-size is-style-fill" style="font-size:16px">
<a class="wp-block-button__link has-text-color has-background wp-element-button" href="<?php echo esc_url( get_permalink( wc_get_page_id( 'shop' ) ) ); ?>" style="border-style:none;border-width:0px;color:#000000;background-color:#ffffff">
<?php echo esc_html( $banner_button ); ?>
</a>
</div>
<!-- /wp:button -->
</div>
<!-- /wp:buttons -->
</div>
<!-- /wp:column -->
<!-- wp:column {"verticalAlignment":"center"} -->
<div class="wp-block-column is-vertically-aligned-center">
<!-- wp:image {"id":1,"sizeSlug":"full","linkDestination":"none"} -->
<figure class="wp-block-image size-full">
<img src="<?php echo esc_url( PatternsHelper::get_image_url( $images, 0, 'images/pattern-placeholders/music-needle-turntable-black-and-white-white-photography.jpg' ) ); ?>" alt="<?php esc_attr_e( 'Placeholder image used to represent products being showcased in a banner.', 'woo-gutenberg-products-block' ); ?>" class="wp-image-1" />
</figure>
<!-- /wp:image -->
</div>
<!-- /wp:column -->
</div>
<!-- /wp:columns -->