Skip to content

Commit

Permalink
Merge branch 'trunk' into comp-woo-9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdharmesh authored Sep 20, 2024
2 parents 200787b + 21d7ac0 commit 8726757
Show file tree
Hide file tree
Showing 18 changed files with 328 additions and 76 deletions.
13 changes: 12 additions & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
*** WooCommerce Square Changelog ***

= 4.7.3 - 2024-08-13 =
= 4.8.0 - 2024-09-16 =
* Add - Support for the WooCommerce Product Block Editor.
* Fix - Address a potential infinite loop issue with the `pull_inventory` step when running a manual synchronization.
* Fix - Cancelling Google Pay on checkout shows validation errors.
* Fix - Missing gift card order item meta during re-order.
* Fix - Ensure we don't hardcode the database prefix in queries we run.
* Fix - Replace the use of deprecated hook `wcs_renewal_order_meta` with `wc_subscriptions_renewal_order_data`.
* Update - Change the business location button text based on the location count.
* Dev - Bump WooCommerce "tested up to" version 9.2.
* Dev - Bump WooCommerce minimum supported version to 9.0.

= 4.7.3 - 2024-08-19 =
* Fix - Inconsistency in the height of Express Payment Button and compliance with the new Woo Express Payment Method Styling API.
* Fix - Ensure the "Uncaught TypeError" JavaScript console error does not occur for out-of-stock products.
* Fix - Ensure compatibility with WooPayments extension.
Expand Down
20 changes: 15 additions & 5 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
defined( 'ABSPATH' ) || exit;

use WooCommerce\Square\Admin\Analytics\Revenue;
use WooCommerce\Square\Handlers\Products;
use WooCommerce\Square\Handlers\Product;

/**
Expand Down Expand Up @@ -161,6 +162,8 @@ private function load_scripts_styles( $hook ) {
Plugin::VERSION
);

wp_enqueue_media();

wp_enqueue_script(
'wc-square-admin-settings',
$this->get_plugin()->get_plugin_url() . '/build/assets/admin/wc-square-admin-settings.js',
Expand Down Expand Up @@ -233,15 +236,22 @@ private function load_scripts_styles( $hook ) {
)
);

$gift_card_placeholder_url = Products::get_gift_card_default_placeholder_url();

if ( empty( $gift_card_placeholder_url ) ) {
$gift_card_placeholder_url = WC_SQUARE_PLUGIN_URL . 'build/images/gift-card-featured-image.png';
}

wp_localize_script(
'woocommerce-square-settings-js',
'wcSquareSettings',
array(
'nonce' => wp_create_nonce( 'wc_square_settings' ),
'homeUrl' => home_url(),
'adminUrl' => admin_url(),
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'depsCheck' => $this->get_plugin()->get_dependency_handler()->meets_php_dependencies(),
'nonce' => wp_create_nonce( 'wc_square_settings' ),
'homeUrl' => home_url(),
'adminUrl' => admin_url(),
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'depsCheck' => $this->get_plugin()->get_dependency_handler()->meets_php_dependencies(),
'gcPlaceholderUrl' => esc_url( $gift_card_placeholder_url ),
)
);

Expand Down
4 changes: 2 additions & 2 deletions includes/Admin/Product_Editor_Compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function __construct() {
);

add_action(
'woocommerce_block_template_area_product-form_after_add_block_product-sku-field',
array( $this, 'add_inventory_control' )
'woocommerce_block_template_area_product-form_after_add_block_product-track-stock',
array( $this, 'add_inventory_control' ),
);

add_action(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace WooCommerce\Square\Admin\Rest;

use WooCommerce\Square\Gateway\Gift_Card;
use WP_REST_Server;
use WP_REST_Request;
use WP_REST_Response;
Expand All @@ -18,13 +19,6 @@
*/
class WC_REST_Square_Gift_Cards_Settings_Controller extends WC_Square_REST_Base_Controller {

/**
* Square settings option name.
*
* @var string
*/
const SQUARE_PAYMENT_SETTINGS_OPTION_NAME = 'woocommerce_gift_cards_pay_settings';

/**
* Endpoint path.
*
Expand All @@ -47,6 +41,8 @@ public function __construct() {
'enabled',
'title',
'description',
'is_default_placeholder',
'placeholder_id',
);

add_action( 'rest_api_init', array( $this, 'register_routes' ) );
Expand All @@ -73,21 +69,31 @@ public function register_routes() {
'callback' => array( $this, 'save_settings' ),
'permission_callback' => array( $this, 'check_permission' ),
'args' => array(
'enabled' => array(
'enabled' => array(
'description' => __( 'Enable Square payment gateway.', 'woocommerce-square' ),
'type' => 'string',
'sanitize_callback' => '',
),
'title' => array(
'title' => array(
'description' => __( 'Square payment gateway title.', 'woocommerce-square' ),
'type' => 'string',
'sanitize_callback' => '',
),
'description' => array(
'description' => array(
'description' => __( 'Square payment gateway description.', 'woocommerce-square' ),
'type' => 'string',
'sanitize_callback' => '',
),
'is_default_placeholder' => array(
'description' => __( 'Indicates if a Gift card product should use the default placeholder provided by the plugin.', 'woocommerce-square' ),
'type' => 'string',
'sanitize_callback' => '',
),
'placeholder_id' => array(
'description' => __( 'ID of the placeholder media.', 'woocommerce-square' ),
'type' => 'integer',
'sanitize_callback' => '',
),
),
)
);
Expand All @@ -99,7 +105,7 @@ public function register_routes() {
* @return WP_REST_Response
*/
public function get_settings() {
$square_settings = get_option( self::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, array() );
$square_settings = get_option( Gift_Card::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, array() );
$filtered_settings = array_intersect_key( $square_settings, array_flip( $this->allowed_params ) );

return new WP_REST_Response( $filtered_settings );
Expand All @@ -119,7 +125,15 @@ public function save_settings( WP_REST_Request $request ) {
$settings[ $key ] = $new_value;
}

update_option( self::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, $settings );
update_option( Gift_Card::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, $settings );

/**
* Action triggered when the Gift card payment settings are updated.
*
* @since x.x.x
*/
do_action( 'wc_square_' . Gift_Card::SQUARE_PAYMENT_SETTINGS_OPTION_NAME . '_settings_updated', $settings );

wp_send_json_success();
}
}
52 changes: 46 additions & 6 deletions includes/Gateway/Gift_Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@

use WooCommerce\Square\Plugin;
use WooCommerce\Square\Framework\Square_Helper;
use WooCommerce\Square\Handlers\Products;
use WooCommerce\Square\Handlers\Product;
use WooCommerce\Square\Utilities\Money_Utility;
use WooCommerce\Square\Framework\PaymentGateway\Payment_Gateway;
use WooCommerce\Square\Gateway;

class Gift_Card extends Payment_Gateway {
/**
* Square settings option name.
*
* @var string
*/
const SQUARE_PAYMENT_SETTINGS_OPTION_NAME = 'woocommerce_gift_cards_pay_settings';

/**
* @var API API base instance
*/
Expand Down Expand Up @@ -43,7 +51,8 @@ public function __construct() {
)
);

add_action( 'init', array( $this, 'add_gift_card_image_placeholder' ) );
add_action( 'wc_square_woocommerce_gift_cards_pay_settings_settings_updated', array( $this, 'add_gift_card_image_placeholder' ) );
add_action( 'delete_attachment', array( $this, 'delete_gift_card_image_placeholder' ) );
add_action( 'wp_ajax_wc_square_check_gift_card_balance', array( $this, 'apply_gift_card' ) );
add_action( 'wp_ajax_nopriv_wc_square_check_gift_card_balance', array( $this, 'apply_gift_card' ) );
add_action( 'wp_ajax_wc_square_gift_card_remove', array( $this, 'remove_gift_card' ) );
Expand Down Expand Up @@ -201,8 +210,12 @@ public static function does_checkout_support_gift_card() {
*
* @since 4.2.0
*/
public function add_gift_card_image_placeholder() {
$placeholder_image = get_option( 'wc_square_gift_card_placeholder_id', false );
public function add_gift_card_image_placeholder( $settings ) {
if ( ! \WooCommerce\Square\Handlers\Products::should_use_default_gift_card_placeholder_image() ) {
return;
}

$placeholder_image = Products::get_gift_card_default_placeholder_id();

if ( ! empty( $placeholder_image ) ) {
if ( ! is_numeric( $placeholder_image ) ) {
Expand All @@ -221,7 +234,8 @@ public function add_gift_card_image_placeholder() {
}

if ( ! file_exists( $filename ) ) {
update_option( 'wc_square_gift_card_placeholder_id', 0 );
$settings['placeholder_id'] = 0;
update_option( self::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, $settings );
return;
}

Expand All @@ -237,11 +251,13 @@ public function add_gift_card_image_placeholder() {
$attach_id = wp_insert_attachment( $attachment, $filename );

if ( is_wp_error( $attach_id ) ) {
update_option( 'wc_square_gift_card_placeholder_id', 0 );
$settings['placeholder_id'] = 0;
update_option( self::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, $settings );
return;
}

update_option( 'wc_square_gift_card_placeholder_id', $attach_id );
$settings['placeholder_id'] = $attach_id;
update_option( self::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, $settings );

// Make sure that this file is included, as wp_generate_attachment_metadata() depends on it.
require_once ABSPATH . 'wp-admin/includes/image.php';
Expand All @@ -251,6 +267,30 @@ public function add_gift_card_image_placeholder() {
wp_update_attachment_metadata( $attach_id, $attach_data );
}

/**
* Disables the `Gift card product placeholder image` setting when the
* gift card placeholder image is deleted from the library.
*
* @since x.x.x
*
* @param int $post_id Attachment ID of the media being deleted.
*/
public function delete_gift_card_image_placeholder( $post_id ) {
$attachment_id = Products::get_gift_card_default_placeholder_id();
$gift_card_settings = get_option( self::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, array() );

if ( $attachment_id !== $post_id ) {
return;
}

if ( isset( $gift_card_settings['is_default_placeholder'] ) && 'yes' === $gift_card_settings['is_default_placeholder'] ) {
$gift_card_settings['is_default_placeholder'] = 'no';
$gift_card_settings['placeholder_id'] = 0;

update_option( self::SQUARE_PAYMENT_SETTINGS_OPTION_NAME, $gift_card_settings );
}
}

/**
* Returns true if the cart contains a Gift Card.
* False otherwise.
Expand Down
Loading

0 comments on commit 8726757

Please sign in to comment.