Skip to content

Commit

Permalink
Merge e68935c into 1ea8329
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Nov 15, 2016
2 parents 1ea8329 + e68935c commit 75f5a06
Show file tree
Hide file tree
Showing 26 changed files with 1,560 additions and 466 deletions.
6 changes: 5 additions & 1 deletion wpsc-admin/admin.php
Expand Up @@ -427,14 +427,18 @@ function wpsc_admin_include_purchase_logs_css_and_js() {
'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' ),
'add_note_nonce' => _wpsc_create_ajax_nonce( 'add_note' ),
'delete_note_nonce' => _wpsc_create_ajax_nonce( 'delete_note' ),
'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'],
'log_id' => isset( $_REQUEST['id'] ) ? absint( $_REQUEST['id'] ) : 0,
'strings' => array(
'confirm_delete' => esc_html__( 'Are you sure you want to remove this item?', 'wp-e-commerce' ),
'confirm_delete_item' => esc_html__( 'Are you sure you want to remove this item?', 'wp-e-commerce' ),
'confirm_delete_note' => esc_html__( 'Are you sure you want to delete this note?', 'wp-e-commerce' ),
'search_head' => esc_html__( 'Search for Products to Add', 'wp-e-commerce' ),
),
) );
Expand Down
73 changes: 66 additions & 7 deletions wpsc-admin/ajax.php
Expand Up @@ -470,7 +470,7 @@ function _wpsc_ajax_remove_log_item() {
$log_id = absint( $_POST['log_id'] );
$log = new WPSC_Purchase_Log( $log_id );

if ( $log->remove_cart_item( $item_id ) ) {
if ( $log->remove_item( $item_id ) ) {
return _wpsc_init_log_items( $log );
}
}
Expand All @@ -497,7 +497,7 @@ function _wpsc_ajax_update_log_item_qty() {
$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'] ) ) );
$result = $log->update_item( $item_id, array( 'quantity' => absint( $_POST['qty'] ) ) );

if ( 0 === $result ) {
return true;
Expand Down Expand Up @@ -531,6 +531,7 @@ function _wpsc_ajax_add_log_item() {
: false;

$item_ids = array();
$log = null;

foreach ( $_POST['product_ids'] as $product_id ) {
$product_id = absint( $product_id );
Expand All @@ -539,17 +540,17 @@ function _wpsc_ajax_add_log_item() {

// 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 );
$item = $log->get_item_from_product_id( $product_id );
if ( $item ) {
// Update item quantity...
$log->update_cart_item( $item->id, array( 'quantity' => ++$item->quantity ) );
$log->update_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 = new wpsc_cart_item( $product_id, array(), $wpsc_cart );
$item_id = $item->save_to_db( $log_id );
$item_ids[] = absint( $item_id );
}

Expand All @@ -565,6 +566,7 @@ function _wpsc_init_log_items( WPSC_Purchase_Log $log, $item_ids = array() ) {
require_once( WPSC_FILE_PATH . '/wpsc-admin/display-sales-logs.php' );

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

while ( wpsc_have_purchaselog_details() ) {
Expand All @@ -581,7 +583,7 @@ function _wpsc_init_log_items( WPSC_Purchase_Log $log, $item_ids = array() ) {
}

return array(
'quantities' => wp_list_pluck( $log->get_cart_contents(), 'quantity', 'id' ),
'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() : '',
Expand All @@ -592,6 +594,63 @@ function _wpsc_init_log_items( WPSC_Purchase_Log $log, $item_ids = array() ) {
);
}

/**
* Add a note to a log.
*
* @since 4.0
* @access private
*
* @return array|WP_Error $return Response args if successful, WP_Error if otherwise
*/
function _wpsc_ajax_add_note() {

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

$result = wpsc_purchlogs_update_notes(
absint( $_POST['log_id'] ),
wp_kses_post( wp_unslash( $_POST['note'] ) )
);

if ( $result instanceof WPSC_Purchase_Log_Notes ) {
require_once( WPSC_FILE_PATH . '/wpsc-admin/display-sales-logs.php' );

$data = $result->get_data();
$keys = array_keys( $data );
$note_id = end( $keys );
$note_args = end( $data );

ob_start();
WPSC_Purchase_Log_Page::note_output( $result, $note_id, $note_args );
$row = ob_get_clean();

return $row;
}
}

return new WP_Error( 'wpsc_ajax_invalid_add_note', __( 'Failed adding log note.', 'wp-e-commerce' ) );
}

/**
* Delete a note from a log.
*
* @since 4.0
* @access private
*
* @return array|WP_Error $return Response args if successful, WP_Error if otherwise
*/
function _wpsc_ajax_delete_note() {

if ( isset( $_POST['log_id'], $_POST['note'] ) && is_numeric( $_POST['note'] ) ) {

$notes = wpsc_get_order_notes( absint( $_POST['log_id'] ) );
$notes->remove( absint( $_POST['note'] ) )->save();

return true;
}

return new WP_Error( 'wpsc_ajax_invalid_delete_note', __( 'Failed to delete log note.', 'wp-e-commerce' ) );
}

/**
* Search for products.
*
Expand Down
91 changes: 90 additions & 1 deletion wpsc-admin/css/admin.css
Expand Up @@ -213,12 +213,23 @@ th#status {
clear: both;
}

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

.wpsc-remove-button .dashicons {
color:#a00;
}

.wpsc-add-row {
border: 1px solid #ddd;
padding: 10px 0;
border-left: 0;
border-right: 0;
}

.wpsc_item_qty {
width: 4em;
}
Expand All @@ -227,6 +238,52 @@ th#status {
float: left;
}

.wpsc-notes {
margin: 5px 0 20px;
}

.wpsc-note {
position: relative;
padding: 1px 1em 1px;
margin: 8px 0;
}

.wpsc-note > p {
border-bottom: 1px solid #ddd;
padding-bottom: 1em;
height: 1.5em;
}

.wpsc-note .note-number {
opacity: .5;
padding-left: 5px;
}

.wpsc-note:nth-child( 2n ) {
background: #f7f7f7;
}

.wpsc-note .wpsc-remove-button {
float: right;
margin-top: -3px;
text-decoration: none;
color: #444;
}

.wpsc-note .wpsc-remove-button .spinner {
float: left;
margin-top: 0;
}

.note-submit {
display: inline-block;
}

#purchlogs_notes .inside {
margin-top: 0;
margin-bottom: 0;
}

#wpsc_purchlogitems_links {
clear: both;
}
Expand Down Expand Up @@ -328,6 +385,38 @@ th#status {
text-align: right;
}

.edit-log-details {
font-size: .8em;
padding-left: 5px;
}

@media screen and ( min-width: 620px ) {
#wpsc-customer-settings-form fieldset {
float: left;
min-width: 300px;
margin-right: 10px;
}
#wpsc-customer-settings-form fieldset [type="text"] {
min-width: 280px;
}
}

.wpsc-form-actions {
clear: both;
}

#edit-shipping-billing {
padding: 18px 18px 0;
background: #fff;
border: 1px solid #e5e5e5;
-webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.04);
box-shadow: 0 1px 1px rgba(0,0,0,0.04);
clear: both;
}

#edit-shipping-billing .wpsc-form-actions {
margin-bottom: 0;
}

/**
* Display Products CSS starts here
Expand Down

0 comments on commit 75f5a06

Please sign in to comment.