Пример #1
0
 /**
  * Handles the process of adding a ticket product to the cart.
  *
  * If the cart already contains a line item for the same product, simply increment the
  * quantity for that item accordingly.
  *
  * @see bug #28917
  * @param $product_id
  * @param $quantity
  */
 protected function add_ticket_to_cart($product_id, $quantity)
 {
     // Is the item in the cart already? Simply adjust the quantity if so
     if (edd_item_in_cart($product_id)) {
         $existing_quantity = edd_get_cart_item_quantity($product_id);
         $quantity += $existing_quantity;
         edd_set_cart_item_quantity($product_id, $quantity);
     } else {
         $options = array('quantity' => $quantity);
         edd_add_to_cart($product_id, $options);
     }
 }
/**
 * Validates the supplied discount sent via AJAX.
 *
 * @since 1.0
 * @return void
 */
function edd_ajax_update_cart_item_quantity()
{
    if (!empty($_POST['quantity']) && !empty($_POST['download_id'])) {
        $download_id = absint($_POST['download_id']);
        $quantity = absint($_POST['quantity']);
        $options = json_decode(stripslashes($_POST['options']), true);
        edd_set_cart_item_quantity($download_id, absint($_POST['quantity']), $options);
        $total = edd_get_cart_total();
        $return = array('download_id' => $download_id, 'quantity' => $quantity, 'taxes' => html_entity_decode(edd_cart_tax(), ENT_COMPAT, 'UTF-8'), 'subtotal' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'));
        // Allow for custom cart item quantity handling
        $return = apply_filters('edd_ajax_cart_item_quantity_response', $return);
        echo json_encode($return);
    }
    edd_die();
}
Пример #3
0
/**
 * Process cart updates, primarily for quantities
 *
 * @since 1.7
 */
function edd_process_cart_update($data)
{
    foreach ($data['edd-cart-downloads'] as $key => $cart_download_id) {
        $options = maybe_unserialize(stripslashes($data['edd-cart-download-' . $key . '-options']));
        $quantity = absint($data['edd-cart-download-' . $key . '-quantity']);
        edd_set_cart_item_quantity($cart_download_id, $quantity, $options);
    }
}
/**
 * Validates the supplied discount sent via AJAX.
 *
 * @since 1.0
 * @return void
 */
function edd_ajax_update_cart_item_quantity()
{
    if (!empty($_POST['quantity']) && !empty($_POST['download_id'])) {
        $download_id = absint($_POST['download_id']);
        $quantity = absint($_POST['quantity']);
        $options = maybe_unserialize(stripslashes($_POST['options']));
        edd_set_cart_item_quantity($download_id, absint($_POST['quantity']), $options);
        $total = edd_get_cart_total();
        $return = array('download_id' => $download_id, 'quantity' => $quantity, 'taxes' => html_entity_decode(edd_cart_tax(), ENT_COMPAT, 'UTF-8'), 'subtotal' => html_entity_decode(edd_currency_filter(edd_format_amount(edd_get_cart_subtotal())), ENT_COMPAT, 'UTF-8'), 'total' => html_entity_decode(edd_currency_filter(edd_format_amount($total)), ENT_COMPAT, 'UTF-8'));
        echo json_encode($return);
    }
    edd_die();
}