Permalink
Browse files

Issue 2163 (#2181)

* Kill more $purchlogitem global usage

* Add utility methods for getting forms data in different ways

* Refactor wpsc_purchaselogs_items to use WPSC_Purchase_Log and WPSC_Checkout_Form_Data objects.

* Favor the get_items() method, over get_cart_contents(). We are not, in fact, getting cart contents - we are getting order items - legacy table names be darned.

* Capitalize classes WPSC_Cart and WPSC_Cart_Item. Backwards-compatible, as PHP class names are case-insensitive.

* Static WPSC_Purchase_Log::update_cache is now just a wrapper for calling the WPSC_Purchase_Log::update_caches method

* Static WPSC_Purchase_Log::delete_cache is now just a wrapper for calling the WPSC_Purchase_Log::delete_caches method

* Fix typos

* Add note about delete_caches params being for back-compat

* Add a contextual document title on sales log view pages

* Scrutinize PR.

* No longer necessary to pass object to update_caches() method.

* Docs improvements.

* Stub for new wpsc_get_order() helper function.

* Log property should be a log object, not checkout form data object.

* Add reset method to WPSC_Query_Base

* Be sure $exists is set with each fetch()

* WPSC_Coupon now also extends WPSC_Query_Base

* add WPSC_Purchase_Log::form_data for initiating WPSC_Checkout_Form_Data object

* fix shipping_name missing last name

* Replace log cart language with "item"

* Update @return docs for the fetch methods

* Implement contact details editing for logs.

* Introduce multiple_meta static key definition, and use to get multiple

Also _wpsc_doing_it_wrong for when get()-ing 'notes' key

* Introduce better sales log notes. Re: #194, for #2165

* Hookup adding/deleting notes via ajax

* Pass item_id to remove_item() method.

* move shipping/billing display output to separate methods

* Hook up ajax-saving for log-page contact-details editing

* Ajax-load payment details as well, since fields are ajax-editable

* Move to proper WP metaboxes on log screen

* Move to proper WP metaboxes on log screen

* Add a edit-contact-details cancel button

* Clean up log pagination styling

* Include item shipping when calculating the total log shipping total

* If we're going to reference a global, we better darn well define it.

* Add helper function for payment gateway support checking

* Add action for registering metaboxes.

* Add base method for processing refunds.

* Minor whitespace and docs cleanup
  • Loading branch information...
1 parent a97791b commit d8f22bf35e19edf1fb5f0d828797c7027a287b60 @JustinSainton JustinSainton committed on GitHub Nov 28, 2016
Showing with 1,887 additions and 606 deletions.
  1. +1 −1 wp-shopping-cart.php
  2. +25 −12 wpsc-admin/admin.php
  3. +2 −4 wpsc-admin/ajax-and-init.php
  4. +123 −8 wpsc-admin/ajax.php
  5. +126 −1 wpsc-admin/css/admin.css
  6. +342 −72 wpsc-admin/display-sales-logs.php
  7. +1 −1 wpsc-admin/includes/purchase-log-action-links.php
  8. +37 −111 wpsc-admin/includes/purchase-logs-page/item-details.php
  9. +21 −21 wpsc-admin/init.php
  10. +146 −6 wpsc-admin/js/purchase-logs.js
  11. +4 −4 wpsc-components/marketplace-core-v1/library/Sputnik.php
  12. +20 −3 wpsc-components/merchant-core-v3/classes/payment-gateway.php
  13. +1 −1 wpsc-components/merchant-core-v3/gateways/worldpay.php
  14. +1 −1 wpsc-components/merchant-core-v3/helpers/admin.php
  15. +5 −1 wpsc-components/merchant-core-v3/helpers/payment-gateway.php
  16. +2 −2 wpsc-components/theme-engine-v2/classes/cart-item-table-order.php
  17. +25 −7 wpsc-components/theme-engine-v2/helpers/css.php
  18. +50 −21 wpsc-components/theme-engine-v2/helpers/template-tags/form.php
  19. +1 −0 wpsc-core/wpsc-includes.php
  20. +1 −1 wpsc-includes/cart-item.class.php
  21. +1 −1 wpsc-includes/cart.class.php
  22. +135 −15 wpsc-includes/checkout-form-data.class.php
  23. +35 −99 wpsc-includes/coupon.class.php
  24. +1 −1 wpsc-includes/google-analytics.class.php
  25. +447 −0 wpsc-includes/purchase-log-notes.class.php
  26. +3 −3 wpsc-includes/purchase-log-notification.class.php
  27. +168 −74 wpsc-includes/purchase-log.class.php
  28. +22 −2 wpsc-includes/purchase-log.helpers.php
  29. +110 −118 wpsc-includes/purchaselogs-items.class.php
  30. +30 −14 wpsc-includes/query-base.class.php
  31. +1 −1 wpsc-includes/stats.functions.php
@@ -143,7 +143,7 @@ public function load_old_textdomain( $mofile, $textdomain ) {
/**
* Sets table names as WPDB properties.
*
- * @since 4.0
+ * @since 4.0.0
* @return array Array of custom tables
*/
public function setup_table_names() {
View
@@ -5,7 +5,7 @@
* These are the main WPSC Admin functions
*
* @package wp-e-commerce
- * @since 3.7
+ * @since 3.7.0
*/
// admin includes
@@ -40,7 +40,7 @@
/**
* wpsc_query_vars_product_list sets the ordering for the edit-products page list
*
- * @since 3.8
+ * @since 3.8.0
* @access public
*
* @uses get_option() Gets option from the DB given key
@@ -90,7 +90,7 @@ function wpsc_admin_edit_posts_orderby( $orderby_sql ) {
/**
* setting the product & variations per page screen option to between 1 and 999
*
- * @since 3.8
+ * @since 3.8.0
* @access public
*
* @uses update_user_option() Updates user option given userid, key, value
@@ -118,7 +118,7 @@ function wpsc_set_screen_option($status, $option, $value){
* @param string $taxonomy Taxonomy.
* @param string $context Context.
*
- * @since 4.0
+ * @since 4.0.0
*
* @return array Filtered dropdown args.
*/
@@ -137,7 +137,7 @@ function wpsc_variation_parent_dropdown_args( $args, $taxonomy, $context ) {
* When rearranging the products for drag and drop it is easiest to arrange them when they are all on the same page...
* @access public
*
- * @since 3.8
+ * @since 3.8.0
* @access public
*
* @uses get_option() Gets option from the database given key
@@ -158,7 +158,7 @@ function wpsc_drag_and_drop_ordering($per_page, $post_type){
/**
* Checks whether to display or hide the update wp-e-commerce link
*
- * @since 3.8
+ * @since 3.8.0
* @access public
*
* @uses get_option() Gets option from DB given key
@@ -391,7 +391,7 @@ function wpsc_add_help_tabs() {
/**
* This function allows change in number of purchase logs shown on Sales Log (Screen Options).
*
- * @since 3.9
+ * @since 3.9.0
* @access public
*
* @uses add_screen_option()
@@ -418,7 +418,14 @@ 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, true );
+ $dependencies = array( 'jquery' );
+
+ if ( isset( $_REQUEST['id'] ) && is_numeric( $_REQUEST['id'] ) ) {
+ wp_enqueue_style( 'wp-admin' );
+ $dependencies[] = 'postbox';
+ }
+
+ wp_enqueue_script( 'wp-e-commerce-purchase-logs', WPSC_URL . '/wpsc-admin/js/purchase-logs.js', $dependencies, 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' ),
@@ -427,15 +434,21 @@ 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' ),
+ 'edit_contact_details_nonce' => _wpsc_create_ajax_nonce( 'edit_contact_details' ),
+ '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' ),
+ 'cancel_btn' => esc_html__( 'Cancel', 'wp-e-commerce' ),
),
) );
@@ -1209,7 +1222,7 @@ function wpsc_print_admin_scripts() {
/**
* wpsc_ajax_ie_save save changes made using inline edit
*
- * @since 3.8
+ * @since 3.8.0
* @access public
*
* @uses get_post_type_object() Gets post object for given registered post type name
@@ -1505,7 +1518,7 @@ function wpsc_support_links( $links ) {
*
* @param array $args Array of removable query args.
*
- * @since 4.0
+ * @since 4.0.0
*
* @return array $args Array of removable query args.
*/
@@ -1522,7 +1535,7 @@ function wpsc_removable_query_args( $args ) {
* @param array $bulk_messages Array of bulk messages.
* @param int $bulk_counts The amount of messages affected.
*
- * @since 4.0
+ * @since 4.0.0
*
* @return array Array of bulk messages.
*/
@@ -6,7 +6,7 @@
* These are the WPSC Admin AJAX functions
*
* @package wp-e-commerce
- * @since 3.7
+ * @since 3.7.0
*
* @uses update_option() Updates option in the database given key and value
* @uses wp_delete_term() Removes term from the database
@@ -80,7 +80,7 @@ function wpsc_admin_ajax() {
/**
* The function that changes the main currency in the DB
- *
+ *
* @uses $wpdb WordPress database object for queries
*/
function wpsc_change_currency() {
@@ -219,5 +219,3 @@ function wpsc_clean_categories() {
}
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ($_REQUEST['wpsc_admin_action'] == 'clean_categories') )
add_action( 'admin_init', 'wpsc_clean_categories' );
-
-
View
@@ -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 );
}
}
@@ -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;
@@ -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 );
@@ -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 );
}
@@ -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() ) {
@@ -581,18 +583,131 @@ 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() : '',
'discount' => wpsc_display_purchlog_discount(),
'total_taxes' => wpsc_display_purchlog_taxes(),
- 'total_shipping' => wpsc_display_purchlog_shipping(),
+ 'total_shipping' => wpsc_display_purchlog_shipping( false, true ),
'final_total' => wpsc_display_purchlog_totalprice(),
);
}
/**
+ * Edit log contact details.
+ *
+ * @since 4.0
+ * @access private
+ *
+ * @return array|WP_Error $return Response args if successful, WP_Error if otherwise
+ */
+function _wpsc_ajax_edit_contact_details() {
+
+ if ( isset( $_POST['log_id'], $_POST['fields'] ) && ! empty( $_POST['fields'] ) ) {
+
+ // Parse the URL query string of the fields array.
+ parse_str( $_POST['fields'], $fields );
+
+ $log_id = absint( $_POST['log_id'] );
+ $log = new WPSC_Purchase_Log( $log_id );
+
+ if ( isset( $fields['wpsc_checkout_details'] ) && is_array( $fields['wpsc_checkout_details'] ) ) {
+ $details = wp_unslash( $fields['wpsc_checkout_details'] );
+
+ // Save the new/updated contact details.
+ WPSC_Checkout_Form_Data::save_form(
+ $log,
+ WPSC_Checkout_Form::get()->get_fields(),
+ array_map( 'sanitize_text_field', $details ),
+ false
+ );
+
+ require_once( WPSC_FILE_PATH . '/wpsc-admin/display-sales-logs.php' );
+
+ $log->init_items();
+
+ // Fetch the shipping/billing formatted output.
+
+ ob_start();
+ WPSC_Purchase_Log_Page::shipping_address_output();
+ $shipping = ob_get_clean();
+
+ ob_start();
+ WPSC_Purchase_Log_Page::billing_address_output();
+ $billing = ob_get_clean();
+
+ ob_start();
+ WPSC_Purchase_Log_Page::payment_details_output();
+ $payment = ob_get_clean();
+
+ return compact( 'shipping', 'billing', 'payment' );
+
+ }
+
+ }
+
+ return new WP_Error( 'wpsc_ajax_invalid_edit_contact_details', __( 'Failed to update contact details for log.', 'wp-e-commerce' ) );
+}
+
+/**
+ * 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.
*
* @since 4.0
Oops, something went wrong.

0 comments on commit d8f22bf

Please sign in to comment.