Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/pb 1485 #62

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions includes/cart/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) {

Expand All @@ -179,36 +174,56 @@ function edd_add_to_cart( $download_id, $options = array() ) {
$options['price_id'] = explode( ',', $options['price_id'] );
}

$variable_prices = edd_get_variable_prices($download_id);
$items = [];

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] )) {
continue;
}
$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 ],
);

}
if( empty($items) ) {
//TODO komunikat o błędnych numerach wariantów
return;
}

} else {

// Sanitize price IDs
foreach( $options as $key => $option ) {

if( 'price_id' == $key ) {
$options[ $key ] = preg_replace( '/[^0-9\.-]/', '', $option );
}

}
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' => $options,
'options' => $options,
'quantity' => $quantity
);
}
Expand All @@ -231,11 +246,9 @@ function edd_add_to_cart( $download_id, $options = array() ) {
$cart[ $key ]['quantity'] += $quantity;
}


} else {

$cart[] = $to_add;

$cart[] = $to_add;
}
}

Expand Down Expand Up @@ -480,6 +493,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 );
Expand Down