Fix downloads remaining

Issues around ‘’ set (unlimited downloads) Fixes #12692
This commit is contained in:
Mike Jolley 2017-01-03 15:03:55 +00:00
parent 98b79ddf5b
commit 2e1e7c0f93
3 changed files with 10 additions and 9 deletions

View File

@ -135,7 +135,7 @@ class WC_Customer_Download extends WC_Data implements ArrayAccess {
* Get downloads_remaining.
*
* @param string $context
* @return integer
* @return integer|string
*/
public function get_downloads_remaining( $context = 'view' ) {
return $this->get_prop( 'downloads_remaining', $context );
@ -233,10 +233,10 @@ class WC_Customer_Download extends WC_Data implements ArrayAccess {
/**
* Get downloads_remaining.
*
* @param int $value
* @param integer|string $value
*/
public function set_downloads_remaining( $value ) {
$this->set_prop( 'downloads_remaining', absint( $value ) );
$this->set_prop( 'downloads_remaining', '' === $value ? '' : absint( $value ) );
}
/**

View File

@ -98,7 +98,7 @@ class WC_Download_Handler {
* @access private
*/
private static function check_downloads_remaining( $download ) {
if ( 0 >= $download->get_downloads_remaining() ) {
if ( '' !== $download->get_downloads_remaining() && 0 >= $download->get_downloads_remaining() ) {
self::download_error( __( 'Sorry, you have reached your download limit for this file', 'woocommerce' ), '', 403 );
}
}

View File

@ -357,17 +357,18 @@ class WC_Order_Item_Product extends WC_Order_Item {
$order = $this->get_order();
if ( $product && $order && $product->is_downloadable() && $order->is_download_permitted() ) {
$data_store = WC_Data_Store::load( 'customer-download' );
$download_ids = $data_store->get_downloads( array(
$data_store = WC_Data_Store::load( 'customer-download' );
$customer_downloads = $data_store->get_downloads( array(
'user_email' => $order->get_billing_email(),
'order_id' => $order->get_id(),
'product_id' => $this->get_variation_id() ? $this->get_variation_id() : $this->get_product_id(),
'return' => 'ids',
) );
foreach ( $customer_downloads as $customer_download ) {
$download_id = $customer_download->get_download_id();
foreach ( $download_ids as $download_id ) {
if ( $product->has_file( $download_id ) ) {
$files[ $download_id ] = $product->get_file( $download_id );
$file = $product->get_file( $download_id );
$files[ $download_id ] = $file->get_data();
$files[ $download_id ]['download_url'] = $this->get_item_download_url( $download_id );
}
}