Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wpsc-components/merchant-core-v2/helpers/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function _wpsc_filter_merchant_v2_payment_method_form_fields( $fields ) {

if ( empty( $selected_value ) ) {
$current_purchase_log_id = wpsc_get_customer_meta( 'current_purchase_log_id' );
$purchase_log = new WPSC_Purchase_Log( $current_purchase_log_id );
$purchase_log = wpsc_get_order( $current_purchase_log_id );
$selected_value = $purchase_log->get( 'gateway' );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public static function get_instance( $gateway ) {
}

public function set_purchase_log( $id ) {
$this->log = new WPSC_Purchase_Log( $id );
$this->log = wpsc_get_order( $id );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ protected function set_purchase_log_for_callbacks( $sessionid = false ) {
}

// Create a new Purchase Log entry
$purchase_log = new WPSC_Purchase_Log( $sessionid, 'sessionid' );
$purchase_log = wpsc_get_order( $sessionid, 'sessionid' );

if ( ! $purchase_log->exists() ) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions wpsc-components/merchant-core-v3/gateways/paypal-pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ protected function set_purchase_log_for_callbacks( $id = false, $sessionid = fal

// Create a new Purchase Log entry
if ( $sessionid === 'sessionid' ) {
$purchase_log = new WPSC_Purchase_Log( $id, 'sessionid' );
$purchase_log = wpsc_get_order( $id, 'sessionid' );
} else {
$purchase_log = new WPSC_Purchase_Log( $id, 'id' );
$purchase_log = wpsc_get_order( $id, 'id' );
}

if ( ! $purchase_log->exists() ) {
Expand Down
4 changes: 2 additions & 2 deletions wpsc-components/merchant-core-v3/gateways/worldpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public function execute( $endpoint, $params = array(), $type = 'POST' ) {
public function type_of_goods( $log_id ) {
$digital = 0;

$log = new WPSC_Purchase_Log( $log_id );
$log = wpsc_get_order( $log_id );
$cart = $log->get_items();

foreach ( $cart as $cartitem ) {
Expand Down Expand Up @@ -460,7 +460,7 @@ public static function get_instance( $gateway ) {
}

public function set_purchase_log( $id ) {
$this->log = new WPSC_Purchase_Log( $id );
$this->log = wpsc_get_order( $id );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion wpsc-components/merchant-core-v3/helpers/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function _wpsc_filter_merchant_v3_payment_method_form_fields( $fields ) {

if ( empty( $selected_value ) ) {
$current_purchase_log_id = wpsc_get_customer_meta( 'current_purchase_log_id' );
$purchase_log = new WPSC_Purchase_Log( $current_purchase_log_id );
$purchase_log = wpsc_get_order( $current_purchase_log_id );
$selected_value = $purchase_log->get( 'gateway' );
}

Expand Down
2 changes: 1 addition & 1 deletion wpsc-components/theme-engine-v1/helpers/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ function wpsc_submit_checkout( $collected_data = true ) {
'wpec_taxes_rate' => $tax_percentage,
);

$purchase_log = new WPSC_Purchase_Log( $args );
$purchase_log = wpsc_get_order( $args );
$purchase_log->save();
$purchase_log_id = $purchase_log->get( 'id' );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function transaction_results( $sessionid, $display_to_screen = true, $transactio
// pre-3.8.9 variable
$echo_to_screen = $display_to_screen;

$purchase_log_object = new WPSC_Purchase_Log( $sessionid, 'sessionid' );
$purchase_log_object = wpsc_get_order( $sessionid, 'sessionid' );

// compatibility with pre-3.8.9 templates where they use a global
// $purchase_log object which is simply just a database row
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct( $id ) {
$this->show_thumbnails = true;
$this->show_shipping = true;

$this->log = new WPSC_Purchase_Log( $id );
$this->log = wpsc_get_order( $id );
$this->items = $this->get_items();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function get_instance( $purchase_log = false ) {
}

if ( is_int( $purchase_log ) ) {
$purchase_log = new WPSC_Purchase_Log( $purchase_log );
$purchase_log = wpsc_get_order( $purchase_log );
}

$id = $purchase_log->get( 'id' );
Expand Down Expand Up @@ -76,7 +76,7 @@ public function __construct( $purchase_log = false ) {

// in case of integer argument, initialize the purchase log object
if ( ! is_object( $purchase_log ) ) {
$purchase_log = new WPSC_Purchase_Log( absint( $purchase_log ) );
$purchase_log = wpsc_get_order( absint( $purchase_log ) );
}

$this->purchase_log = $purchase_log;
Expand Down Expand Up @@ -171,7 +171,7 @@ private function get_active_shipping() {

$current_purchase_log_id = wpsc_get_customer_meta( 'current_purchase_log_id' );

$purchase_log = new WPSC_Purchase_Log( $current_purchase_log_id );
$purchase_log = wpsc_get_order( $current_purchase_log_id );
$module = $purchase_log->get( 'shipping_method' );
$option = $purchase_log->get( 'shipping_option' );

Expand All @@ -190,4 +190,4 @@ private function get_active_shipping() {
private function encode_shipping_option_id( $module, $option ) {
return md5( $module . ':' . $option );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function transaction_results( $sessionid, $display_to_screen = true, $transactio
// pre-3.8.9 variable
$echo_to_screen = $display_to_screen;

$purchase_log_object = new WPSC_Purchase_Log( $sessionid, 'sessionid' );
$purchase_log_object = wpsc_get_order( $sessionid, 'sessionid' );

// compatibility with pre-3.8.9 templates where they use a global
// $purchase_log object which is simply just a database row
Expand Down
8 changes: 4 additions & 4 deletions wpsc-components/theme-engine-v2/mvc/controllers/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private function submit_review_order() {

// Update the Purchase Log
$purchase_log_id = wpsc_get_customer_meta( 'current_purchase_log_id' );
$purchase_log = new WPSC_Purchase_Log( $purchase_log_id );
$purchase_log = wpsc_get_order( $purchase_log_id );
$purchase_log->set( 'base_shipping', $wpsc_cart->calculate_base_shipping() );
$purchase_log->set( 'totalprice', $wpsc_cart->calculate_total_price() );
$purchase_log->save();
Expand Down Expand Up @@ -241,14 +241,14 @@ public function get_purchase_log() {
$create = true;

if ( $purchase_log_id ) {
$purchase_log = new WPSC_Purchase_Log( $purchase_log_id );
$purchase_log = wpsc_get_order( $purchase_log_id );
$create = ! $purchase_log->exists();
}

if ( $create ) {
wpsc_delete_customer_meta( 'current_purchase_log_id' );

$purchase_log = new WPSC_Purchase_Log();
$purchase_log = wpsc_get_order();

$purchase_log->set( array(
'user_ID' => get_current_user_id(),
Expand Down Expand Up @@ -452,7 +452,7 @@ private function submit_payment_method() {
}

$purchase_log_id = wpsc_get_customer_meta( 'current_purchase_log_id' );
$purchase_log = new WPSC_Purchase_Log( $purchase_log_id );
$purchase_log = wpsc_get_order( $purchase_log_id );
$submitted_gateway = $_POST['wpsc_payment_method'];

$purchase_log->set( array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function order( $id ) {
$this->view = 'customer-account-order';
$form_data_obj = new WPSC_Checkout_Form_Data( $id );
$this->form = WPSC_Checkout_Form::get();
$this->log = new WPSC_Purchase_Log( $id );
$this->log = wpsc_get_order( $id );
$this->title = sprintf(
__( 'View Order #%d', 'wp-e-commerce' ),
$id
Expand Down
2 changes: 1 addition & 1 deletion wpsc-includes/checkout-form-data.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public function set( $key, $value = '' ) {
*/
public function save() {

$log = new WPSC_Purchase_Log( $this->log_id );
$log = wpsc_get_order( $this->log_id );
$form = WPSC_Checkout_Form::get();
$fields = $form->get_fields();

Expand Down
2 changes: 1 addition & 1 deletion wpsc-includes/google-analytics.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function remove_currency_and_html( $args ) {
}
public function add_pushes( $session_id ) {

$purchase = new WPSC_Purchase_Log( $session_id, 'sessionid' );
$purchase = wpsc_get_order( $session_id, 'sessionid' );
$purchase_id = $purchase->get( 'id' );

$data = new WPSC_Checkout_Form_Data( $purchase_id );
Expand Down
4 changes: 2 additions & 2 deletions wpsc-includes/merchant.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function return_to_checkout() {
* go to transaction results, if this changes and you extend this, your merchant module may go to the wrong place
*/
function go_to_transaction_results( $session_id ) {
$purchase_log = new WPSC_Purchase_Log( $this->purchase_id );
$purchase_log = wpsc_get_order( $this->purchase_id );

//Now to do actions once the payment has been attempted
switch ( $purchase_log->get( 'processed' ) ) {
Expand Down Expand Up @@ -334,7 +334,7 @@ function set_transaction_details( $transaction_id, $status = 1 ) {
*/
function set_authcode( $authcode, $append = false ){

$log = new WPSC_Purchase_Log( $this->purchase_id );
$log = wpsc_get_order( $this->purchase_id );
$current_authcode = $log->get( 'authcode' );

if ( $append && ! empty( $current_authcode ) ) {
Expand Down
96 changes: 91 additions & 5 deletions wpsc-includes/purchase-log.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
define( 'WPSC_PURCHASE_LOG_STATS_CACHE_EXPIRE', DAY_IN_SECONDS * 2 );
}

class WPSC_Purchase_Log extends WPSC_Query_Base {
class WPSC_Purchase_Log extends WPSC_Query_Registry {
const INCOMPLETE_SALE = 1;
const ORDER_RECEIVED = 2;
const ACCEPTED_PAYMENT = 3;
Expand Down Expand Up @@ -139,6 +139,8 @@ class WPSC_Purchase_Log extends WPSC_Query_Base {
protected $shipping_country = null;
protected $payment_method = null;
protected $shipping_method = null;
protected static $flag = false;
protected static $alt_ids = false;

/**
* Get the SQL query format for a column
Expand Down Expand Up @@ -426,7 +428,7 @@ public function update_caches() {
*/
public static function delete_cache( $value, $col = 'id' ) {
// this will pull from the old cache, so no worries there
$log = new WPSC_Purchase_Log( $value, $col );
$log = self::get_instance( $value, $col );
$log->delete_caches( $value, $col );
}

Expand Down Expand Up @@ -529,13 +531,15 @@ public function delete( $log_id = false ) {
* create a new empty object. Otherwise, this will get the purchase log from the
* DB either by using purchase log id or sessionid (specified by the 2nd argument).
*
* It is preferred to use WPSC_Purchase_Log::get_instance() or wpsc_get_order().
*
* Eg:
*
* // get purchase log with ID number 23
* $log = new WPSC_Purchase_Log( 23 );
* $log = WPSC_Purchase_Log::get_instance( 23 );
*
* // get purchase log with sessionid "asdf"
* $log = new WPSC_Purchase_Log( 'asdf', 'sessionid' )
* $log = WPSC_Purchase_Log::get_instance( 'asdf', 'sessionid' )
*
* @access public
* @since 3.8.9
Expand All @@ -544,6 +548,12 @@ public function delete( $log_id = false ) {
* @param string $col Optional. Defaults to 'id'.
*/
public function __construct( $value = false, $col = 'id' ) {
if ( ! self::$flag ) {
_wpsc_doing_it_wrong( 'wpsc_purchlog_notes_class_error', __( 'Please use `WPSC_Purchase_Log::get_instance( $log_id )` instead of `new WPSC_Purchase_Log( $log_id ).', 'wp-e-commerce' ), '3.12.0' );
}

parent::add_instance( $this );

if ( false === $value ) {
return;
}
Expand Down Expand Up @@ -586,6 +596,72 @@ public function __construct( $value = false, $col = 'id' ) {
}
}

/**
* Retrieve a WPSC_Purchase_Log instance.
* Get the log either by using purchase log id or sessionid (specified by the 2nd argument).
*
* Eg:
*
* // get purchase log with ID number 23
* $log = WPSC_Purchase_Log::get_instance( 23 );
*
* // get purchase log with sessionid "asdf"
* $log = WPSC_Purchase_Log::get_instance( 'asdf', 'sessionid' )
*
* @since 3.12.0
*
* @param string $value Optional. Defaults to false.
* @param string $col Optional. Defaults to 'id'.
*
* @return WPSC_Purchase_Log object instance.
*/
public static function get_instance( $value = false, $col = 'id' ) {
$instance = false;

if ( $value && isset( self::$alt_ids[ $col ][ $value ] ) ) {
$instance = parent::_get_instance( __CLASS__, self::$alt_ids[ $col ][ $value ] );
}

if ( ! $instance ) {
self::$flag = true;
$instance = new self( $value, $col );
self::$flag = false;
}

$id = $instance->get( 'id' );
$instance_id = $instance->instance_id();

// If fetched object matches one we already have (based on the ID), then use original instance.
if ( $id && 'id' !== $col && isset( self::$alt_ids['id'][ $id ] ) ) {
$existing = parent::_get_instance( __CLASS__, self::$alt_ids['id'][ $id ] );
if ( $existing ) {
$instance = $existing;
$instance_id = $instance->instance_id();
}
}

if ( $value && 'id' !== $col ) {
self::$alt_ids[ $col ][ $value ] = $instance_id;
}

if ( $id ) {
self::$alt_ids['id'][ $id ] = $instance_id;
}

return $instance;
}

/**
* Retrieves the unique identifier for a WPSC_Query_Base instance.
*
* @since 3.12.0
*
* @return mixed
*/
public function instance_id() {
return spl_object_hash( $this );
}

private function set_total_shipping() {

$base_shipping = $this->get( 'base_shipping' );
Expand Down Expand Up @@ -1044,6 +1120,16 @@ public function save() {
$this->save_meta();
}

$instance_id = $this->instance_id();

if ( $sessionid = $this->get( 'sessionid' ) ) {
self::$alt_ids['sessionid'][ $sessionid ] = $instance_id;
}

if ( $id = $this->get( 'id' ) ) {
self::$alt_ids['id'][ $id ] = $instance_id;
}

do_action( 'wpsc_purchase_log_save', $this );

return $result;
Expand Down Expand Up @@ -1138,7 +1224,7 @@ public static function get_log_by_meta( $key = '', $value = '' ) {
$id = $wpdb->get_var( $sql );

if ( $id ) {
return new WPSC_Purchase_Log( $id );
return self::get_instance( $id );
} else {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion wpsc-includes/purchase-log.helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
function wpsc_get_order( $order_id, $by = 'id' ) {
$order = wpsc_is_order( $order_id );
return $order ? $order : new WPSC_Purchase_Log( $order_id, $by );
return $order ? $order : WPSC_Purchase_Log::get_instance( $order_id, $by );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion wpsc-includes/purchaselogs-items.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct( $id, $purchase_log = null ) {

$this->log = $purchase_log instanceof WPSC_Purchase_Log
? $purchase_log
: new WPSC_Purchase_Log( $this->purchlogid );
: wpsc_get_order( $this->purchlogid );

$this->get_purchlog_details();
}
Expand Down
2 changes: 1 addition & 1 deletion wpsc-includes/purchaselogs.functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ function wpsc_purchlog_edit_status( $purchlog_id = '', $purchlog_status = '' ) {
$purchlog_status = absint( $_POST['new_status'] );
}

$purchase_log = new WPSC_Purchase_Log( $purchlog_id );
$purchase_log = wpsc_get_order( $purchlog_id );

// In the future when everyone is using the 2.0 merchant api,
// we should use the merchant class to update the staus,
Expand Down
Loading