From 719b639e23369c2e538c49e2b686cfb6d403045d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Bogda=C5=84ski?= Date: Sat, 7 Dec 2024 23:04:47 +0100 Subject: [PATCH 1/3] =?UTF-8?q?PB-1485=20Zweryfikowa=C4=87=20nieprawid?= =?UTF-8?q?=C5=82owo=20pobran=C4=85=20kwot=C4=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/cart/functions.php | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/includes/cart/functions.php b/includes/cart/functions.php index 662d80c6e8..d69dd5d1ec 100644 --- a/includes/cart/functions.php +++ b/includes/cart/functions.php @@ -179,36 +179,44 @@ function edd_add_to_cart( $download_id, $options = array() ) { $options['price_id'] = explode( ',', $options['price_id'] ); } + $variable_prices = edd_get_variable_prices($download_id); + if ( isset( $options['price_id'] ) && is_array( $options['price_id'] ) ) { // Process multiple price options at once - foreach ( $options['price_id'] as $key => $price ) { + foreach ( $options['price_id'] as $key => $price_id ) { + + $price_id = preg_replace( '/[^0-9]/', '', $price_id ); + if (is_array($variable_prices) && !isset( $variable_prices[$price_id] )) { + $price_id = '0'; + } + $options['price_id'][ $key ] = $price_id; $items[] = array( 'id' => $download_id, 'options' => array( - 'price_id' => preg_replace( '/[^0-9\.-]/', '', $price ) + 'price_id' => $price_id ), 'quantity' => $quantity[ $key ], ); } - } else { + } elseif ( isset( $options['price_id'] ) ) { // Sanitize price IDs - foreach( $options as $key => $option ) { - - if( 'price_id' == $key ) { - $options[ $key ] = preg_replace( '/[^0-9\.-]/', '', $option ); - } - + $price_id = preg_replace( '/[^0-9]/', '', $options['price_id'] ); + if (is_array($variable_prices) && !isset( $variable_prices[ $price_id ] )) { + $price_id = '0'; } + $options['price_id'] = $price_id; // Add a single item $items[] = array( 'id' => $download_id, - 'options' => $options, + 'options' => array( + 'price_id' => $price_id + ), 'quantity' => $quantity ); } @@ -480,6 +488,10 @@ function edd_get_cart_item_price( $download_id = 0, $options = array(), $remove_ } + if( false === $price ) { + $price = edd_get_highest_price_option( $download_id ); + } + if( ! $variable_prices || false === $price ) { // Get the standard Download price if not using variable prices $price = edd_get_download_price( $download_id ); From 654d366c061905d19dca5fc9326ea802c99670cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Bogda=C5=84ski?= Date: Sun, 8 Dec 2024 03:39:37 +0100 Subject: [PATCH 2/3] =?UTF-8?q?PB-1485=20Zweryfikowa=C4=87=20nieprawid?= =?UTF-8?q?=C5=82owo=20pobran=C4=85=20kwot=C4=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/cart/functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/cart/functions.php b/includes/cart/functions.php index d69dd5d1ec..4711da9f07 100644 --- a/includes/cart/functions.php +++ b/includes/cart/functions.php @@ -180,6 +180,7 @@ function edd_add_to_cart( $download_id, $options = array() ) { } $variable_prices = edd_get_variable_prices($download_id); + $items = []; if ( isset( $options['price_id'] ) && is_array( $options['price_id'] ) ) { From c624654601be2247a32550010631015a975c80bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Bogda=C5=84ski?= Date: Tue, 17 Dec 2024 18:18:15 +0100 Subject: [PATCH 3/3] =?UTF-8?q?PB-1485=20Zweryfikowa=C4=87=20nieprawid?= =?UTF-8?q?=C5=82owo=20pobran=C4=85=20kwot=C4=99=20-=20poprawki?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/cart/functions.php | 44 ++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/includes/cart/functions.php b/includes/cart/functions.php index 4711da9f07..c6ef7cfde2 100644 --- a/includes/cart/functions.php +++ b/includes/cart/functions.php @@ -150,11 +150,6 @@ function edd_add_to_cart( $download_id, $options = array() ) { $cart = apply_filters( 'edd_pre_add_to_cart_contents', edd_get_cart_contents() ); - if ( edd_has_variable_prices( $download_id ) && ! isset( $options['price_id'] ) ) { - // Forces to the first price ID if none is specified and download has variable prices - $options['price_id'] = '0'; - } - if( isset( $options['quantity'] ) ) { if ( is_array( $options['quantity'] ) ) { @@ -189,7 +184,7 @@ function edd_add_to_cart( $download_id, $options = array() ) { $price_id = preg_replace( '/[^0-9]/', '', $price_id ); if (is_array($variable_prices) && !isset( $variable_prices[$price_id] )) { - $price_id = '0'; + continue; } $options['price_id'][ $key ] = $price_id; @@ -202,22 +197,33 @@ function edd_add_to_cart( $download_id, $options = array() ) { ); } - - } elseif ( isset( $options['price_id'] ) ) { - - // Sanitize price IDs - $price_id = preg_replace( '/[^0-9]/', '', $options['price_id'] ); - if (is_array($variable_prices) && !isset( $variable_prices[ $price_id ] )) { - $price_id = '0'; + if( empty($items) ) { + //TODO komunikat o błędnych numerach wariantów + return; } - $options['price_id'] = $price_id; + + } else { + if ( isset( $options['price_id'] ) ) { + // Sanitize price IDs + $price_id = preg_replace( '/[^0-9]/', '', $options['price_id'] ); + + if (is_array($variable_prices) && !isset( $variable_prices[ $price_id ] )) { + //TODO komunikat o błędnym numerze wariantu + return; + } + $options['price_id'] = $price_id; + } + else { + if ( is_array($variable_prices) && !empty($variable_prices) ) { + //TODO komunikat o niepodaniu numeru wariantu + return; + } + } // Add a single item $items[] = array( 'id' => $download_id, - 'options' => array( - 'price_id' => $price_id - ), + 'options' => $options, 'quantity' => $quantity ); } @@ -240,11 +246,9 @@ function edd_add_to_cart( $download_id, $options = array() ) { $cart[ $key ]['quantity'] += $quantity; } - } else { - $cart[] = $to_add; - + $cart[] = $to_add; } }