Skip to content

Commit

Permalink
Merge branch 'trunk' into feat/40
Browse files Browse the repository at this point in the history
  • Loading branch information
dkotter committed Aug 23, 2024
2 parents 41a280b + 84a1af6 commit 9d569bd
Show file tree
Hide file tree
Showing 13 changed files with 755 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public function add_support() {
add_filter( 'woocommerce_my_subscriptions_payment_method', array( $this, 'maybe_render_payment_method' ), 10, 3 );

// don't copy over order-specific meta to the WC_Subscription object during renewal processing
add_filter( 'wcs_renewal_order_meta', array( $this, 'do_not_copy_order_meta' ) );
add_filter( 'wc_subscriptions_renewal_order_data', array( $this, 'do_not_copy_order_meta' ) );

// process the Change Payment "transaction"
add_filter( 'wc_payment_gateway_' . $this->get_gateway()->get_id() . '_process_payment', array( $this, 'process_change_payment' ), 10, 3 );
Expand Down Expand Up @@ -304,10 +304,9 @@ public function do_not_copy_order_meta( $order_meta ) {

$meta_keys = $this->get_order_specific_meta_keys();

foreach ( $order_meta as $index => $meta ) {

if ( in_array( $meta['meta_key'], $meta_keys, true ) ) {
unset( $order_meta[ $index ] );
foreach ( $meta_keys as $meta_key ) {
if ( isset( $order_meta[ $meta_key ] ) ) {
unset( $order_meta[ $meta_key ] );
}
}

Expand Down
47 changes: 47 additions & 0 deletions includes/Handlers/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function __construct() {

// Add Gift Card "send-to" email address to the order meta.
add_action( 'woocommerce_checkout_create_order_line_item', array( $this, 'add_gift_card_add_to_cart_details_to_order' ), 10, 4 );
add_action( 'woocommerce_add_order_again_cart_item', array( $this, 'reorder_gift_card' ) );
add_filter( 'woocommerce_order_item_display_meta_key', array( $this, 'modify_gift_card_line_item_key' ), 10, 3 );
add_action( 'wc_square_gift_card_activated', array( $this, 'trigger_email_for_gift_card_sent' ) );
add_filter( 'woocommerce_hidden_order_itemmeta', array( $this, 'hide_gift_card_line_item_meta' ) );
Expand Down Expand Up @@ -525,6 +526,52 @@ public function add_gift_card_add_to_cart_details_to_order( $item, $cart_item_ke
}
}

/**
* Adds gift card related order item meta to the order again cart item.
*
* @param array $cart_item_data Cart item data.
*
* @return array
*/
public function reorder_gift_card( $cart_item_data ) {
// Disabling PHPCS check as nonce verification is done in the parent method.
$order_id = absint( wp_unslash( $_GET['order_again'] ?? 0 ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended

if ( ! $order_id ) {
return $cart_item_data;
}

$order = wc_get_order( $order_id );
$order_items = $order->get_items();

if ( empty( $order_items ) ) {
return $cart_item_data;
}

$product = wc_get_product( $cart_item_data['product_id'] );

if ( ! Product::is_gift_card( $product ) ) {
return $cart_item_data;
}

/** @var \WC_Order_Item $order_item */
foreach ( $order_items as $order_item ) {
$order_item_data = $order_item->get_data();
$product = wc_get_product( $order_item_data['product_id'] );

if ( ! Product::is_gift_card( $product ) ) {
continue;
}

$cart_item_data['square-gift-card-send-to-email'] = $order_item->get_meta( 'square-gift-card-send-to-email' );
$cart_item_data['square-gift-card-sender-name'] = $order_item->get_meta( 'square-gift-card-sender-name' );
$cart_item_data['square-gift-card-sent-to-first-name'] = $order_item->get_meta( 'square-gift-card-sent-to-first-name' );
$cart_item_data['square-gift-card-sent-to-message'] = $order_item->get_meta( 'square-gift-card-sent-to-message' );
}

return $cart_item_data;
}

/**
* Filters the meta key into a human-readable format.
*
Expand Down
5 changes: 2 additions & 3 deletions includes/Handlers/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1657,13 +1657,12 @@ private static function update_price_money( $product, \Square\Models\CatalogObje
*/
public static function get_parent_product_id_by_variation_id( $variation_id ) {
global $wpdb;

return $wpdb->get_var(
$wpdb->prepare(
"
SELECT pr.post_parent
FROM wp_posts pr
INNER JOIN wp_posts pp ON pp.ID = pr.post_parent
FROM {$wpdb->prefix}posts pr
INNER JOIN {$wpdb->prefix}posts pp ON pp.ID = pr.post_parent
WHERE pr.ID=%d AND pr.post_type IN ('product', 'product_variation') AND pp.post_type = 'product';
",
$variation_id
Expand Down
14 changes: 14 additions & 0 deletions includes/Sync/Manual_Synchronization.php
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,20 @@ protected function pull_inventory() {

$product->save();

$in_progress['processed_variation_ids'][] = $catalog_object_id;
} else {
Records::set_record(
array(
'type' => 'alert',
'message' => sprintf(
/* translators: %1$s - Item Variation ID */
__( '[Pull Inventory] The product does not exist in the WooCommerce store for the item variation: %1$s.', 'woocommerce-square' ),
$catalog_object_id
),
)
);

// Add the catalog object ID to the processed list to avoid processing it again.
$in_progress['processed_variation_ids'][] = $catalog_object_id;
}

Expand Down
74 changes: 73 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
"version": "4.7.3",
"homepage": "https://woocommerce.com/products/woocommerce-square/",
"scripts": {
"build": "composer install --no-dev && npm run build:webpack && npm run archive",
"build": "composer install --no-dev && npm run build:webpack && npm run makepot && npm run archive",
"build:dev": "composer install && npm run build:webpack",
"build:webpack": "rimraf build/* && wp-scripts build",
"build-watch:webpack": "rimraf build/* && wp-scripts start",
"lint:js": "wp-scripts lint-js src/ --ext js",
"lint:js:fix": "wp-scripts lint-js src/ --ext js --fix",
"phpcompat": "./vendor/bin/phpcs --standard=phpcs-compat.xml.dist -p .",
"update-deps": "npm install -g rimraf && rimraf node_modules && rimraf npm-shrinkwrap.json && npm install && npm shrinkwrap --dev",
"makepot": "wpi18n makepot --domain-path i18n/languages --pot-file woocommerce-square.pot --type plugin --main-file woocommerce-square.php --exclude node_modules,tests,docs",
"archive": "composer archive --file=$npm_package_name --format=zip",
"postarchive": "rm -rf $npm_package_name && unzip $npm_package_name.zip -d $npm_package_name && rm $npm_package_name.zip && zip -r $npm_package_name.zip $npm_package_name && rm -rf $npm_package_name",
"woorelease": "npm run build",
Expand All @@ -37,7 +38,8 @@
"@wordpress/env": "^10.0.0",
"@wordpress/scripts": "^24.6.0",
"copy-webpack-plugin": "^12.0.2",
"dotenv": "^16.4.5"
"dotenv": "^16.4.5",
"node-wp-i18n": "^1.2.7"
},
"engines": {
"node": ">=20",
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/credit-card/checkout-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const CheckoutHandler = ( {
const square = useContext( SquareWebContext );

const {
onPaymentProcessing,
onPaymentSetup,
onCheckoutAfterProcessingWithError,
onCheckoutAfterProcessingWithSuccess,
} = eventRegistration;
Expand All @@ -42,7 +42,7 @@ export const CheckoutHandler = ( {
checkoutFormHandler;

usePaymentProcessing(
onPaymentProcessing,
onPaymentSetup,
emitResponse,
square,
getPaymentMethodData,
Expand Down
8 changes: 4 additions & 4 deletions src/blocks/credit-card/use-payment-processing.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ import { getSquareServerData } from '../square-utils';
* If the checkout has errors, we send `has-checkout-errors` to the server-side so that the status
* of the request can be set to 'ERROR' before gateway validation is done.
*
* @param {Function} onPaymentProcessing Callback for registering observers on the payment processing event
* @param {Function} onPaymentSetup Callback for registering observers on the payment processing event
* @param {EmitResponseProps} emitResponse Helpers for observer response objects
* @param {SquareContext} squareContext Square payment form context variable
* @param {Function} getPaymentMethodData CreateNonce function
* @param {Function} createNonce CreateNonce function
* @param {Function} verifyBuyer VerifyBuyer function
*/
export const usePaymentProcessing = (
onPaymentProcessing,
onPaymentSetup,
emitResponse,
squareContext,
getPaymentMethodData,
Expand Down Expand Up @@ -106,10 +106,10 @@ export const usePaymentProcessing = (
return response;
};

const unsubscribe = onPaymentProcessing( processCheckout );
const unsubscribe = onPaymentSetup( processCheckout );
return unsubscribe;
}, [
onPaymentProcessing,
onPaymentSetup,
emitResponse.responseTypes.SUCCESS,
emitResponse.responseTypes.ERROR,
createNonce,
Expand Down
Loading

0 comments on commit 9d569bd

Please sign in to comment.