Skip to content

Commit

Permalink
Merge 777306a into 7f89c76
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Nov 6, 2016
2 parents 7f89c76 + 777306a commit 0d3ec45
Show file tree
Hide file tree
Showing 24 changed files with 2,661 additions and 1,247 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -20,3 +20,5 @@ release.sh

.sass-cache
*.codekit

notes.md
14 changes: 12 additions & 2 deletions wpsc-admin/admin.php
Expand Up @@ -18,7 +18,9 @@
require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/duplicate-product-class.php' );
require_once( WPSC_FILE_PATH . '/wpsc-admin/includes/updating-functions.php' );
require_once( WPSC_FILE_PATH . '/wpsc-admin/display-coupons.php' );
require_once( WPSC_FILE_PATH . '/wpsc-includes/purchaselogs.functions.php' );
require_once( WPSC_FILE_PATH . '/wpsc-includes/purchaselogs.class.php' );
require_once( WPSC_FILE_PATH . '/wpsc-includes/purchaselogs-items.class.php' );
require_once( WPSC_FILE_PATH . '/wpsc-includes/theming.class.php' );
require_once( WPSC_FILE_PATH . '/wpsc-admin/ajax.php' );
require_once( WPSC_FILE_PATH . '/wpsc-admin/init.php' );
Expand Down Expand Up @@ -416,21 +418,29 @@ function wpsc_admin_include_purchase_logs_css_and_js() {

_wpsc_enqueue_wp_e_commerce_admin();

wp_enqueue_script( 'wp-e-commerce-purchase-logs', WPSC_URL . '/wpsc-admin/js/purchase-logs.js', array( 'jquery' ), WPSC_VERSION . '.' . WPSC_MINOR_VERSION );
wp_enqueue_script( 'wp-e-commerce-purchase-logs', WPSC_URL . '/wpsc-admin/js/purchase-logs.js', array( 'jquery' ), WPSC_VERSION . '.' . WPSC_MINOR_VERSION, true );
wp_localize_script( 'wp-e-commerce-purchase-logs', 'WPSC_Purchase_Logs_Admin', array(
'nonce' => wp_create_nonce( 'wpsc_purchase_logs' ),
'change_purchase_log_status_nonce' => _wpsc_create_ajax_nonce( 'change_purchase_log_status' ),
'purchase_log_save_tracking_id_nonce' => _wpsc_create_ajax_nonce( 'purchase_log_save_tracking_id' ),
'purchase_log_send_tracking_email_nonce' => _wpsc_create_ajax_nonce( 'purchase_log_send_tracking_email' ),
'remove_log_item_nonce' => _wpsc_create_ajax_nonce( 'remove_log_item' ),
'update_log_item_qty_nonce' => _wpsc_create_ajax_nonce( 'update_log_item_qty' ),
'add_log_item_nonce' => _wpsc_create_ajax_nonce( 'add_log_item' ),
'search_products_nonce' => _wpsc_create_ajax_nonce( 'search_products' ),
'sending_message' => _x( 'sending...', 'sending tracking email for purchase log', 'wp-e-commerce' ),
'sent_message' => _x( 'Email Sent!', 'sending tracking email for purchase log', 'wp-e-commerce' ),
'current_view' => empty( $_REQUEST['status'] ) ? 'all' : $_REQUEST['status'],
'current_filter' => empty( $_REQUEST['m'] ) ? '' : $_REQUEST['m'],
'current_page' => empty( $_REQUEST['paged'] ) ? '' : $_REQUEST['paged'],
'strings' => array(
'confirm_delete' => esc_html__( 'Are you sure you want to remove this item?', 'wp-e-commerce' ),
'search_head' => esc_html__( 'Search for Products to Add', 'wp-e-commerce' ),
),
) );

// Purchase Log Action Links
wp_enqueue_script( 'wpsc-purchase-log-action-links', WPSC_URL . '/wpsc-admin/js/purchase-log-action-links.js', array( 'jquery' ), WPSC_VERSION . '.' . WPSC_MINOR_VERSION );
wp_enqueue_script( 'wpsc-purchase-log-action-links', WPSC_URL . '/wpsc-admin/js/purchase-log-action-links.js', array( 'jquery' ), WPSC_VERSION . '.' . WPSC_MINOR_VERSION, true );
wp_localize_script( 'wpsc-purchase-log-action-links', 'WPSC_Purchase_Log_Action_Links', array(
'purchase_log_action_link_nonce' => _wpsc_create_ajax_nonce( 'purchase_log_action_link' ),
'log_id' => empty( $_REQUEST['id'] ) ? '' : absint( $_REQUEST['id'] )
Expand Down
205 changes: 204 additions & 1 deletion wpsc-admin/ajax.php
@@ -1,5 +1,4 @@
<?php

/**
* Verify nonce of an AJAX request
*
Expand Down Expand Up @@ -455,6 +454,210 @@ function _wpsc_ajax_purchase_log_action_link() {

}

/**
* Remove purchase log item.
*
* @since 4.0
* @access private
*
* @return array|WP_Error $return Response args if successful, WP_Error if otherwise
*/
function _wpsc_ajax_remove_log_item() {

if ( isset( $_POST['item_id'], $_POST['log_id'] ) ) {

$item_id = absint( $_POST['item_id'] );
$log_id = absint( $_POST['log_id'] );
$log = new WPSC_Purchase_Log( $log_id );

if ( $log->remove_cart_item( $item_id ) ) {
return _wpsc_init_log_items( $log );
}
}

return new WP_Error( 'wpsc_ajax_invalid_remove_log_item', __( 'Removing log item failed.', 'wp-e-commerce' ) );
}

/**
* Update purchase log item quantity.
*
* @since 4.0
* @access private
*
* @return array|WP_Error $return Response args if successful, WP_Error if otherwise
*/
function _wpsc_ajax_update_log_item_qty() {

if ( isset( $_POST['item_id'], $_POST['log_id'], $_POST['qty'] ) ) {

if ( empty( $_POST['qty'] ) ) {
return _wpsc_ajax_remove_log_item();
}

$item_id = absint( $_POST['item_id'] );
$log_id = absint( $_POST['log_id'] );
$log = new WPSC_Purchase_Log( $log_id );
$result = $log->update_cart_item( $item_id, array( 'quantity' => absint( $_POST['qty'] ) ) );

if ( 0 === $result ) {
return true;
} elseif ( false !== $result ) {
return _wpsc_init_log_items( $log );
}
}

return new WP_Error( 'wpsc_ajax_invalid_update_log_item_qty', __( 'Updating log item quantity failed.', 'wp-e-commerce' ) );
}

/**
* Add purchase log item.
*
* @since 4.0
* @access private
*
* @return array|WP_Error $return Response args if successful, WP_Error if otherwise
*/
function _wpsc_ajax_add_log_item() {
global $wpsc_cart;

if (
isset( $_POST['product_ids'], $_POST['log_id'] )
&& is_array( $_POST['product_ids'] )
&& ! empty( $_POST['product_ids'] )
) {

$existing = isset( $_POST['existing'] ) && is_array( $_POST['existing'] )
? array_map( 'absint', $_POST['existing'] )
: false;

$item_ids = array();

foreach ( $_POST['product_ids'] as $product_id ) {
$product_id = absint( $product_id );
$log_id = absint( $_POST['log_id'] );
$log = new WPSC_Purchase_Log( $log_id );

// Is product is already in item list?
if ( $existing && in_array( $product_id, $existing, true ) ) {
$item = $log->get_cart_item_from_product_id( $product_id );
if ( $item ) {
// Update item quantity...
$log->update_cart_item( $item->id, array( 'quantity' => ++$item->quantity ) );
// And move on.
continue;
}
}

$item = new wpsc_cart_item( $product_id, array(), $wpsc_cart );
$item_id = $item->save_to_db( $log_id );
$item_ids[] = absint( $item_id );
}

return _wpsc_init_log_items( $log, $item_ids );
}

return new WP_Error( 'wpsc_ajax_invalid_add_log_item', __( 'Adding log item failed.', 'wp-e-commerce' ) );
}

function _wpsc_init_log_items( WPSC_Purchase_Log $log, $item_ids = array() ) {
$log->init_items();

require_once( WPSC_FILE_PATH . '/wpsc-admin/display-sales-logs.php' );

$html = '';
$htmls[] = array();

while ( wpsc_have_purchaselog_details() ) {
wpsc_the_purchaselog_item();

ob_start();
WPSC_Purchase_Log_Page::purchase_log_cart_item( $log->can_edit() );
$cart_item = ob_get_clean();

$htmls[ wpsc_purchaselog_details_id() ] = $cart_item;
if ( ! empty( $item_ids ) && in_array( absint( wpsc_purchaselog_details_id() ), $item_ids, true ) ) {
$html .= $cart_item;
}
}

return array(
'quantities' => wp_list_pluck( $log->get_items(), 'quantity', 'id' ),
'html' => $html,
'htmls' => $htmls,
'discount_data' => wpsc_purchlog_has_discount_data() ? esc_html__( 'Coupon Code', 'wp-e-commerce' ) . ': ' . wpsc_display_purchlog_discount_data() : '',
'discount' => wpsc_display_purchlog_discount(),
'total_taxes' => wpsc_display_purchlog_taxes(),
'total_shipping' => wpsc_display_purchlog_shipping(),
'final_total' => wpsc_display_purchlog_totalprice(),
);
}

/**
* Search for products.
*
* @since 4.0
* @access private
*
* @return array|WP_Error $return Response args if successful, WP_Error if otherwise
*/
function _wpsc_ajax_search_products() {
$pt_object = get_post_type_object( 'wpsc-product' );

$s = wp_unslash( $_POST['search'] );
$args = array(
'post_type' => 'wpsc-product',
'post_status' => array( 'publish', 'inherit' ),
'posts_per_page' => 50,
);
if ( '' !== $s ) {
$args['s'] = $s;
}

$posts = get_posts( $args );

if ( ! $posts ) {
return new WP_Error( 'wpsc_ajax_invalid_search_products', __( 'No items found.', 'wp-e-commerce' ) );
}

$alt = '';
foreach ( $posts as $post ) {
$post->title = trim( $post->post_title ) ? $post->post_title : __( '(no title)' );
$alt = ( 'alternate' === $alt ) ? '' : 'alternate';

$post->status = $post->post_status;

switch ( $post->post_status ) {
case 'publish' :
case 'private' :
$post->status = __( 'Published' );
break;
case 'future' :
$post->status = __( 'Scheduled' );
break;
case 'pending' :
$post->status = __( 'Pending Review' );
break;
case 'draft' :
$post->status = __( 'Draft' );
break;
default :
$post->status = $post->post_status;
break;
}

if ( '0000-00-00 00:00:00' === $post->post_date ) {
$post->time = '';
} else {
/* translators: date format in table columns, see https://secure.php.net/date */
$post->time = mysql2date( __( 'Y/m/d' ), $post->post_date );
}

$post->class = $alt;
}

return $posts;
}

/**
* Handle AJAX clear downloads lock purchase log action
*
Expand Down
10 changes: 10 additions & 0 deletions wpsc-admin/css/admin.css
Expand Up @@ -213,6 +213,16 @@ th#status {
clear: both;
}

.wpsc-remove-item-button {
background: none;
border: none;
line-height: 1.60em;
}

.wpsc_item_qty {
width: 4em;
}

.wpsc_pushdown_img {
float: left;
}
Expand Down

0 comments on commit 0d3ec45

Please sign in to comment.