Version Description
- New: Individual item details are sent to Paypal Express Checkout
- Change: Automatically reload database update page when PHP maximum execution time is detected
- Change: Add progress bar and estimated time remaining for database update tasks
- Change: Themes can now use taxonomy-wpsc_product_category-{$term}.php and taxonomy-wpsc_product_category.php templates, which take precedence over page.php when viewing a product category
- Change: Paypal Express Checkout API is updated to ver 71.0
- Fix: Tax is calculated incorrectly when a coupon is used
- Fix: Update a large database of products and variations take ages
- Fix: Reloading database update page makes wpec scan the records from the beginning instead of continuing where it left off
- Fix: Reactivating the plugin causes Fatal Error (PHP Timeout) if there are a lot of attached images (not just post products, but all image attachments)
- Fix: Purchase logs' statuses are not properly updated when upgrading from 3.7.x
- Fix: Billing state is not sent to checkout
- Fix: Country name is truncated when sending to payment gateway
- Fix: Billing state code is not properly converted before sending to payment gateway
- Fix: Wrong USA country code is sent to Paypal Standard Payment
- Fix: Wrong sandbox gateway URL for Paypal Pro
- Fix: SSLVERIFY error when connecting to Paypal Pro Gateway
- Fix: Template hierarchy error with child themes
- Fix: Total amount is not visible when checking out with Paypal Express Checkout
- Fix: Transaction result page is inaccurate after checking out with Paypal Express Checkout
- Fix: Incompatibility with Thesis theme's loop when viewing product category, or paginated product listing
Download this release
Release Info
Developer | mychelle |
Plugin | WP eCommerce |
Version | 3.8.3 |
Comparing to | |
See all releases |
Code changes from version 3.8.2 to 3.8.3
- readme.txt +23 -1
- wp-shopping-cart.php +1 -1
- wpsc-admin/admin.php +1 -1
- wpsc-admin/ajax-and-init.php +2 -1
- wpsc-admin/css/admin.css +35 -0
- wpsc-admin/display-sales-logs.php +48 -13
- wpsc-admin/display-update.page.php +25 -17
- wpsc-admin/includes/product-functions.php +1 -1
- wpsc-admin/includes/updating-functions.php +585 -312
- wpsc-core/js/user.js +13 -7
- wpsc-core/wpsc-constants.php +3 -3
- wpsc-core/wpsc-installer.php +10 -7
- wpsc-includes/ajax.functions.php +1 -1
- wpsc-includes/cart.class.php +9 -3
- wpsc-includes/checkout.class.php +32 -51
- wpsc-includes/merchant.class.php +38 -10
- wpsc-includes/purchaselogs.class.php +1 -1
- wpsc-includes/theme.functions.php +30 -17
- wpsc-merchants/paypal-express.merchant.php +76 -44
- wpsc-merchants/paypal-pro.merchant.php +3 -2
- wpsc-merchants/paypal-standard.merchant.php +7 -6
- wpsc-shipping/flatrate.php +5 -3
- wpsc-taxes/controllers/taxes_controller.class.php +15 -1
- wpsc-theme/functions/wpsc-transaction_results_functions.php +21 -14
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://getshopped.org
|
|
4 |
Tags: e-commerce, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.1.1
|
7 |
-
Stable tag: 3.8.
|
8 |
|
9 |
WP e-Commerce is a Web 2.0 application designed with usability, aesthetics, and presentation in mind.
|
10 |
|
@@ -37,6 +37,28 @@ After upgrading from earlier versions look for link "Update Store". This will up
|
|
37 |
|
38 |
|
39 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
= 3.8.2 =
|
41 |
* Add: Currency display for Google RSS feed
|
42 |
* Add: Third-party plugins can now filter 'wpsc-tax_rate' to provide their own tax solution
|
4 |
Tags: e-commerce, wp-e-commerce, shop, cart, paypal, authorize, stock control, ecommerce, shipping, tax
|
5 |
Requires at least: 3.0
|
6 |
Tested up to: 3.1.1
|
7 |
+
Stable tag: 3.8.3
|
8 |
|
9 |
WP e-Commerce is a Web 2.0 application designed with usability, aesthetics, and presentation in mind.
|
10 |
|
37 |
|
38 |
|
39 |
== Changelog ==
|
40 |
+
= 3.8.3 =
|
41 |
+
* New: Individual item details are sent to Paypal Express Checkout
|
42 |
+
* Change: Automatically reload database update page when PHP maximum execution time is detected
|
43 |
+
* Change: Add progress bar and estimated time remaining for database update tasks
|
44 |
+
* Change: Themes can now use taxonomy-wpsc_product_category-{$term}.php and taxonomy-wpsc_product_category.php templates, which take precedence over page.php when viewing a product category
|
45 |
+
* Change: Paypal Express Checkout API is updated to ver 71.0
|
46 |
+
* Fix: Tax is calculated incorrectly when a coupon is used
|
47 |
+
* Fix: Update a large database of products and variations take ages
|
48 |
+
* Fix: Reloading database update page makes wpec scan the records from the beginning instead of continuing where it left off
|
49 |
+
* Fix: Reactivating the plugin causes Fatal Error (PHP Timeout) if there are a lot of attached images (not just post products, but all image attachments)
|
50 |
+
* Fix: Purchase logs' statuses are not properly updated when upgrading from 3.7.x
|
51 |
+
* Fix: Billing state is not sent to checkout
|
52 |
+
* Fix: Country name is truncated when sending to payment gateway
|
53 |
+
* Fix: Billing state code is not properly converted before sending to payment gateway
|
54 |
+
* Fix: Wrong USA country code is sent to Paypal Standard Payment
|
55 |
+
* Fix: Wrong sandbox gateway URL for Paypal Pro
|
56 |
+
* Fix: SSLVERIFY error when connecting to Paypal Pro Gateway
|
57 |
+
* Fix: Template hierarchy error with child themes
|
58 |
+
* Fix: Total amount is not visible when checking out with Paypal Express Checkout
|
59 |
+
* Fix: Transaction result page is inaccurate after checking out with Paypal Express Checkout
|
60 |
+
* Fix: Incompatibility with Thesis theme's loop when viewing product category, or paginated product listing
|
61 |
+
|
62 |
= 3.8.2 =
|
63 |
* Add: Currency display for Google RSS feed
|
64 |
* Add: Third-party plugins can now filter 'wpsc-tax_rate' to provide their own tax solution
|
wp-shopping-cart.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: WP e-Commerce
|
4 |
* Plugin URI: http://getshopped.org/
|
5 |
* Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://getshopped.org" target="_blank">GetShopped.org</a> | <a href="http://getshopped.org/forums/" target="_blank">Support Forum</a> | <a href="http://docs.getshopped.org/" target="_blank">Documentation</a>
|
6 |
-
* Version: 3.8.
|
7 |
* Author: Instinct Entertainment
|
8 |
* Author URI: http://getshopped.org/
|
9 |
**/
|
3 |
* Plugin Name: WP e-Commerce
|
4 |
* Plugin URI: http://getshopped.org/
|
5 |
* Description: A plugin that provides a WordPress Shopping Cart. See also: <a href="http://getshopped.org" target="_blank">GetShopped.org</a> | <a href="http://getshopped.org/forums/" target="_blank">Support Forum</a> | <a href="http://docs.getshopped.org/" target="_blank">Documentation</a>
|
6 |
+
* Version: 3.8.3
|
7 |
* Author: Instinct Entertainment
|
8 |
* Author URI: http://getshopped.org/
|
9 |
**/
|
wpsc-admin/admin.php
CHANGED
@@ -357,7 +357,7 @@ function wpsc_admin_include_css_and_js_refac( $pagehook ) {
|
|
357 |
'l10n_print_after' => 'try{convertEntities(wpsc_adminL10n);}catch(e){};'
|
358 |
) );
|
359 |
}
|
360 |
-
if ( 'dashboard_page_wpsc-upgrades' == $pagehook )
|
361 |
wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' );
|
362 |
wp_deregister_script( 'prototype' );
|
363 |
|
357 |
'l10n_print_after' => 'try{convertEntities(wpsc_adminL10n);}catch(e){};'
|
358 |
) );
|
359 |
}
|
360 |
+
if ( 'dashboard_page_wpsc-upgrades' == $pagehook || 'dashboard_page_wpsc-update' == $pagehook )
|
361 |
wp_enqueue_style( 'wp-e-commerce-admin', WPSC_URL . '/wpsc-admin/css/admin.css', false, $version_identifier, 'all' );
|
362 |
wp_deregister_script( 'prototype' );
|
363 |
|
wpsc-admin/ajax-and-init.php
CHANGED
@@ -1327,6 +1327,7 @@ function wpsc_checkout_settings() {
|
|
1327 |
}
|
1328 |
|
1329 |
if ( isset( $_POST['new_form_name'] ) ) {
|
|
|
1330 |
foreach ( $_POST['new_form_name'] as $form_id => $form_name ) {
|
1331 |
$form_type = $_POST['new_form_type'][$form_id];
|
1332 |
$form_mandatory = 0;
|
@@ -1388,7 +1389,7 @@ function wpsc_checkout_settings() {
|
|
1388 |
if ( isset( $updated ) ) {
|
1389 |
$sendback = add_query_arg( 'updated', $updated, $sendback );
|
1390 |
}
|
1391 |
-
if (
|
1392 |
$sendback = add_query_arg( 'added', $added, $sendback );
|
1393 |
}
|
1394 |
if ( isset( $_SESSION['wpsc_settings_curr_page'] ) ) {
|
1327 |
}
|
1328 |
|
1329 |
if ( isset( $_POST['new_form_name'] ) ) {
|
1330 |
+
$added = 0;
|
1331 |
foreach ( $_POST['new_form_name'] as $form_id => $form_name ) {
|
1332 |
$form_type = $_POST['new_form_type'][$form_id];
|
1333 |
$form_mandatory = 0;
|
1389 |
if ( isset( $updated ) ) {
|
1390 |
$sendback = add_query_arg( 'updated', $updated, $sendback );
|
1391 |
}
|
1392 |
+
if ( ! empty( $added ) ) {
|
1393 |
$sendback = add_query_arg( 'added', $added, $sendback );
|
1394 |
}
|
1395 |
if ( isset( $_SESSION['wpsc_settings_curr_page'] ) ) {
|
wpsc-admin/css/admin.css
CHANGED
@@ -1755,4 +1755,39 @@ float: left;
|
|
1755 |
|
1756 |
.ajax-loading {
|
1757 |
visibility: hidden;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1758 |
}
|
1755 |
|
1756 |
.ajax-loading {
|
1757 |
visibility: hidden;
|
1758 |
+
}
|
1759 |
+
|
1760 |
+
.dashboard_page_wpsc-update .wpsc-progress-bar {
|
1761 |
+
position:relative;
|
1762 |
+
height:20px;
|
1763 |
+
width:300px;
|
1764 |
+
border:1px solid #3a58cf;
|
1765 |
+
margin:-0.75em 0 27px;
|
1766 |
+
}
|
1767 |
+
|
1768 |
+
.dashboard_page_wpsc-update .wpsc-progress-bar * {
|
1769 |
+
position:absolute;
|
1770 |
+
left:0;
|
1771 |
+
top:0;
|
1772 |
+
background:#f9f9f9;
|
1773 |
+
font-size:12px;
|
1774 |
+
}
|
1775 |
+
|
1776 |
+
.dashboard_page_wpsc-update .wpsc-progress-bar .block {
|
1777 |
+
background-color:#527dff;
|
1778 |
+
z-index:-1;
|
1779 |
+
height:20px;
|
1780 |
+
}
|
1781 |
+
|
1782 |
+
.dashboard_page_wpsc-update .wpsc-progress-bar span {
|
1783 |
+
display:block;
|
1784 |
+
left:310px;
|
1785 |
+
line-height:20px;
|
1786 |
+
width:200px;
|
1787 |
+
}
|
1788 |
+
|
1789 |
+
.dashboard_page_wpsc-update .wpsc-progress-bar .eta {
|
1790 |
+
top:22px;
|
1791 |
+
line-height:15px;
|
1792 |
+
width:100%;
|
1793 |
}
|
wpsc-admin/display-sales-logs.php
CHANGED
@@ -13,19 +13,47 @@ if(!isset($purchlogs)){
|
|
13 |
}
|
14 |
|
15 |
function wpsc_display_sales_logs() {
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
30 |
|
31 |
function wpsc_display_sales_log_index() {
|
@@ -85,6 +113,13 @@ function wpsc_display_sales_logs() {
|
|
85 |
if(get_option('wpsc_purchaselogs_fixed')== false || (wpsc_check_uniquenames()) ){ ?>
|
86 |
<div class='error' style='padding:8px;line-spacing:8px;'><span ><?php printf( __('When upgrading the WP e-Commerce Plugin from 3.6.* to 3.7 it is required that you associate your checkout form fields with the new Purchase Logs system. To do so please <a href="%s">Click Here</a>', 'wpsc'), $fixpage); ?></span></div>
|
87 |
<?php }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
///// end of update message section //////?>
|
89 |
<div id='dashboard-widgets' style='min-width: 825px;'>
|
90 |
<?php /* end of sidebar start of main column */ ?>
|
13 |
}
|
14 |
|
15 |
function wpsc_display_sales_logs() {
|
16 |
+
$subpage = empty( $_GET['subpage'] ) ? '' : $_GET['subpage'];
|
17 |
+
|
18 |
+
switch( $subpage ) {
|
19 |
+
case 'upgrade-purchase-logs':
|
20 |
+
wpsc_upgrade_purchase_logs();
|
21 |
+
break;
|
22 |
+
|
23 |
+
case 'update-purchase-logs-3.8':
|
24 |
+
wpsc_update_purchase_logs_3dot8();
|
25 |
+
break;
|
26 |
+
|
27 |
+
default:
|
28 |
+
wpsc_display_sales_log_index();
|
29 |
+
break;
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
function wpsc_update_purchase_logs_3dot8() {
|
34 |
+
if ( _wpsc_purchlogs_need_update() )
|
35 |
+
wpsc_update_purchase_logs();
|
36 |
+
|
37 |
+
?>
|
38 |
+
<div class="wrap">
|
39 |
+
<h2><?php echo esc_html( __('Sales', 'wpsc') ); ?> </h2>
|
40 |
+
<p><?php printf( __( 'Your purchase logs have been updated! <a href="%s">Click here</a> to return.'), remove_query_arg( 'subpage' ) ); ?></p>
|
41 |
+
</div>
|
42 |
+
<?php
|
43 |
+
}
|
44 |
+
|
45 |
+
function _wpsc_purchlogs_need_update() {
|
46 |
+
global $wpdb;
|
47 |
+
|
48 |
+
if ( get_option( '_wpsc_purchlogs_3.8_updated' ) )
|
49 |
+
return false;
|
50 |
+
|
51 |
+
$c = $wpdb->get_var( "SELECT COUNT(*) FROM " . WPSC_TABLE_PURCHASE_LOGS . " WHERE plugin_version IN ('3.6', '3.7')" );
|
52 |
+
if ( $c > 0 )
|
53 |
+
return true;
|
54 |
+
|
55 |
+
update_option( '_wpsc_purchlogs_3.8_updated', true );
|
56 |
+
return false;
|
57 |
}
|
58 |
|
59 |
function wpsc_display_sales_log_index() {
|
113 |
if(get_option('wpsc_purchaselogs_fixed')== false || (wpsc_check_uniquenames()) ){ ?>
|
114 |
<div class='error' style='padding:8px;line-spacing:8px;'><span ><?php printf( __('When upgrading the WP e-Commerce Plugin from 3.6.* to 3.7 it is required that you associate your checkout form fields with the new Purchase Logs system. To do so please <a href="%s">Click Here</a>', 'wpsc'), $fixpage); ?></span></div>
|
115 |
<?php }
|
116 |
+
|
117 |
+
if ( _wpsc_purchlogs_need_update() ) {
|
118 |
+
?>
|
119 |
+
<div class='error' style='padding:8px;line-spacing:8px;'><span ><?php printf( __('It has been detected that some of your purchase logs were not updated properly when you upgrade to WP e-Commerce %s. Please <a href="%s">click here</a> to fix this problem.', 'wpsc'), WPSC_VERSION, add_query_arg( 'subpage', 'update-purchase-logs-3.8' ) ); ?></span></div>
|
120 |
+
<?php
|
121 |
+
}
|
122 |
+
|
123 |
///// end of update message section //////?>
|
124 |
<div id='dashboard-widgets' style='min-width: 825px;'>
|
125 |
<?php /* end of sidebar start of main column */ ?>
|
wpsc-admin/display-update.page.php
CHANGED
@@ -58,27 +58,33 @@ function wpsc_display_php_version_notice() {
|
|
58 |
<?php
|
59 |
}
|
60 |
|
61 |
-
function wpsc_display_update_page() {
|
62 |
-
|
|
|
|
|
|
|
63 |
<div class="wrap">
|
64 |
<h2><?php echo esc_html( __('Update WP e-Commerce', 'wpsc') ); ?> </h2>
|
65 |
<br />
|
66 |
-
|
67 |
<?php
|
68 |
-
if ( isset( $
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
|
|
|
|
|
|
|
|
82 |
echo '<br /><br /><strong>' . __('WP e-Commerce updated successfully!', 'wpsc') . '</strong><br />';
|
83 |
if( '' != get_option('permalink_structure')){ ?>
|
84 |
<em><?php printf(__('Note: It looks like you have custom permalinks, you will need to refresh your permalinks <a href="%s">here</a>','wpsc' ) , admin_url('options-permalink.php') ); ?></em>
|
@@ -87,6 +93,8 @@ function wpsc_display_update_page() { ?>
|
|
87 |
update_option('wpsc_version', 3.8);
|
88 |
update_option('wpsc_hide_update', true);
|
89 |
update_option( 'wpsc_needs_update', false );
|
|
|
|
|
90 |
else:
|
91 |
|
92 |
|
58 |
<?php
|
59 |
}
|
60 |
|
61 |
+
function wpsc_display_update_page() {
|
62 |
+
global $wpdb;
|
63 |
+
|
64 |
+
?>
|
65 |
+
|
66 |
<div class="wrap">
|
67 |
<h2><?php echo esc_html( __('Update WP e-Commerce', 'wpsc') ); ?> </h2>
|
68 |
<br />
|
|
|
69 |
<?php
|
70 |
+
if ( isset( $_REQUEST['run_updates'] ) ) :
|
71 |
+
ob_implicit_flush( true );
|
72 |
+
$wpsc_update = WPSC_Update::get_instance();
|
73 |
+
$update_stages = array(
|
74 |
+
'convert_category_groups' => __( 'Updating Categories...' , 'wpsc' ),
|
75 |
+
'convert_variation_sets' => __( 'Updating Variations...' , 'wpsc' ),
|
76 |
+
'convert_products_to_posts' => __( 'Updating Products ...' , 'wpsc' ),
|
77 |
+
'convert_variation_combinations' => __( 'Updating Child Products...', 'wpsc' ),
|
78 |
+
'update_files' => __( 'Updating Product Files...' , 'wpsc' ),
|
79 |
+
'update_purchase_logs' => __( 'Updating Purchase Logs... ', 'wpsc' ),
|
80 |
+
'create_or_update_tables' => __( 'Updating Database...' , 'wpsc' ),
|
81 |
+
'update_database' => '',
|
82 |
+
);
|
83 |
+
|
84 |
+
foreach ( $update_stages as $function => $message ) {
|
85 |
+
$wpsc_update->run( $function, $message );
|
86 |
+
}
|
87 |
+
|
88 |
echo '<br /><br /><strong>' . __('WP e-Commerce updated successfully!', 'wpsc') . '</strong><br />';
|
89 |
if( '' != get_option('permalink_structure')){ ?>
|
90 |
<em><?php printf(__('Note: It looks like you have custom permalinks, you will need to refresh your permalinks <a href="%s">here</a>','wpsc' ) , admin_url('options-permalink.php') ); ?></em>
|
93 |
update_option('wpsc_version', 3.8);
|
94 |
update_option('wpsc_hide_update', true);
|
95 |
update_option( 'wpsc_needs_update', false );
|
96 |
+
$wpsc_update->clean_up();
|
97 |
+
ob_implicit_flush( false );
|
98 |
else:
|
99 |
|
100 |
|
wpsc-admin/includes/product-functions.php
CHANGED
@@ -210,7 +210,7 @@ function wpsc_pre_update( $data , $postarr ) {
|
|
210 |
$data["post_parent"] = $postarr["parent_post"];
|
211 |
|
212 |
// Sanitize status for variations (see #324)
|
213 |
-
if ($data['post_parent'] && $data['post_parent'] != $data['ID']) {
|
214 |
$data['post_status'] = 'inherit';
|
215 |
}
|
216 |
|
210 |
$data["post_parent"] = $postarr["parent_post"];
|
211 |
|
212 |
// Sanitize status for variations (see #324)
|
213 |
+
if ( $data['post_parent'] && ( ! isset( $data['ID'] ) || $data['post_parent'] != $data['ID'] ) ) {
|
214 |
$data['post_status'] = 'inherit';
|
215 |
}
|
216 |
|
wpsc-admin/includes/updating-functions.php
CHANGED
@@ -6,6 +6,199 @@
|
|
6 |
* @since 3.8
|
7 |
*/
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
/**
|
10 |
* wpsc_convert_category_groups function.
|
11 |
*
|
@@ -14,7 +207,8 @@
|
|
14 |
*/
|
15 |
function wpsc_convert_category_groups() {
|
16 |
global $wpdb, $user_ID;
|
17 |
-
|
|
|
18 |
//if they're updating from 3.6, and they've got categories with no group, let's fix that problem, eh?
|
19 |
$categorisation_groups = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_CATEGORISATION_GROUPS."` WHERE `active` IN ('1')");
|
20 |
if(count($categorisation_groups) == 0) {
|
@@ -24,8 +218,10 @@ function wpsc_convert_category_groups() {
|
|
24 |
$wpdb->query($sql);
|
25 |
$categorisation_groups = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_CATEGORISATION_GROUPS."` WHERE `active` IN ('1')");
|
26 |
}
|
27 |
-
|
28 |
foreach((array)$categorisation_groups as $cat_group) {
|
|
|
|
|
29 |
$category_id = wpsc_get_meta($cat_group->id, 'category_group_id', 'wpsc_category_group');
|
30 |
|
31 |
if(!is_numeric($category_id) || ( $category_id < 1)) {
|
@@ -43,11 +239,11 @@ function wpsc_convert_category_groups() {
|
|
43 |
wpsc_update_categorymeta($category_id, 'uses_billing_address', 0);
|
44 |
}
|
45 |
|
46 |
-
if(!is_wp_error($new_category))
|
47 |
-
|
48 |
}
|
49 |
-
delete_option("wpsc_product_category_children");
|
50 |
-
_get_term_hierarchy('wpsc_product_category');
|
51 |
}
|
52 |
|
53 |
/**
|
@@ -65,10 +261,12 @@ function wpsc_convert_categories($new_parent_category, $group_id, $old_parent_ca
|
|
65 |
} else {
|
66 |
$categorisation = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active` IN ('1') AND `group_id` IN ('{$group_id}') AND `category_parent` IN (0)");
|
67 |
}
|
|
|
68 |
|
69 |
if($categorisation > 0) {
|
70 |
|
71 |
foreach((array)$categorisation as $category) {
|
|
|
72 |
$category_id = wpsc_get_meta($category->id, 'category_id', 'wpsc_old_category');
|
73 |
|
74 |
if(!is_numeric($category_id) || ( $category_id < 1)) {
|
@@ -108,16 +306,17 @@ function wpsc_convert_categories($new_parent_category, $group_id, $old_parent_ca
|
|
108 |
}
|
109 |
}
|
110 |
|
111 |
-
function wpsc_convert_variation_sets() {
|
112 |
global $wpdb, $user_ID;
|
113 |
$variation_sets = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_VARIATIONS."`");
|
114 |
-
|
|
|
115 |
foreach((array)$variation_sets as $variation_set) {
|
|
|
116 |
$variation_set_id = wpsc_get_meta($variation_set->id, 'variation_set_id', 'wpsc_variation_set');
|
117 |
-
|
118 |
if(!is_numeric($variation_set_id) || ( $variation_set_id < 1)) {
|
119 |
$new_variation_set = wp_insert_term( $variation_set->name, 'wpsc-variation',array('parent' => 0));
|
120 |
-
|
121 |
if(!is_wp_error($new_variation_set))
|
122 |
$variation_set_id = $new_variation_set['term_id'];
|
123 |
}
|
@@ -132,7 +331,7 @@ function wpsc_convert_variation_sets() {
|
|
132 |
|
133 |
if(!is_numeric($variation_id) || ( $variation_id < 1)) {
|
134 |
$new_variation = wp_insert_term( $variation->name, 'wpsc-variation',array('parent' => $variation_set_id));
|
135 |
-
|
136 |
if(!is_wp_error($new_variation))
|
137 |
$variation_id = $new_variation['term_id'];
|
138 |
}
|
@@ -143,7 +342,6 @@ function wpsc_convert_variation_sets() {
|
|
143 |
}
|
144 |
}
|
145 |
}
|
146 |
-
|
147 |
}
|
148 |
|
149 |
/**
|
@@ -155,163 +353,207 @@ function wpsc_convert_variation_sets() {
|
|
155 |
function wpsc_convert_products_to_posts() {
|
156 |
global $wpdb, $user_ID;
|
157 |
// Select all products
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
$
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
$product_post_values = array(
|
181 |
-
'post_author' => $user_ID,
|
182 |
-
'post_date' => $post_date,
|
183 |
-
'post_content' => $product['description'],
|
184 |
-
'post_excerpt' => $product['additional_description'],
|
185 |
-
'post_title' => $product['name'],
|
186 |
-
'post_status' => $post_status,
|
187 |
-
'post_type' => "wpsc-product",
|
188 |
-
'post_name' => sanitize_title($product['name']),
|
189 |
-
'menu_order' => $product['order']
|
190 |
-
);
|
191 |
-
$post_id = wp_insert_post($product_post_values);
|
192 |
-
}
|
193 |
-
|
194 |
-
$product_meta = $wpdb->get_results("
|
195 |
-
SELECT IF( ( `custom` != 1 ),
|
196 |
-
CONCAT( '_wpsc_', `meta_key` ) ,
|
197 |
-
`meta_key`
|
198 |
-
) AS `meta_key`,
|
199 |
-
`meta_value`
|
200 |
-
FROM `".WPSC_TABLE_PRODUCTMETA."`
|
201 |
-
WHERE `product_id` = " . $product['id'] . "
|
202 |
-
AND `meta_value` != ''", ARRAY_A);
|
203 |
-
|
204 |
-
$post_data = array();
|
205 |
-
|
206 |
-
foreach($product_meta as $k => $pm) :
|
207 |
-
if($pm['meta_value'] == 'om')
|
208 |
-
$pm['meta_value'] = 1;
|
209 |
-
$pm['meta_value'] = maybe_unserialize($pm['meta_value']);
|
210 |
-
if(strpos($pm['meta_key'], '_wpsc_') === 0)
|
211 |
-
$post_data['_wpsc_product_metadata'][$pm['meta_key']] = $pm['meta_value'];
|
212 |
-
else
|
213 |
-
update_post_meta($post_id, $pm['meta_key'], $pm['meta_value']);
|
214 |
-
endforeach;
|
215 |
-
|
216 |
-
|
217 |
-
$post_data['_wpsc_original_id'] = (int)$product['id'];
|
218 |
-
$post_data['_wpsc_price'] = (float)$product['price'];
|
219 |
-
$post_data['_wpsc_special_price'] = $post_data['_wpsc_price'] - (float)$product['special_price']; // special price get stored in a weird way in 3.7.x
|
220 |
-
$post_data['_wpsc_stock'] = (float)$product['quantity'];
|
221 |
-
$post_data['_wpsc_is_donation'] = $product['donation'];
|
222 |
-
$post_data['_wpsc_sku'] = $sku;
|
223 |
-
if((bool)$product['quantity_limited'] != true) {
|
224 |
-
$post_data['_wpsc_stock'] = false;
|
225 |
-
}
|
226 |
-
unset($post_data['_wpsc_limited_stock']);
|
227 |
-
|
228 |
-
$post_data['_wpsc_product_metadata']['is_stock_limited'] = (int)(bool)$product['quantity_limited'];
|
229 |
-
|
230 |
-
// Product Weight
|
231 |
-
$post_data['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($product['weight'], $product['weight_unit'], "pound", true);
|
232 |
-
$post_data['_wpsc_product_metadata']['weight_unit'] = $product['weight_unit'];
|
233 |
-
$post_data['_wpsc_product_metadata']['display_weight_as'] = $product['weight_unit'];
|
234 |
-
|
235 |
-
$post_data['_wpsc_product_metadata']['has_no_shipping'] = (int)(bool)$product['no_shipping'];
|
236 |
-
$post_data['_wpsc_product_metadata']['shipping'] = array('local' => $product['pnp'], 'international' => $product['international_pnp']);
|
237 |
|
|
|
|
|
238 |
|
239 |
-
|
240 |
-
|
241 |
-
if(isset($post_data['meta'])) {
|
242 |
-
$post_data['_wpsc_product_metadata']['unpublish_when_none_left'] = (int)(bool)$post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'];
|
243 |
-
}
|
244 |
-
$post_data['_wpsc_product_metadata']['no_shipping'] = (int)(bool)$product['no_shipping'];
|
245 |
-
|
246 |
-
foreach($post_data as $meta_key => $meta_value) {
|
247 |
-
// prefix all meta keys with _wpsc_
|
248 |
-
update_post_meta($post_id, $meta_key, $meta_value);
|
249 |
-
}
|
250 |
|
251 |
-
|
252 |
-
$wp_upload_dir_data = wp_upload_dir();
|
253 |
-
$wp_upload_basedir = $wp_upload_dir_data['basedir'];
|
254 |
-
|
255 |
-
$category_ids = array();
|
256 |
-
$category_data = $wpdb->get_col("SELECT `category_id` FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` WHERE `product_id` IN ('{$product['id']}')");
|
257 |
-
foreach($category_data as $old_category_id) {
|
258 |
-
$category_ids[] = wpsc_get_meta($old_category_id, 'category_id', 'wpsc_old_category');
|
259 |
-
|
260 |
-
}
|
261 |
-
wp_set_product_categories($post_id, $category_ids);
|
262 |
-
|
263 |
-
$product_data = get_post($post_id);
|
264 |
-
$image_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `product_id` IN ('{$product['id']}') ORDER BY `image_order` ASC", ARRAY_A);
|
265 |
-
foreach((array)$image_data as $image_row) {
|
266 |
-
// Get the image path info
|
267 |
-
$image_pathinfo = pathinfo($image_row['image']);
|
268 |
-
|
269 |
-
// use the path info to clip off the file extension
|
270 |
-
$image_name = basename($image_pathinfo['basename'], ".{$image_pathinfo['extension']}");
|
271 |
|
272 |
-
//
|
273 |
-
$
|
274 |
-
|
275 |
-
|
276 |
-
$
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
|
|
292 |
'post_author' => $user_ID,
|
293 |
-
'
|
294 |
-
'
|
295 |
-
'
|
296 |
-
'post_title' => $
|
297 |
-
'post_status' =>
|
298 |
-
'post_type' => "
|
299 |
-
'post_name' =>
|
300 |
-
|
301 |
-
|
302 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
303 |
);
|
304 |
-
$
|
305 |
}
|
306 |
-
|
307 |
-
update_attached_file( $attachment_id, $new_path );
|
308 |
-
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $new_path ) );
|
309 |
-
}
|
310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
}
|
312 |
-
|
313 |
//Just throwing the payment gateway update in here because it doesn't really warrant it's own function :)
|
314 |
-
|
315 |
$custom_gateways = get_option('custom_gateway_options');
|
316 |
array_walk($custom_gateways, "wpec_update_gateway");
|
317 |
update_option('custom_gateway_options', $custom_gateways);
|
@@ -330,162 +572,192 @@ function wpec_update_gateway(&$value,$key) {
|
|
330 |
}
|
331 |
function wpsc_convert_variation_combinations() {
|
332 |
global $wpdb, $user_ID, $current_version_number;
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
|
|
|
|
338 |
|
339 |
-
$
|
340 |
-
|
341 |
-
'post_status' => 'all',
|
342 |
-
'numberposts' => -1
|
343 |
-
) );
|
344 |
-
|
345 |
-
foreach((array)$posts as $post) {
|
346 |
|
347 |
-
|
348 |
-
//
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
'
|
357 |
-
|
358 |
-
);
|
359 |
-
|
360 |
-
// select the original product ID
|
361 |
-
$original_id = get_post_meta($post->ID, '_wpsc_original_id', true);
|
362 |
-
$parent_stock = get_post_meta($post->ID, '_wpsc_stock', true);
|
363 |
-
|
364 |
-
// select the variation set associations
|
365 |
-
$variation_set_associations = $wpdb->get_col("SELECT `variation_id` FROM ".WPSC_TABLE_VARIATION_ASSOC." WHERE `associated_id` = '{$original_id}'");
|
366 |
-
// select the variation associations if the count of variation sets is greater than zero
|
367 |
-
if(($original_id > 0) && (count($variation_set_associations) > 0)) {
|
368 |
-
$variation_associations = $wpdb->get_col("SELECT `value_id` FROM ".WPSC_TABLE_VARIATION_VALUES_ASSOC." WHERE `product_id` = '{$original_id}' AND `variation_id` IN(".implode(", ", $variation_set_associations).") AND `visible` IN ('1')");
|
369 |
-
} else {
|
370 |
-
// otherwise, we have no active variations, skip to the next product
|
371 |
-
continue;
|
372 |
-
}
|
373 |
-
|
374 |
-
foreach($variation_set_associations as $variation_set_id) {
|
375 |
-
$base_product_terms[] = wpsc_get_meta($variation_set_id, 'variation_set_id', 'wpsc_variation_set');
|
376 |
-
}
|
377 |
-
|
378 |
-
foreach($variation_associations as $variation_association_id) {
|
379 |
-
$base_product_terms[] = wpsc_get_meta($variation_association_id, 'variation_id', 'wpsc_variation');
|
380 |
-
}
|
381 |
-
|
382 |
-
// Now that we have the term IDs, we need to retrieve the slugs, as wp_set_object_terms will not use IDs in the way we want
|
383 |
-
// If we pass IDs into wp_set_object_terms, it creates terms using the ID as the name.
|
384 |
-
$parent_product_terms = get_terms('wpsc-variation', array(
|
385 |
-
'hide_empty' => 0,
|
386 |
-
'include' => implode(",", $base_product_terms),
|
387 |
-
'orderby' => 'parent'
|
388 |
-
));
|
389 |
-
$base_product_term_slugs = array();
|
390 |
-
foreach($parent_product_terms as $parent_product_term) {
|
391 |
-
$base_product_term_slugs[] = $parent_product_term->slug;
|
392 |
-
|
393 |
-
}
|
394 |
-
|
395 |
-
wp_set_object_terms($post->ID, $base_product_term_slugs, 'wpsc-variation');
|
396 |
-
|
397 |
-
// select all variation "products"
|
398 |
-
$variation_items = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_VARIATION_PROPERTIES." WHERE `product_id` = '{$original_id}'");
|
399 |
-
|
400 |
-
foreach((array)$variation_items as $variation_item) {
|
401 |
-
// initialize the requisite arrays to empty
|
402 |
-
$variation_ids = array();
|
403 |
-
$term_data = array();
|
404 |
-
// make a temporary copy of the product teplate
|
405 |
-
$product_values = $child_product_template;
|
406 |
|
407 |
-
|
408 |
-
$
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
416 |
|
417 |
-
|
418 |
-
if(count($variation_ids) > 0 && ( count($variation_set_associations) == count($variation_ids) ) ) {
|
419 |
-
$combination_terms = get_terms('wpsc-variation', array(
|
420 |
-
'hide_empty' => 0,
|
421 |
-
'include' => implode(",", $variation_ids),
|
422 |
-
'orderby' => 'parent',
|
423 |
-
));
|
424 |
-
|
425 |
-
foreach($combination_terms as $term) {
|
426 |
-
$term_data['ids'][] = $term->term_id;
|
427 |
-
$term_data['slugs'][] = $term->slug;
|
428 |
-
$term_data['names'][] = $term->name;
|
429 |
-
}
|
430 |
-
|
431 |
-
$product_values['post_title'] .= " (".implode(", ", $term_data['names']).")";
|
432 |
-
$product_values['post_name'] = sanitize_title($product_values['post_title']);
|
433 |
-
|
434 |
-
$selected_post = get_posts(array(
|
435 |
-
'name' => $product_values['post_name'],
|
436 |
-
'post_parent' => $post->ID,
|
437 |
-
'post_type' => "wpsc-product",
|
438 |
-
'post_status' => 'all',
|
439 |
-
'suppress_filters' => true
|
440 |
-
));
|
441 |
-
|
442 |
-
$selected_post = array_shift($selected_post);
|
443 |
-
|
444 |
-
$child_product_id = wpsc_get_child_object_in_terms($post->ID, $term_data['ids'], 'wpsc-variation');
|
445 |
-
$post_data = array();
|
446 |
-
$post_data['_wpsc_price'] = (float)$variation_item->price;
|
447 |
-
$post_data['_wpsc_stock'] = (float)$variation_item->stock;
|
448 |
-
if( !is_numeric( $parent_stock ) )
|
449 |
-
$post_data['_wpsc_stock'] = false;
|
450 |
-
|
451 |
-
$post_data['_wpsc_original_variation_id'] = (float)$variation_item->id;
|
452 |
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
}
|
466 |
-
}
|
467 |
-
|
468 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
469 |
$child_product_id = $selected_post->ID;
|
|
|
|
|
|
|
470 |
}
|
471 |
-
}
|
472 |
-
if($child_product_id > 0) {
|
473 |
|
474 |
-
|
475 |
-
|
476 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
477 |
}
|
478 |
-
|
479 |
-
|
480 |
-
wp_set_object_terms($child_product_id, $term_data['slugs'], 'wpsc-variation');
|
481 |
}
|
482 |
-
|
483 |
-
unset($term_data);
|
484 |
-
}
|
485 |
|
|
|
|
|
|
|
|
|
|
|
486 |
}
|
|
|
|
|
|
|
487 |
}
|
488 |
-
delete_option("wpsc-variation_children");
|
489 |
_get_term_hierarchy('wpsc-variation');
|
490 |
delete_option("wpsc_product_category_children");
|
491 |
_get_term_hierarchy('wpsc_product_category');
|
@@ -494,8 +766,10 @@ _get_term_hierarchy('wpsc_product_category');
|
|
494 |
function wpsc_update_files() {
|
495 |
global $wpdb, $user_ID;
|
496 |
$product_files = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_PRODUCT_FILES."");
|
|
|
497 |
|
498 |
foreach($product_files as $product_file) {
|
|
|
499 |
$variation_post_ids = array();
|
500 |
if(!empty($product_file->product_id)){
|
501 |
$product_post_id = (int)$wpdb->get_var($wpdb->prepare( "SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE meta_key = %s AND `meta_value` = %d LIMIT 1", '_wpsc_original_id', $product_file->product_id ));
|
@@ -584,21 +858,20 @@ function wpsc_update_database() {
|
|
584 |
*/
|
585 |
|
586 |
function old_get_product_meta($product_id, $key, $single = false) {
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
|
|
595 |
} else {
|
596 |
-
|
597 |
$meta_values = array_map('maybe_unserialize', $meta_values);
|
598 |
}
|
599 |
}
|
600 |
-
} else {
|
601 |
-
$meta_values = false;
|
602 |
}
|
603 |
if (is_array($meta_values) && (count($meta_values) == 1)) {
|
604 |
return array_pop($meta_values);
|
6 |
* @since 3.8
|
7 |
*/
|
8 |
|
9 |
+
class WPSC_Update
|
10 |
+
{
|
11 |
+
private static $instance;
|
12 |
+
private $timeout;
|
13 |
+
private $script_start;
|
14 |
+
private $stages;
|
15 |
+
|
16 |
+
public static function get_instance() {
|
17 |
+
if ( empty( self::$instance ) )
|
18 |
+
self::$instance = new WPSC_Update();
|
19 |
+
|
20 |
+
return self::$instance;
|
21 |
+
}
|
22 |
+
|
23 |
+
private function __construct() {
|
24 |
+
$this->timeout = ini_get( 'max_execution_time' );
|
25 |
+
$this->script_start = time();
|
26 |
+
|
27 |
+
if ( ! $this->stages = get_transient( 'wpsc_update_progress' ) ) {
|
28 |
+
$this->stages = array();
|
29 |
+
}
|
30 |
+
}
|
31 |
+
|
32 |
+
public function clean_up() {
|
33 |
+
delete_transient( 'wpsc_update_progress' );
|
34 |
+
delete_transient( 'wpsc_update_product_offset' );
|
35 |
+
delete_transient( 'wpsc_update_variation_comb_offset' );
|
36 |
+
delete_transient( 'wpsc_update_current_product' );
|
37 |
+
delete_transient( 'wpsc_update_current_child_products' );
|
38 |
+
}
|
39 |
+
|
40 |
+
public function check_timeout() {
|
41 |
+
$safety = 2; // refresh page within 2 seconds of PHP max execution time limit
|
42 |
+
$wiggle_room = $this->timeout - $safety;
|
43 |
+
|
44 |
+
$terminate = time() - $this->script_start >= $wiggle_room;
|
45 |
+
|
46 |
+
if ( $terminate ) {
|
47 |
+
do_action( 'wpsc_update_timeout_terminate' );
|
48 |
+
$location = remove_query_arg( array( 'start_over', 'eta', 'current_percent' ) );
|
49 |
+
$location = add_query_arg( 'run_updates', 1, $location );
|
50 |
+
$location = apply_filters( 'wpsc_update_terminate_location', $location );
|
51 |
+
?>
|
52 |
+
<script type="text/javascript">
|
53 |
+
location.href = "<?php echo $location; ?>"
|
54 |
+
</script>
|
55 |
+
<?php
|
56 |
+
exit;
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
public function run( $function, $message = '' ) {
|
61 |
+
if ( $message )
|
62 |
+
echo "<p>{$message}</p>";
|
63 |
+
|
64 |
+
if ( empty( $this->stages[$function] ) ) {
|
65 |
+
call_user_func( 'wpsc_' . $function );
|
66 |
+
$this->stages[$function] = true;
|
67 |
+
set_transient( 'wpsc_update_progress', $this->stages, 604800 );
|
68 |
+
}
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
class WPSC_Update_Progress
|
73 |
+
{
|
74 |
+
private $milestone;
|
75 |
+
private $start;
|
76 |
+
private $count;
|
77 |
+
private $current_percent = 0;
|
78 |
+
private $total;
|
79 |
+
private $eta;
|
80 |
+
private $i;
|
81 |
+
|
82 |
+
public function __construct( $total ) {
|
83 |
+
$this->total = $total;
|
84 |
+
$this->milestone = $this->start = time();
|
85 |
+
if ( ! empty( $_REQUEST['current_percent'] ) )
|
86 |
+
$this->current_percent = (int) $_REQUEST['current_percent'];
|
87 |
+
|
88 |
+
add_filter( 'wpsc_update_terminate_location', array( $this, 'filter_terminate_location' ) );
|
89 |
+
|
90 |
+
echo '<div class="wpsc-progress-bar">';
|
91 |
+
if ( ! empty( $_REQUEST['start_over'] ) )
|
92 |
+
return;
|
93 |
+
|
94 |
+
if ( isset( $_REQUEST['current_percent'] ) ) {
|
95 |
+
echo "<div class='block' style='width:{$_REQUEST['current_percent']}%;'> </div>";
|
96 |
+
}
|
97 |
+
|
98 |
+
if ( isset( $_REQUEST['eta'] ) ) {
|
99 |
+
$this->eta = (int) $_REQUEST['eta'];
|
100 |
+
$this->print_eta();
|
101 |
+
}
|
102 |
+
|
103 |
+
if ( isset( $_REQUEST['i'] ) )
|
104 |
+
echo "<span>{$_REQUEST['i']}/{$this->total}</span>";
|
105 |
+
}
|
106 |
+
|
107 |
+
public function filter_terminate_location( $location ) {
|
108 |
+
$location = add_query_arg( array(
|
109 |
+
'current_percent' => $this->current_percent,
|
110 |
+
'i' => $this->i,
|
111 |
+
), $location );
|
112 |
+
if ( $this->eta !== null )
|
113 |
+
$location = add_query_arg( 'eta', $this->eta, $location );
|
114 |
+
else
|
115 |
+
$location = remove_query_arg( 'eta', $location );
|
116 |
+
return $location;
|
117 |
+
}
|
118 |
+
|
119 |
+
private function print_eta() {
|
120 |
+
echo '<div class="eta">';
|
121 |
+
echo __( 'Estimated time left:', 'wpsc' ) . ' ';
|
122 |
+
if ( $this->eta == 0 )
|
123 |
+
echo __( 'Under a minute', 'wpsc' );
|
124 |
+
else
|
125 |
+
printf( _n( '%d minute', '%d minutes', $this->eta ), $this->eta );
|
126 |
+
echo '</div>';
|
127 |
+
}
|
128 |
+
|
129 |
+
public function update( $i ) {
|
130 |
+
if ( empty( $this->count ) )
|
131 |
+
$this->count = $i;
|
132 |
+
|
133 |
+
$this->i = $i;
|
134 |
+
$now = time();
|
135 |
+
$percent = min( floor( $i * 100 / $this->total ), 100 );
|
136 |
+
|
137 |
+
if ( $percent != $this->current_percent ) {
|
138 |
+
echo "<div class='block' style='width:{$percent}%;'> </div>";
|
139 |
+
$this->current_percent = $percent;
|
140 |
+
}
|
141 |
+
|
142 |
+
echo "<span>{$i}/{$this->total}</span>";
|
143 |
+
|
144 |
+
if ( $now - $this->milestone >= 5 ) {
|
145 |
+
$processed = $i - $this->count + 1;
|
146 |
+
$this->eta = floor( ( $this->total - $i ) * ( $now - $this->start ) / ( $processed * 60 ) );
|
147 |
+
$this->print_eta();
|
148 |
+
$this->milestone = $now;
|
149 |
+
}
|
150 |
+
|
151 |
+
if ( $percent == 100 ) {
|
152 |
+
remove_filter( 'wpsc_update_terminate_location', array( $this, 'filter_terminate_location' ) );
|
153 |
+
echo '<div class="eta">Done!</div>';
|
154 |
+
echo '</div>';
|
155 |
+
}
|
156 |
+
}
|
157 |
+
}
|
158 |
+
|
159 |
+
function wpsc_update_step( $i, $total ) {
|
160 |
+
static $current;
|
161 |
+
static $milestone;
|
162 |
+
static $start;
|
163 |
+
static $count;
|
164 |
+
static $current_percent;
|
165 |
+
|
166 |
+
$now = time();
|
167 |
+
|
168 |
+
if ( $current != $total ) {
|
169 |
+
$current = $total;
|
170 |
+
$milestone = $start = $now;
|
171 |
+
$count = $i;
|
172 |
+
}
|
173 |
+
|
174 |
+
$percent = min( round( $i * 100 / $total, 2 ), 100 );
|
175 |
+
|
176 |
+
if ( floor( $percent ) != $current_percent ) {
|
177 |
+
echo "<div class='block' style='width:{$percent}%;'> </div>";
|
178 |
+
$current_percent = floor( $percent );
|
179 |
+
}
|
180 |
+
|
181 |
+
if ( $now - $milestone == 5 ) {
|
182 |
+
$processed = $i - $count + 1;
|
183 |
+
$eta = floor( ( $total - $i ) * ( $now - $start ) / ( $processed * 60 ) );
|
184 |
+
echo '<div class="eta">';
|
185 |
+
echo __( 'Estimated time left:', 'wpsc' ) . ' ';
|
186 |
+
if ( $eta == 0 )
|
187 |
+
echo __( 'Under a minute', 'wpsc' );
|
188 |
+
else
|
189 |
+
printf( _n( '%d minute', '%d minutes', $eta ), $eta );
|
190 |
+
echo '</div>';
|
191 |
+
$milestone = $now;
|
192 |
+
}
|
193 |
+
}
|
194 |
+
|
195 |
+
function wpsc_update_purchase_logs() {
|
196 |
+
global $wpdb;
|
197 |
+
|
198 |
+
// bump all purchase log status
|
199 |
+
$wpdb->query( "UPDATE " . WPSC_TABLE_PURCHASE_LOGS . " SET processed = processed + 1, plugin_version = '" . WPSC_VERSION . "' WHERE plugin_version IN ('3.6', '3.7') " );
|
200 |
+
}
|
201 |
+
|
202 |
/**
|
203 |
* wpsc_convert_category_groups function.
|
204 |
*
|
207 |
*/
|
208 |
function wpsc_convert_category_groups() {
|
209 |
global $wpdb, $user_ID;
|
210 |
+
$wpsc_update = WPSC_Update::get_instance();
|
211 |
+
|
212 |
//if they're updating from 3.6, and they've got categories with no group, let's fix that problem, eh?
|
213 |
$categorisation_groups = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_CATEGORISATION_GROUPS."` WHERE `active` IN ('1')");
|
214 |
if(count($categorisation_groups) == 0) {
|
218 |
$wpdb->query($sql);
|
219 |
$categorisation_groups = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_CATEGORISATION_GROUPS."` WHERE `active` IN ('1')");
|
220 |
}
|
221 |
+
|
222 |
foreach((array)$categorisation_groups as $cat_group) {
|
223 |
+
$wpsc_update->check_timeout();
|
224 |
+
|
225 |
$category_id = wpsc_get_meta($cat_group->id, 'category_group_id', 'wpsc_category_group');
|
226 |
|
227 |
if(!is_numeric($category_id) || ( $category_id < 1)) {
|
239 |
wpsc_update_categorymeta($category_id, 'uses_billing_address', 0);
|
240 |
}
|
241 |
|
242 |
+
if(! isset( $new_category ) || !is_wp_error($new_category))
|
243 |
+
wpsc_convert_categories($category_id, $cat_group->id);
|
244 |
}
|
245 |
+
delete_option("wpsc_product_category_children");
|
246 |
+
_get_term_hierarchy('wpsc_product_category');
|
247 |
}
|
248 |
|
249 |
/**
|
261 |
} else {
|
262 |
$categorisation = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_CATEGORIES."` WHERE `active` IN ('1') AND `group_id` IN ('{$group_id}') AND `category_parent` IN (0)");
|
263 |
}
|
264 |
+
$wpsc_update = WPSC_Update::get_instance();
|
265 |
|
266 |
if($categorisation > 0) {
|
267 |
|
268 |
foreach((array)$categorisation as $category) {
|
269 |
+
$wpsc_update->check_timeout();
|
270 |
$category_id = wpsc_get_meta($category->id, 'category_id', 'wpsc_old_category');
|
271 |
|
272 |
if(!is_numeric($category_id) || ( $category_id < 1)) {
|
306 |
}
|
307 |
}
|
308 |
|
309 |
+
function wpsc_convert_variation_sets() {
|
310 |
global $wpdb, $user_ID;
|
311 |
$variation_sets = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_VARIATIONS."`");
|
312 |
+
$wpsc_update = WPSC_Update::get_instance();
|
313 |
+
|
314 |
foreach((array)$variation_sets as $variation_set) {
|
315 |
+
$wpsc_update->check_timeout();
|
316 |
$variation_set_id = wpsc_get_meta($variation_set->id, 'variation_set_id', 'wpsc_variation_set');
|
317 |
+
|
318 |
if(!is_numeric($variation_set_id) || ( $variation_set_id < 1)) {
|
319 |
$new_variation_set = wp_insert_term( $variation_set->name, 'wpsc-variation',array('parent' => 0));
|
|
|
320 |
if(!is_wp_error($new_variation_set))
|
321 |
$variation_set_id = $new_variation_set['term_id'];
|
322 |
}
|
331 |
|
332 |
if(!is_numeric($variation_id) || ( $variation_id < 1)) {
|
333 |
$new_variation = wp_insert_term( $variation->name, 'wpsc-variation',array('parent' => $variation_set_id));
|
334 |
+
|
335 |
if(!is_wp_error($new_variation))
|
336 |
$variation_id = $new_variation['term_id'];
|
337 |
}
|
342 |
}
|
343 |
}
|
344 |
}
|
|
|
345 |
}
|
346 |
|
347 |
/**
|
353 |
function wpsc_convert_products_to_posts() {
|
354 |
global $wpdb, $user_ID;
|
355 |
// Select all products
|
356 |
+
$wpsc_update = WPSC_Update::get_instance();
|
357 |
+
if ( ! empty($wpdb->charset) )
|
358 |
+
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
359 |
+
if ( ! empty($wpdb->collate) )
|
360 |
+
$charset_collate .= " COLLATE $wpdb->collate";
|
361 |
+
|
362 |
+
if ( ! $offset = get_transient( 'wpsc_update_product_offset' ) )
|
363 |
+
$offset = 0;
|
364 |
+
$limit = 90;
|
365 |
+
$sql = "
|
366 |
+
SELECT * FROM " . WPSC_TABLE_PRODUCT_LIST . "
|
367 |
+
WHERE active = '1'
|
368 |
+
LIMIT %d, %d
|
369 |
+
";
|
370 |
+
$post_created = get_transient( 'wpsc_update_current_product' );
|
371 |
+
$total = $wpdb->get_var( "SELECT COUNT(*) FROM " . WPSC_TABLE_PRODUCT_LIST . " WHERE active='1'" );
|
372 |
+
$progress = new WPSC_Update_Progress( $total );
|
373 |
+
|
374 |
+
while (true) {
|
375 |
+
$product_data = $wpdb->get_results( $wpdb->prepare( $sql, $offset, $limit ), ARRAY_A );
|
376 |
+
$i = $offset;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
|
378 |
+
if ( empty( $product_data ) )
|
379 |
+
break;
|
380 |
|
381 |
+
foreach((array)$product_data as $product) {
|
382 |
+
$wpsc_update->check_timeout( '</div>' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
|
384 |
+
$post_id = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
385 |
|
386 |
+
// if a product is in the middle of being converted
|
387 |
+
if ( $post_created && ! empty( $post_created['original_id'] ) && $post_created['original_id'] == $product['id'] )
|
388 |
+
$post_id = $post_created['post_id'];
|
389 |
+
|
390 |
+
$sku = old_get_product_meta($product['id'], 'sku', true);
|
391 |
+
|
392 |
+
if($post_id == 0) {
|
393 |
+
$post_status = "publish";
|
394 |
+
if($product['publish'] != 1) {
|
395 |
+
$post_status = "draft";
|
396 |
+
}
|
397 |
+
|
398 |
+
//check the product added time with the current time to make sure its not out - this aviods the future post status
|
399 |
+
$product_added_time = strtotime($product['date_added']);
|
400 |
+
$current_time = time();
|
401 |
+
|
402 |
+
$post_date = $product['date_added'];
|
403 |
+
if ((int)$current_time < (int)$product_added_time)
|
404 |
+
$post_date = date("Y-m-d H:i:s");
|
405 |
+
|
406 |
+
$product_post_values = array(
|
407 |
'post_author' => $user_ID,
|
408 |
+
'post_date' => $post_date,
|
409 |
+
'post_content' => $product['description'],
|
410 |
+
'post_excerpt' => $product['additional_description'],
|
411 |
+
'post_title' => $product['name'],
|
412 |
+
'post_status' => $post_status,
|
413 |
+
'post_type' => "wpsc-product",
|
414 |
+
'post_name' => $product['name']
|
415 |
+
);
|
416 |
+
|
417 |
+
$product['order'] = $wpdb->get_var( $wpdb->prepare( "
|
418 |
+
SELECT order FROM " . WPSC_TABLE_PRODUCT_ORDER . "
|
419 |
+
WHERE product_id = %d
|
420 |
+
" ), $product['id'] );
|
421 |
+
|
422 |
+
$product_post_values['menu_order'] = $product['order'];
|
423 |
+
|
424 |
+
$post_id = wp_insert_post($product_post_values);
|
425 |
+
$post_created = array(
|
426 |
+
'original_id' => $product['id'],
|
427 |
+
'post_id' => $post_id,
|
428 |
);
|
429 |
+
set_transient( 'wpsc_update_current_product', $post_created, 604800 );
|
430 |
}
|
|
|
|
|
|
|
|
|
431 |
|
432 |
+
$product_meta = $wpdb->get_results("
|
433 |
+
SELECT IF( ( `custom` != 1 ),
|
434 |
+
CONCAT( '_wpsc_', `meta_key` ) ,
|
435 |
+
`meta_key`
|
436 |
+
) AS `meta_key`,
|
437 |
+
`meta_value`
|
438 |
+
FROM `".WPSC_TABLE_PRODUCTMETA."`
|
439 |
+
WHERE `product_id` = " . $product['id'] . "
|
440 |
+
AND `meta_value` != ''", ARRAY_A);
|
441 |
+
|
442 |
+
$post_data = array();
|
443 |
+
|
444 |
+
foreach($product_meta as $k => $pm) :
|
445 |
+
if($pm['meta_value'] == 'om')
|
446 |
+
$pm['meta_value'] = 1;
|
447 |
+
$pm['meta_value'] = maybe_unserialize($pm['meta_value']);
|
448 |
+
if(strpos($pm['meta_key'], '_wpsc_') === 0)
|
449 |
+
$post_data['_wpsc_product_metadata'][$pm['meta_key']] = $pm['meta_value'];
|
450 |
+
else
|
451 |
+
update_post_meta($post_id, $pm['meta_key'], $pm['meta_value']);
|
452 |
+
endforeach;
|
453 |
+
|
454 |
+
|
455 |
+
$post_data['_wpsc_original_id'] = (int)$product['id'];
|
456 |
+
$post_data['_wpsc_price'] = (float)$product['price'];
|
457 |
+
$post_data['_wpsc_special_price'] = $post_data['_wpsc_price'] - (float)$product['special_price']; // special price get stored in a weird way in 3.7.x
|
458 |
+
$post_data['_wpsc_stock'] = (float)$product['quantity'];
|
459 |
+
$post_data['_wpsc_is_donation'] = $product['donation'];
|
460 |
+
$post_data['_wpsc_sku'] = $sku;
|
461 |
+
if((bool)$product['quantity_limited'] != true) {
|
462 |
+
$post_data['_wpsc_stock'] = false;
|
463 |
+
}
|
464 |
+
unset($post_data['_wpsc_limited_stock']);
|
465 |
+
|
466 |
+
$post_data['_wpsc_product_metadata']['is_stock_limited'] = (int)(bool)$product['quantity_limited'];
|
467 |
+
|
468 |
+
// Product Weight
|
469 |
+
$post_data['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($product['weight'], $product['weight_unit'], "pound", true);
|
470 |
+
$post_data['_wpsc_product_metadata']['weight_unit'] = $product['weight_unit'];
|
471 |
+
$post_data['_wpsc_product_metadata']['display_weight_as'] = $product['weight_unit'];
|
472 |
+
|
473 |
+
$post_data['_wpsc_product_metadata']['has_no_shipping'] = (int)(bool)$product['no_shipping'];
|
474 |
+
$post_data['_wpsc_product_metadata']['shipping'] = array('local' => $product['pnp'], 'international' => $product['international_pnp']);
|
475 |
+
|
476 |
+
|
477 |
+
$post_data['_wpsc_product_metadata']['quantity_limited'] = (int)(bool)$product['quantity_limited'];
|
478 |
+
$post_data['_wpsc_product_metadata']['special'] = (int)(bool)$product['special'];
|
479 |
+
if(isset($post_data['meta'])) {
|
480 |
+
$post_data['_wpsc_product_metadata']['unpublish_when_none_left'] = (int)(bool)$post_data['meta']['_wpsc_product_metadata']['unpublish_when_none_left'];
|
481 |
+
}
|
482 |
+
$post_data['_wpsc_product_metadata']['no_shipping'] = (int)(bool)$product['no_shipping'];
|
483 |
+
|
484 |
+
foreach($post_data as $meta_key => $meta_value) {
|
485 |
+
// prefix all meta keys with _wpsc_
|
486 |
+
update_post_meta($post_id, $meta_key, $meta_value);
|
487 |
+
}
|
488 |
+
|
489 |
+
// get the wordpress upload directory data
|
490 |
+
$wp_upload_dir_data = wp_upload_dir();
|
491 |
+
$wp_upload_basedir = $wp_upload_dir_data['basedir'];
|
492 |
+
|
493 |
+
$category_ids = array();
|
494 |
+
$category_data = $wpdb->get_col("SELECT `category_id` FROM `".WPSC_TABLE_ITEM_CATEGORY_ASSOC."` WHERE `product_id` IN ('{$product['id']}')");
|
495 |
+
foreach($category_data as $old_category_id) {
|
496 |
+
$category_ids[] = wpsc_get_meta($old_category_id, 'category_id', 'wpsc_old_category');
|
497 |
+
|
498 |
+
}
|
499 |
+
wp_set_product_categories($post_id, $category_ids);
|
500 |
+
|
501 |
+
$product_data = get_post($post_id);
|
502 |
+
$image_data = $wpdb->get_results("SELECT * FROM `".WPSC_TABLE_PRODUCT_IMAGES."` WHERE `product_id` IN ('{$product['id']}') ORDER BY `image_order` ASC", ARRAY_A);
|
503 |
+
foreach((array)$image_data as $image_row) {
|
504 |
+
$wpsc_update->check_timeout( '</div>' );
|
505 |
+
// Get the image path info
|
506 |
+
$image_pathinfo = pathinfo($image_row['image']);
|
507 |
+
|
508 |
+
// use the path info to clip off the file extension
|
509 |
+
$image_name = basename($image_pathinfo['basename'], ".{$image_pathinfo['extension']}");
|
510 |
+
|
511 |
+
// construct the full image path
|
512 |
+
$full_image_path = WPSC_IMAGE_DIR.$image_row['image'];
|
513 |
+
$attached_file_path = str_replace($wp_upload_basedir."/", '', $full_image_path);
|
514 |
+
$upload_dir = wp_upload_dir();
|
515 |
+
$new_path = $upload_dir['path'].'/'.$image_name.'.'.$image_pathinfo['extension'];
|
516 |
+
if(is_file($full_image_path)){
|
517 |
+
copy($full_image_path, $new_path);
|
518 |
+
}else{
|
519 |
+
continue;
|
520 |
+
}
|
521 |
+
// construct the full image url
|
522 |
+
$subdir = $upload_dir['subdir'].'/'.$image_name.'.'.$image_pathinfo['extension'];
|
523 |
+
$subdir = substr($subdir , 1);
|
524 |
+
$attachment_id = (int)$wpdb->get_var("SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_title` IN('$image_name') AND `post_parent` IN('$post_id') LIMIT 1");
|
525 |
+
|
526 |
+
// get the image MIME type
|
527 |
+
$mime_type_data = wpsc_get_mimetype($full_image_path, true);
|
528 |
+
if((int)$attachment_id == 0 ) {
|
529 |
+
// construct the image data array
|
530 |
+
$image_post_values = array(
|
531 |
+
'post_author' => $user_ID,
|
532 |
+
'post_parent' => $post_id,
|
533 |
+
'post_date' => $product_data->post_date,
|
534 |
+
'post_content' => $image_name,
|
535 |
+
'post_title' => $image_name,
|
536 |
+
'post_status' => "inherit",
|
537 |
+
'post_type' => "attachment",
|
538 |
+
'post_name' => sanitize_title($image_name),
|
539 |
+
'post_mime_type' => $mime_type_data['mime_type'],
|
540 |
+
'menu_order' => absint($image_row['image_order']),
|
541 |
+
'guid' => $new_path
|
542 |
+
);
|
543 |
+
$attachment_id = wp_insert_post($image_post_values);
|
544 |
+
}
|
545 |
+
|
546 |
+
update_attached_file( $attachment_id, $new_path );
|
547 |
+
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $new_path ) );
|
548 |
+
}
|
549 |
+
$i ++;
|
550 |
+
$progress->update( $i );
|
551 |
+
set_transient( 'wpsc_update_product_offset', $i, 604800 );
|
552 |
+
}
|
553 |
+
|
554 |
+
$offset += $limit;
|
555 |
}
|
|
|
556 |
//Just throwing the payment gateway update in here because it doesn't really warrant it's own function :)
|
|
|
557 |
$custom_gateways = get_option('custom_gateway_options');
|
558 |
array_walk($custom_gateways, "wpec_update_gateway");
|
559 |
update_option('custom_gateway_options', $custom_gateways);
|
572 |
}
|
573 |
function wpsc_convert_variation_combinations() {
|
574 |
global $wpdb, $user_ID, $current_version_number;
|
575 |
+
$wpsc_update = WPSC_Update::get_instance();
|
576 |
+
remove_filter( 'get_terms', 'wpsc_get_terms_category_sort_filter' );
|
577 |
+
if ( ! $offset = get_transient( 'wpsc_update_variation_comb_offset' ) )
|
578 |
+
$offset = 0;
|
579 |
+
$limit = 150;
|
580 |
+
wp_defer_term_counting( true );
|
581 |
+
$sql = "SELECT * FROM {$wpdb->posts} WHERE post_type = 'wpsc-product' AND post_parent = 0 LIMIT %d, %d";
|
582 |
|
583 |
+
$total = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'wpsc-product' AND post_parent = 0" );
|
584 |
+
$progress = new WPSC_Update_Progress( $total );
|
|
|
|
|
|
|
|
|
|
|
585 |
|
586 |
+
while ( true ) {
|
587 |
+
// get the posts
|
588 |
+
// I use a direct SQL query here because the get_posts function sometimes does not function for a reason that is not clear.
|
589 |
+
$posts = $wpdb->get_results( $wpdb->prepare( $sql, $offset, $limit ) );
|
590 |
+
$i = $offset;
|
591 |
+
if ( empty( $posts ) )
|
592 |
+
break;
|
593 |
+
|
594 |
+
foreach((array)$posts as $post) {
|
595 |
+
if ( ! $child_products = get_transient( 'wpsc_update_current_child_products' ) )
|
596 |
+
$child_products = array();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
597 |
|
598 |
+
$wpsc_update->check_timeout();
|
599 |
+
$base_product_terms = array();
|
600 |
+
//create a post template
|
601 |
+
$child_product_template = array(
|
602 |
+
'post_author' => $user_ID,
|
603 |
+
'post_content' => $post->post_content,
|
604 |
+
'post_excerpt' => $post->post_excerpt,
|
605 |
+
'post_title' => $post->post_title,
|
606 |
+
'post_status' => 'inherit',
|
607 |
+
'post_type' => "wpsc-product",
|
608 |
+
'post_name' => $post->post_title,
|
609 |
+
'post_parent' => $post->ID
|
610 |
+
);
|
611 |
+
|
612 |
+
// select the original product ID
|
613 |
+
$original_id = get_post_meta($post->ID, '_wpsc_original_id', true);
|
614 |
+
$parent_stock = get_post_meta($post->ID, '_wpsc_stock', true);
|
615 |
+
|
616 |
+
// select the variation set associations
|
617 |
+
$variation_set_associations = $wpdb->get_col("SELECT `variation_id` FROM ".WPSC_TABLE_VARIATION_ASSOC." WHERE `associated_id` = '{$original_id}'");
|
618 |
+
// select the variation associations if the count of variation sets is greater than zero
|
619 |
+
if(($original_id > 0) && (count($variation_set_associations) > 0)) {
|
620 |
+
$variation_associations = $wpdb->get_col("SELECT `value_id` FROM ".WPSC_TABLE_VARIATION_VALUES_ASSOC." WHERE `product_id` = '{$original_id}' AND `variation_id` IN(".implode(", ", $variation_set_associations).") AND `visible` IN ('1')");
|
621 |
+
} else {
|
622 |
+
// otherwise, we have no active variations, skip to the next product
|
623 |
+
$i++;
|
624 |
+
$progress->update( $i );
|
625 |
+
set_transient( 'wpsc_update_variation_comb_offset', $i, 604800 );
|
626 |
+
continue;
|
627 |
+
}
|
628 |
|
629 |
+
$variation_set_id_sql = "SELECT meta_value FROM " . WPSC_TABLE_META . " WHERE object_type='wpsc_variation_set' AND object_id IN (" . implode( ',', $variation_set_associations ) . ") AND meta_key = 'variation_set_id'";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
630 |
|
631 |
+
$variation_set_terms = $wpdb->get_col( $variation_set_id_sql );
|
632 |
+
|
633 |
+
$variation_associations_sql = "SELECT meta_value FROM " . WPSC_TABLE_META . " WHERE object_type='wpsc_variation' AND object_id IN (" . implode( ',', $variation_associations ) . ") AND meta_key = 'variation_id'";
|
634 |
+
|
635 |
+
$variation_associations_terms = $wpdb->get_col( $variation_associations_sql );
|
636 |
+
|
637 |
+
$base_product_terms = array_merge( $base_product_terms, $variation_set_terms, $variation_associations_terms );
|
638 |
+
|
639 |
+
// Now that we have the term IDs, we need to retrieve the slugs, as wp_set_object_terms will not use IDs in the way we want
|
640 |
+
// If we pass IDs into wp_set_object_terms, it creates terms using the ID as the name.
|
641 |
+
$parent_product_terms = get_terms('wpsc-variation', array(
|
642 |
+
'hide_empty' => 0,
|
643 |
+
'include' => implode(",", $base_product_terms),
|
644 |
+
'orderby' => 'parent'
|
645 |
+
));
|
646 |
+
$base_product_term_slugs = array();
|
647 |
+
foreach($parent_product_terms as $parent_product_term) {
|
648 |
+
$base_product_term_slugs[] = $parent_product_term->slug;
|
649 |
+
|
650 |
+
}
|
651 |
+
|
652 |
+
wp_set_object_terms($post->ID, $base_product_term_slugs, 'wpsc-variation');
|
653 |
+
|
654 |
+
// select all variation "products"
|
655 |
+
$variation_items = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_VARIATION_PROPERTIES." WHERE `product_id` = '{$original_id}'");
|
656 |
+
|
657 |
+
foreach((array)$variation_items as $variation_item) {
|
658 |
+
$wpsc_update->check_timeout();
|
659 |
+
// initialize the requisite arrays to empty
|
660 |
+
$variation_ids = array();
|
661 |
+
$term_data = array(
|
662 |
+
'ids' => array(),
|
663 |
+
'slugs' => array(),
|
664 |
+
'names' => array(),
|
665 |
+
);
|
666 |
+
// make a temporary copy of the product teplate
|
667 |
+
$product_values = $child_product_template;
|
668 |
+
|
669 |
+
// select all values this "product" is associated with, then loop through them, getting the term id of the variation using the value ID
|
670 |
+
$variation_associations_combinations = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_VARIATION_COMBINATIONS." WHERE `priceandstock_id` = '{$variation_item->id}'");
|
671 |
+
foreach((array)$variation_associations_combinations as $association) {
|
672 |
+
$variation_id = (int)wpsc_get_meta($association->value_id, 'variation_id', 'wpsc_variation');
|
673 |
+
// discard any values that are null, as they break the selecting of the terms
|
674 |
+
if($variation_id > 0 && in_array($association->value_id, $variation_associations) ) {
|
675 |
+
$variation_ids[] = $variation_id;
|
676 |
}
|
677 |
+
}
|
678 |
+
|
679 |
+
// if we have more than zero remaining terms, get the term data, then loop through it to convert it to a more useful set of arrays.
|
680 |
+
if(count($variation_ids) > 0 && ( count($variation_set_associations) == count($variation_ids) ) ) {
|
681 |
+
$combination_terms = get_terms('wpsc-variation', array(
|
682 |
+
'hide_empty' => 0,
|
683 |
+
'include' => implode(",", $variation_ids),
|
684 |
+
));
|
685 |
+
|
686 |
+
foreach($combination_terms as $term) {
|
687 |
+
$term_data['ids'][] = $term->term_id;
|
688 |
+
$term_data['slugs'][] = $term->slug;
|
689 |
+
$term_data['names'][] = $term->name;
|
690 |
+
}
|
691 |
+
|
692 |
+
$product_values['post_title'] .= " (".implode(", ", $term_data['names']).")";
|
693 |
+
$product_values['post_name'] = sanitize_title($product_values['post_title']);
|
694 |
+
|
695 |
+
$selected_post = get_posts(array(
|
696 |
+
'name' => $product_values['post_name'],
|
697 |
+
'post_parent' => $post->ID,
|
698 |
+
'post_type' => "wpsc-product",
|
699 |
+
'post_status' => 'all',
|
700 |
+
'suppress_filters' => true
|
701 |
+
));
|
702 |
+
|
703 |
+
$selected_post = array_shift($selected_post);
|
704 |
+
$key = md5( $post->ID . ':' . count( $term_data['ids'] ) . ':' . implode(',', $term_data['ids'] ) );
|
705 |
+
$child_product_id = false;
|
706 |
+
|
707 |
+
if ( ! empty( $child_products[$key] ) )
|
708 |
+
$child_product_id = $child_products[$key];
|
709 |
+
|
710 |
+
$post_data = array();
|
711 |
+
$post_data['_wpsc_price'] = (float)$variation_item->price;
|
712 |
+
$post_data['_wpsc_stock'] = (float)$variation_item->stock;
|
713 |
+
if( !is_numeric( $parent_stock ) )
|
714 |
+
$post_data['_wpsc_stock'] = false;
|
715 |
+
|
716 |
+
$post_data['_wpsc_original_variation_id'] = (float)$variation_item->id;
|
717 |
+
|
718 |
+
// Product Weight
|
719 |
+
$post_data['_wpsc_product_metadata']['weight'] = wpsc_convert_weight($variation_item->weight, $variation_item->weight_unit, "pound", true);
|
720 |
+
$post_data['_wpsc_product_metadata']['display_weight_as'] = $variation_item->weight_unit;
|
721 |
+
$post_data['_wpsc_product_metadata']['weight_unit'] = $variation_item->weight_unit;
|
722 |
+
|
723 |
+
$already_exists = true;
|
724 |
+
|
725 |
+
if ( ! empty( $selected_post ) && $selected_post->ID != $child_product_id ) {
|
726 |
$child_product_id = $selected_post->ID;
|
727 |
+
} elseif ( empty( $child_product_id ) ) {
|
728 |
+
$child_product_id = wp_insert_post( $product_values );
|
729 |
+
$already_exists = false;
|
730 |
}
|
|
|
|
|
731 |
|
732 |
+
if($child_product_id > 0) {
|
733 |
+
|
734 |
+
foreach($post_data as $meta_key => $meta_value) {
|
735 |
+
// prefix all meta keys with _wpsc_
|
736 |
+
update_post_meta($child_product_id, $meta_key, $meta_value);
|
737 |
+
}
|
738 |
+
|
739 |
+
|
740 |
+
wp_set_object_terms($child_product_id, $term_data['slugs'], 'wpsc-variation');
|
741 |
+
if ( ! $already_exists ) {
|
742 |
+
$child_products[$key] = $child_product_id;
|
743 |
+
set_transient( 'wpsc_update_current_child_products', $child_products, 604800 );
|
744 |
+
}
|
745 |
}
|
746 |
+
|
747 |
+
unset($term_data);
|
|
|
748 |
}
|
|
|
|
|
|
|
749 |
|
750 |
+
}
|
751 |
+
$i++;
|
752 |
+
$progress->update( $i );
|
753 |
+
set_transient( 'wpsc_update_variation_comb_offset', $i, 604800 );
|
754 |
+
delete_transient( 'wpsc_update_current_child_products' );
|
755 |
}
|
756 |
+
|
757 |
+
$offset += $limit;
|
758 |
+
|
759 |
}
|
760 |
+
delete_option("wpsc-variation_children");
|
761 |
_get_term_hierarchy('wpsc-variation');
|
762 |
delete_option("wpsc_product_category_children");
|
763 |
_get_term_hierarchy('wpsc_product_category');
|
766 |
function wpsc_update_files() {
|
767 |
global $wpdb, $user_ID;
|
768 |
$product_files = $wpdb->get_results("SELECT * FROM ".WPSC_TABLE_PRODUCT_FILES."");
|
769 |
+
$wpsc_update = WPSC_Update::get_instance();
|
770 |
|
771 |
foreach($product_files as $product_file) {
|
772 |
+
$wpsc_update->check_timeout();
|
773 |
$variation_post_ids = array();
|
774 |
if(!empty($product_file->product_id)){
|
775 |
$product_post_id = (int)$wpdb->get_var($wpdb->prepare( "SELECT `post_id` FROM `{$wpdb->postmeta}` WHERE meta_key = %s AND `meta_value` = %d LIMIT 1", '_wpsc_original_id', $product_file->product_id ));
|
858 |
*/
|
859 |
|
860 |
function old_get_product_meta($product_id, $key, $single = false) {
|
861 |
+
global $wpdb, $post_meta_cache, $blog_id;
|
862 |
+
$product_id = (int)$product_id;
|
863 |
+
$meta_values = false;
|
864 |
+
if($product_id > 0) {
|
865 |
+
$meta_id = $wpdb->get_var("SELECT `id` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_key` IN('$key') AND `product_id` = '$product_id' LIMIT 1");
|
866 |
+
//exit($meta_id);
|
867 |
+
if(is_numeric($meta_id) && ($meta_id > 0)) {
|
868 |
+
if($single != false) {
|
869 |
+
$meta_values = maybe_unserialize($wpdb->get_var("SELECT `meta_value` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_key` IN('$key') AND `product_id` = '$product_id' LIMIT 1"));
|
870 |
} else {
|
871 |
+
$meta_values = $wpdb->get_col("SELECT `meta_value` FROM `".WPSC_TABLE_PRODUCTMETA."` WHERE `meta_key` IN('$key') AND `product_id` = '$product_id'");
|
872 |
$meta_values = array_map('maybe_unserialize', $meta_values);
|
873 |
}
|
874 |
}
|
|
|
|
|
875 |
}
|
876 |
if (is_array($meta_values) && (count($meta_values) == 1)) {
|
877 |
return array_pop($meta_values);
|
wpsc-core/js/user.js
CHANGED
@@ -463,18 +463,24 @@ jQuery(document).ready(
|
|
463 |
}
|
464 |
}
|
465 |
);
|
466 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
467 |
jQuery("input.custom_gateway").change(
|
468 |
function() {
|
469 |
if(jQuery(this).attr('checked') == true) {
|
470 |
-
|
471 |
-
jQuery('table input',parent_div).attr( 'disabled', false);
|
472 |
-
jQuery('table',parent_div).css('display', 'block');
|
473 |
-
jQuery("div.custom_gateway table").not(jQuery('table',parent_div)).css('display', 'none');
|
474 |
-
|
475 |
-
jQuery("div.custom_gateway table input").not(jQuery('table input',parent_div)).attr( 'disabled', true);
|
476 |
}
|
477 |
}
|
478 |
);
|
|
|
|
|
479 |
}
|
480 |
);
|
463 |
}
|
464 |
}
|
465 |
);
|
466 |
+
|
467 |
+
function selectCustomGateway() {
|
468 |
+
var parent_div = jQuery(this).parents("div.custom_gateway");
|
469 |
+
|
470 |
+
jQuery('table input',parent_div).attr( 'disabled', false);
|
471 |
+
jQuery('table',parent_div).show();
|
472 |
+
jQuery("div.custom_gateway table").not(jQuery('table',parent_div)).hide();
|
473 |
+
jQuery("div.custom_gateway table input").not(jQuery('table input',parent_div)).attr( 'disabled', true);
|
474 |
+
}
|
475 |
+
|
476 |
jQuery("input.custom_gateway").change(
|
477 |
function() {
|
478 |
if(jQuery(this).attr('checked') == true) {
|
479 |
+
selectCustomGateway.call(this);
|
|
|
|
|
|
|
|
|
|
|
480 |
}
|
481 |
}
|
482 |
);
|
483 |
+
|
484 |
+
selectCustomGateway.call(jQuery('input.custom_gateway:checked'));
|
485 |
}
|
486 |
);
|
wpsc-core/wpsc-constants.php
CHANGED
@@ -26,9 +26,9 @@ function wpsc_core_constants() {
|
|
26 |
if(!defined('WPSC_URL'))
|
27 |
define( 'WPSC_URL', plugins_url( '', __FILE__ ) );
|
28 |
// Define Plugin version
|
29 |
-
define( 'WPSC_VERSION', '3.8.
|
30 |
-
define( 'WPSC_MINOR_VERSION', '
|
31 |
-
define( 'WPSC_PRESENTABLE_VERSION', '3.8.
|
32 |
|
33 |
// Define Debug Variables for developers
|
34 |
define( 'WPSC_DEBUG', false );
|
26 |
if(!defined('WPSC_URL'))
|
27 |
define( 'WPSC_URL', plugins_url( '', __FILE__ ) );
|
28 |
// Define Plugin version
|
29 |
+
define( 'WPSC_VERSION', '3.8.3' );
|
30 |
+
define( 'WPSC_MINOR_VERSION', '382573' );
|
31 |
+
define( 'WPSC_PRESENTABLE_VERSION', '3.8.3' );
|
32 |
|
33 |
// Define Debug Variables for developers
|
34 |
define( 'WPSC_DEBUG', false );
|
wpsc-core/wpsc-installer.php
CHANGED
@@ -45,8 +45,9 @@ function wpsc_install() {
|
|
45 |
add_option( 'wpsc_purchaselogs_fixed', true );
|
46 |
}
|
47 |
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
// run the create or update code here.
|
52 |
wpsc_create_or_update_tables();
|
@@ -563,11 +564,11 @@ function wpsc_create_or_update_tables( $debug = false ) {
|
|
563 |
|
564 |
$null_match = false;
|
565 |
if ( $existing_table_column['Null'] = 'NO' ) {
|
566 |
-
if ( stristr( $table_data['columns'][$column_name], "NOT NULL" ) !== false ) {
|
567 |
$null_match = true;
|
568 |
}
|
569 |
} else {
|
570 |
-
if ( stristr( $table_data['columns'][$column_name], "NOT NULL" ) === false ) {
|
571 |
$null_match = true;
|
572 |
}
|
573 |
}
|
@@ -591,7 +592,9 @@ function wpsc_create_or_update_tables( $debug = false ) {
|
|
591 |
foreach ( (array)$missing_or_extra_table_columns as $missing_or_extra_table_column ) {
|
592 |
if ( isset( $table_data['columns'][$missing_or_extra_table_column] ) ) {
|
593 |
//table column is missing, add it
|
594 |
-
$
|
|
|
|
|
595 |
if ( $previous_column != '' ) {
|
596 |
$previous_column = "AFTER `$previous_column`";
|
597 |
}
|
@@ -601,7 +604,7 @@ function wpsc_create_or_update_tables( $debug = false ) {
|
|
601 |
$failure_reasons[] = $wpdb->last_error;
|
602 |
}
|
603 |
// run updating functions to do more complex work with default values and the like
|
604 |
-
if ( is_callable( $table_data['actions']['after'][$missing_or_extra_table_column] ) ) {
|
605 |
$table_data['actions']['after'][$missing_or_extra_table_column]( $missing_or_extra_table_column );
|
606 |
}
|
607 |
}
|
@@ -765,7 +768,7 @@ function wpsc_add_checkout_fields() {
|
|
765 |
global $wpdb;
|
766 |
$data_forms = $wpdb->get_results( "SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "`", ARRAY_A );
|
767 |
|
768 |
-
if ( $data_forms[0]['count'] == 0 ) {
|
769 |
|
770 |
$sql = " INSERT INTO `" . WPSC_TABLE_CHECKOUT_FORMS . "` ( `name`, `type`, `mandatory`, `display_log`, `default`, `active`, `checkout_order`, `unique_name`) VALUES ( '" . __( 'Your billing/contact details', 'wpsc' ) . "', 'heading', '0', '0', '', '1', 1,''),
|
771 |
( '" . __( 'First Name', 'wpsc' ) . "', 'text', '1', '1', '', '1', 2,'billingfirstname'),
|
45 |
add_option( 'wpsc_purchaselogs_fixed', true );
|
46 |
}
|
47 |
|
48 |
+
// TODO: need a better approach to resize thumbnails
|
49 |
+
/* if ( !$first_install )
|
50 |
+
wpsc_regenerate_thumbnails(); */
|
51 |
|
52 |
// run the create or update code here.
|
53 |
wpsc_create_or_update_tables();
|
564 |
|
565 |
$null_match = false;
|
566 |
if ( $existing_table_column['Null'] = 'NO' ) {
|
567 |
+
if ( isset( $table_data['columns'][$column_name] ) && stristr( $table_data['columns'][$column_name], "NOT NULL" ) !== false ) {
|
568 |
$null_match = true;
|
569 |
}
|
570 |
} else {
|
571 |
+
if ( isset( $table_data['columns'][$column_name] ) && stristr( $table_data['columns'][$column_name], "NOT NULL" ) === false ) {
|
572 |
$null_match = true;
|
573 |
}
|
574 |
}
|
592 |
foreach ( (array)$missing_or_extra_table_columns as $missing_or_extra_table_column ) {
|
593 |
if ( isset( $table_data['columns'][$missing_or_extra_table_column] ) ) {
|
594 |
//table column is missing, add it
|
595 |
+
$index = array_search( $missing_or_extra_table_column, $supplied_table_columns ) - 1;
|
596 |
+
|
597 |
+
$previous_column = isset( $supplied_table_columns[$index] ) ? $supplied_table_columns[$index] : '';
|
598 |
if ( $previous_column != '' ) {
|
599 |
$previous_column = "AFTER `$previous_column`";
|
600 |
}
|
604 |
$failure_reasons[] = $wpdb->last_error;
|
605 |
}
|
606 |
// run updating functions to do more complex work with default values and the like
|
607 |
+
if ( isset( $table_data['actions']['after'][$missing_or_extra_table_column] ) && is_callable( $table_data['actions']['after'][$missing_or_extra_table_column] ) ) {
|
608 |
$table_data['actions']['after'][$missing_or_extra_table_column]( $missing_or_extra_table_column );
|
609 |
}
|
610 |
}
|
768 |
global $wpdb;
|
769 |
$data_forms = $wpdb->get_results( "SELECT COUNT(*) AS `count` FROM `" . WPSC_TABLE_CHECKOUT_FORMS . "`", ARRAY_A );
|
770 |
|
771 |
+
if ( isset( $data_forms[0] ) && $data_forms[0]['count'] == 0 ) {
|
772 |
|
773 |
$sql = " INSERT INTO `" . WPSC_TABLE_CHECKOUT_FORMS . "` ( `name`, `type`, `mandatory`, `display_log`, `default`, `active`, `checkout_order`, `unique_name`) VALUES ( '" . __( 'Your billing/contact details', 'wpsc' ) . "', 'heading', '0', '0', '', '1', 1,''),
|
774 |
( '" . __( 'First Name', 'wpsc' ) . "', 'text', '1', '1', '', '1', 2,'billingfirstname'),
|
wpsc-includes/ajax.functions.php
CHANGED
@@ -530,7 +530,7 @@ function wpsc_submit_checkout() {
|
|
530 |
}
|
531 |
$selectedCountry = $wpdb->get_results( "SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode='" . $wpdb->escape( $_SESSION['wpsc_delivery_country'] ) . "'", ARRAY_A );
|
532 |
foreach ( $wpsc_cart->cart_items as $cartitem ) {
|
533 |
-
if($cartitem->meta[0]['no_shipping']
|
534 |
$categoriesIDs = $cartitem->category_id_list;
|
535 |
foreach ( (array)$categoriesIDs as $catid ) {
|
536 |
if ( is_array( $catid ) )
|
530 |
}
|
531 |
$selectedCountry = $wpdb->get_results( "SELECT id, country FROM `" . WPSC_TABLE_CURRENCY_LIST . "` WHERE isocode='" . $wpdb->escape( $_SESSION['wpsc_delivery_country'] ) . "'", ARRAY_A );
|
532 |
foreach ( $wpsc_cart->cart_items as $cartitem ) {
|
533 |
+
if( ! empty( $cartitem->meta[0]['no_shipping'] ) ) continue;
|
534 |
$categoriesIDs = $cartitem->category_id_list;
|
535 |
foreach ( (array)$categoriesIDs as $catid ) {
|
536 |
if ( is_array( $catid ) )
|
wpsc-includes/cart.class.php
CHANGED
@@ -490,18 +490,24 @@ function wpsc_shipping_quote_selected_state() {
|
|
490 |
}
|
491 |
}
|
492 |
function wpsc_have_morethanone_shipping_quote(){
|
493 |
-
global $wpsc_cart;
|
494 |
|
495 |
// if it's fixed rate shipping, and all the prices are the same, then there aren't really options.
|
496 |
-
if (count($wpsc_cart->shipping_methods) == 1 && $wpsc_cart->shipping_methods[0] == 'flatrate') {
|
497 |
$last_price = false;
|
498 |
$first_quote_name = false;
|
499 |
-
|
|
|
|
|
|
|
|
|
|
|
500 |
if (!$first_quote_name) $first_quote_name = $name;
|
501 |
if ($last_price !== false && $quote != $last_price) return true;
|
502 |
$last_price = $quote;
|
503 |
}
|
504 |
$wpsc_cart->rewind_shipping_methods();
|
|
|
505 |
$wpsc_cart->update_shipping('flatrate', $name);
|
506 |
return false;
|
507 |
}
|
490 |
}
|
491 |
}
|
492 |
function wpsc_have_morethanone_shipping_quote(){
|
493 |
+
global $wpsc_cart, $wpsc_shipping_modules;
|
494 |
|
495 |
// if it's fixed rate shipping, and all the prices are the same, then there aren't really options.
|
496 |
+
if ( count($wpsc_cart->shipping_methods) == 1 && $wpsc_cart->shipping_methods[0] == 'flatrate' ) {
|
497 |
$last_price = false;
|
498 |
$first_quote_name = false;
|
499 |
+
|
500 |
+
$quotes = $wpsc_shipping_modules['flatrate']->getQuote();
|
501 |
+
if ( empty( $quotes ) )
|
502 |
+
return false;
|
503 |
+
|
504 |
+
foreach ((array)$quotes as $name => $quote) {
|
505 |
if (!$first_quote_name) $first_quote_name = $name;
|
506 |
if ($last_price !== false && $quote != $last_price) return true;
|
507 |
$last_price = $quote;
|
508 |
}
|
509 |
$wpsc_cart->rewind_shipping_methods();
|
510 |
+
|
511 |
$wpsc_cart->update_shipping('flatrate', $name);
|
512 |
return false;
|
513 |
}
|
wpsc-includes/checkout.class.php
CHANGED
@@ -347,59 +347,31 @@ function wpsc_the_checkout_CC_validation() {
|
|
347 |
}
|
348 |
|
349 |
function wpsc_the_checkout_CC_validation_class() {
|
350 |
-
$
|
351 |
-
if ( isset( $_SESSION['wpsc_gateway_error_messages'] ) && $_SESSION['wpsc_gateway_error_messages']['card_number'] != '' ) {
|
352 |
-
$output = 'class="validation-error"';
|
353 |
-
}
|
354 |
-
return $output;
|
355 |
}
|
356 |
|
357 |
function wpsc_the_checkout_CCexpiry_validation_class() {
|
358 |
-
$
|
359 |
-
if ( $_SESSION['wpsc_gateway_error_messages']['expdate'] != '' ) {
|
360 |
-
$output = 'class="validation-error"';
|
361 |
-
}
|
362 |
-
return $output;
|
363 |
}
|
364 |
|
365 |
function wpsc_the_checkout_CCexpiry_validation() {
|
366 |
-
$
|
367 |
-
if ( $_SESSION['wpsc_gateway_error_messages']['expdate'] != '' ) {
|
368 |
-
$output = $_SESSION['wpsc_gateway_error_messages']['expdate'];
|
369 |
-
}
|
370 |
-
return $output;
|
371 |
}
|
372 |
|
373 |
function wpsc_the_checkout_CCcvv_validation_class() {
|
374 |
-
$
|
375 |
-
if ( $_SESSION['wpsc_gateway_error_messages']['card_code'] != '' ) {
|
376 |
-
$output = 'class="validation-error"';
|
377 |
-
}
|
378 |
-
return $output;
|
379 |
}
|
380 |
|
381 |
function wpsc_the_checkout_CCcvv_validation() {
|
382 |
-
$
|
383 |
-
if ( $_SESSION['wpsc_gateway_error_messages']['card_code'] != '' ) {
|
384 |
-
$output = $_SESSION['wpsc_gateway_error_messages']['card_code'];
|
385 |
-
}
|
386 |
-
return $output;
|
387 |
}
|
388 |
|
389 |
function wpsc_the_checkout_CCtype_validation_class() {
|
390 |
-
$
|
391 |
-
if ( $_SESSION['wpsc_gateway_error_messages']['cctype'] != '' ) {
|
392 |
-
$output = 'class="validation-error"';
|
393 |
-
}
|
394 |
-
return $output;
|
395 |
}
|
396 |
|
397 |
function wpsc_the_checkout_CCtype_validation() {
|
398 |
-
$
|
399 |
-
if ( $_SESSION['wpsc_gateway_error_messages']['cctype'] != '' ) {
|
400 |
-
$output = $_SESSION['wpsc_gateway_error_messages']['cctype'];
|
401 |
-
}
|
402 |
-
return $output;
|
403 |
}
|
404 |
|
405 |
function wpsc_checkout_form_is_header() {
|
@@ -461,8 +433,8 @@ function wpsc_shipping_country_list( $shippingdetails = false ) {
|
|
461 |
$output = "<input type='hidden' name='wpsc_ajax_actions' value='update_location' />";
|
462 |
$js = " onchange='submit_change_country();'";
|
463 |
}
|
464 |
-
$selected_country = $_SESSION['wpsc_delivery_country'];
|
465 |
-
$selected_region = $_SESSION['wpsc_delivery_region'];
|
466 |
|
467 |
if ( empty( $selected_country ) )
|
468 |
$selected_country = esc_attr( get_option( 'base_country' ) );
|
@@ -881,8 +853,8 @@ class wpsc_checkout {
|
|
881 |
|
882 |
if ( $form_data->type != 'heading' ) {
|
883 |
if ( is_array( $value ) ) {
|
884 |
-
if ( in_array( $form_data->unique_name, array( 'billingcountry', 'shippingcountry'
|
885 |
-
$value = $value
|
886 |
$prepared_query = $wpdb->prepare( "INSERT INTO `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` ( `log_id` , `form_id` , `value` ) VALUES ( %d, %d, %s)", $purchase_id, $form_data->id, $value );
|
887 |
} else {
|
888 |
foreach ( (array)$value as $v ) {
|
@@ -1052,35 +1024,44 @@ function wpsc_gateway_cc_check() {
|
|
1052 |
function wpsc_gateway_form_fields() {
|
1053 |
global $wpsc_gateway, $gateway_checkout_form_fields;
|
1054 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1055 |
// Match fields to gateway
|
1056 |
switch ( $wpsc_gateway->gateway['internalname'] ) {
|
1057 |
|
1058 |
case 'paypal_pro' : // legacy
|
1059 |
case 'wpsc_merchant_paypal_pro' :
|
1060 |
-
$output = sprintf( $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']], wpsc_the_checkout_CC_validation_class(), $
|
1061 |
-
wpsc_the_checkout_CCexpiry_validation_class(), $
|
1062 |
-
wpsc_the_checkout_CCcvv_validation_class(), $
|
1063 |
-
wpsc_the_checkout_CCtype_validation_class(), $
|
1064 |
);
|
1065 |
break;
|
1066 |
|
1067 |
case 'authorize' :
|
1068 |
case 'paypal_payflow' :
|
1069 |
-
$output = @sprintf( $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']], wpsc_the_checkout_CC_validation_class(), $
|
1070 |
-
wpsc_the_checkout_CCexpiry_validation_class(), $
|
1071 |
-
wpsc_the_checkout_CCcvv_validation_class(), $
|
1072 |
);
|
1073 |
break;
|
1074 |
|
1075 |
case 'eway' :
|
1076 |
case 'bluepay' :
|
1077 |
-
$output = sprintf( $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']], wpsc_the_checkout_CC_validation_class(), $
|
1078 |
-
wpsc_the_checkout_CCexpiry_validation_class(), $
|
1079 |
);
|
1080 |
break;
|
1081 |
case 'linkpoint' :
|
1082 |
-
$output = sprintf( $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']], wpsc_the_checkout_CC_validation_class(), $
|
1083 |
-
wpsc_the_checkout_CCexpiry_validation_class(), $
|
1084 |
);
|
1085 |
break;
|
1086 |
|
@@ -1088,7 +1069,7 @@ function wpsc_gateway_form_fields() {
|
|
1088 |
|
1089 |
if ( isset( $output ) && !empty( $output ) )
|
1090 |
return $output;
|
1091 |
-
|
1092 |
return $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']];
|
1093 |
}
|
1094 |
|
347 |
}
|
348 |
|
349 |
function wpsc_the_checkout_CC_validation_class() {
|
350 |
+
return empty( $_SESSION['wspc_gateway_error_messages']['card_number'] ) ? '' : 'class="validation-error"';
|
|
|
|
|
|
|
|
|
351 |
}
|
352 |
|
353 |
function wpsc_the_checkout_CCexpiry_validation_class() {
|
354 |
+
return empty( $_SESSION['wpsc_gateway_error_messages']['expdate'] ) ? '' : 'class="validation-error"';
|
|
|
|
|
|
|
|
|
355 |
}
|
356 |
|
357 |
function wpsc_the_checkout_CCexpiry_validation() {
|
358 |
+
return empty( $_SESSION['wpsc_gateway_error_messages']['expdate'] ) ? '' : $_SESSION['wpsc_gateway_error_messages']['expdate'];
|
|
|
|
|
|
|
|
|
359 |
}
|
360 |
|
361 |
function wpsc_the_checkout_CCcvv_validation_class() {
|
362 |
+
return empty( $_SESSION['wpsc_gateway_error_messages']['card_code'] ) ? '' : 'class="validation-error"';
|
|
|
|
|
|
|
|
|
363 |
}
|
364 |
|
365 |
function wpsc_the_checkout_CCcvv_validation() {
|
366 |
+
return empty( $_SESSION['wpsc_gateway_error_messages']['card_code'] ) ? '' : $_SESSION['wpsc_gateway_error_messages']['card_code'];
|
|
|
|
|
|
|
|
|
367 |
}
|
368 |
|
369 |
function wpsc_the_checkout_CCtype_validation_class() {
|
370 |
+
return empty( $_SESSION['wpsc_gateway_error_messages']['cctype'] ) ? '' : 'class="validation-error"';
|
|
|
|
|
|
|
|
|
371 |
}
|
372 |
|
373 |
function wpsc_the_checkout_CCtype_validation() {
|
374 |
+
return empty( $_SESSION['wpsc_gateway_error_messages']['cctype'] ) ? '' : $_SESSION['wpsc_gateway_error_messages']['cctype'];
|
|
|
|
|
|
|
|
|
375 |
}
|
376 |
|
377 |
function wpsc_checkout_form_is_header() {
|
433 |
$output = "<input type='hidden' name='wpsc_ajax_actions' value='update_location' />";
|
434 |
$js = " onchange='submit_change_country();'";
|
435 |
}
|
436 |
+
$selected_country = isset( $_SESSION['wpsc_delivery_country'] ) ? $_SESSION['wpsc_delivery_country'] : '';
|
437 |
+
$selected_region = isset( $_SESSION['wpsc_delivery_region'] ) ? $_SESSION['wpsc_delivery_region'] : '';
|
438 |
|
439 |
if ( empty( $selected_country ) )
|
440 |
$selected_country = esc_attr( get_option( 'base_country' ) );
|
853 |
|
854 |
if ( $form_data->type != 'heading' ) {
|
855 |
if ( is_array( $value ) ) {
|
856 |
+
if ( in_array( $form_data->unique_name, array( 'billingcountry' , 'shippingcountry') ) ) {
|
857 |
+
$value = serialize($value);
|
858 |
$prepared_query = $wpdb->prepare( "INSERT INTO `" . WPSC_TABLE_SUBMITED_FORM_DATA . "` ( `log_id` , `form_id` , `value` ) VALUES ( %d, %d, %s)", $purchase_id, $form_data->id, $value );
|
859 |
} else {
|
860 |
foreach ( (array)$value as $v ) {
|
1024 |
function wpsc_gateway_form_fields() {
|
1025 |
global $wpsc_gateway, $gateway_checkout_form_fields;
|
1026 |
|
1027 |
+
$messages = isset( $_SESSION['wpsc_gateway_error_messages'] ) ? $_SESSION['wpsc_gateway_error_messages'] : array();
|
1028 |
+
|
1029 |
+
$error = array(
|
1030 |
+
'card_number' => empty( $messages['card_number'] ) ? '' : $messages['card_number'],
|
1031 |
+
'expdate' => empty( $messages['expdate'] ) ? '' : $messages['expdate'],
|
1032 |
+
'card_code' => empty( $messages['card_code'] ) ? '' : $messages['card_code'],
|
1033 |
+
'cctype' => empty( $messages['cctype'] ) ? '' : $messages['cctype'],
|
1034 |
+
);
|
1035 |
+
|
1036 |
// Match fields to gateway
|
1037 |
switch ( $wpsc_gateway->gateway['internalname'] ) {
|
1038 |
|
1039 |
case 'paypal_pro' : // legacy
|
1040 |
case 'wpsc_merchant_paypal_pro' :
|
1041 |
+
$output = sprintf( $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']], wpsc_the_checkout_CC_validation_class(), $error['card_number'],
|
1042 |
+
wpsc_the_checkout_CCexpiry_validation_class(), $error['expdate'],
|
1043 |
+
wpsc_the_checkout_CCcvv_validation_class(), $error['card_code'],
|
1044 |
+
wpsc_the_checkout_CCtype_validation_class(), $error['cctype']
|
1045 |
);
|
1046 |
break;
|
1047 |
|
1048 |
case 'authorize' :
|
1049 |
case 'paypal_payflow' :
|
1050 |
+
$output = @sprintf( $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']], wpsc_the_checkout_CC_validation_class(), $error['card_number'],
|
1051 |
+
wpsc_the_checkout_CCexpiry_validation_class(), $error['expdate'],
|
1052 |
+
wpsc_the_checkout_CCcvv_validation_class(), $error['card_code']
|
1053 |
);
|
1054 |
break;
|
1055 |
|
1056 |
case 'eway' :
|
1057 |
case 'bluepay' :
|
1058 |
+
$output = sprintf( $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']], wpsc_the_checkout_CC_validation_class(), $error['card_number'],
|
1059 |
+
wpsc_the_checkout_CCexpiry_validation_class(), $error['expdate']
|
1060 |
);
|
1061 |
break;
|
1062 |
case 'linkpoint' :
|
1063 |
+
$output = sprintf( $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']], wpsc_the_checkout_CC_validation_class(), $error['card_number'],
|
1064 |
+
wpsc_the_checkout_CCexpiry_validation_class(), $error['expdate']
|
1065 |
);
|
1066 |
break;
|
1067 |
|
1069 |
|
1070 |
if ( isset( $output ) && !empty( $output ) )
|
1071 |
return $output;
|
1072 |
+
elseif ( isset( $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']] ) )
|
1073 |
return $gateway_checkout_form_fields[$wpsc_gateway->gateway['internalname']];
|
1074 |
}
|
1075 |
|
wpsc-includes/merchant.class.php
CHANGED
@@ -149,11 +149,21 @@ class wpsc_merchant {
|
|
149 |
$address_data['billing']['state'] = wpsc_get_state_by_id( $country[1], 'code' );
|
150 |
|
151 |
break;
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
153 |
case 'shippingstate' :
|
154 |
-
if (
|
155 |
-
$address_data[
|
156 |
-
|
157 |
break;
|
158 |
|
159 |
default :
|
@@ -190,6 +200,7 @@ class wpsc_merchant {
|
|
190 |
'billing_address' => $address_data['billing'],
|
191 |
'shipping_address' => $address_data['shipping'],
|
192 |
);
|
|
|
193 |
}
|
194 |
|
195 |
/**
|
@@ -214,9 +225,10 @@ class wpsc_merchant {
|
|
214 |
$this->cart_data['is_subscription'] = true;
|
215 |
|
216 |
|
217 |
-
$rebill_interval = get_post_meta( $cart_row['prodid'], '_wpsc_rebill_interval', true )
|
|
|
218 |
|
219 |
-
|
220 |
$new_cart_item = array(
|
221 |
"cart_item_id" => $cart_row['id'],
|
222 |
"product_id" => $cart_row['prodid'],
|
@@ -231,14 +243,14 @@ class wpsc_merchant {
|
|
231 |
"is_subscription" => $is_recurring,
|
232 |
"recurring_data" => array(
|
233 |
"rebill_interval" => array(
|
234 |
-
'unit' => $rebill_interval['unit'],
|
235 |
-
'length' => $rebill_interval['number']
|
236 |
),
|
237 |
"charge_to_expiry" => (bool)get_post_meta( $cart_row['prodid'], '_wpsc_charge_to_expiry', true ),
|
238 |
"times_to_rebill" => get_post_meta( $cart_row['prodid'], '_wpsc_rebill_number', true )
|
239 |
)
|
240 |
);
|
241 |
-
|
242 |
$this->cart_items[] = $new_cart_item;
|
243 |
}
|
244 |
}
|
@@ -270,7 +282,23 @@ class wpsc_merchant {
|
|
270 |
* go to transaction results, if this changes and you extend this, your merchant module may go to the wrong place
|
271 |
*/
|
272 |
function go_to_transaction_results( $session_id ) {
|
273 |
-
global $wpdb;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
274 |
|
275 |
$transaction_url_with_sessionid = add_query_arg( 'sessionid', $session_id, get_option( 'transact_url' ) );
|
276 |
wp_redirect( $transaction_url_with_sessionid );
|
149 |
$address_data['billing']['state'] = wpsc_get_state_by_id( $country[1], 'code' );
|
150 |
|
151 |
break;
|
152 |
+
|
153 |
+
case 'shippingcountry' :
|
154 |
+
$country = maybe_unserialize( $collected_form_row['value'] );
|
155 |
+
|
156 |
+
if ( is_array( $country ) ) {
|
157 |
+
$address_data['shipping']['state'] = wpsc_get_state_by_id( $country[1], 'code' );
|
158 |
+
$country = $country[0];
|
159 |
+
}
|
160 |
+
|
161 |
+
$address_data[$address_data_set][$address_key] = $country;
|
162 |
+
break;
|
163 |
+
|
164 |
case 'shippingstate' :
|
165 |
+
if ( is_numeric( $collected_form_row['value'] ) && empty( $address_data['shipping']['state'] ) )
|
166 |
+
$address_data['shipping']['state'] = wpsc_get_state_by_id( $collected_form_row['value'], 'code' );
|
|
|
167 |
break;
|
168 |
|
169 |
default :
|
200 |
'billing_address' => $address_data['billing'],
|
201 |
'shipping_address' => $address_data['shipping'],
|
202 |
);
|
203 |
+
|
204 |
}
|
205 |
|
206 |
/**
|
225 |
$this->cart_data['is_subscription'] = true;
|
226 |
|
227 |
|
228 |
+
if ( ! $rebill_interval = get_post_meta( $cart_row['prodid'], '_wpsc_rebill_interval', true ) )
|
229 |
+
$rebill_interval = array();
|
230 |
|
231 |
+
|
232 |
$new_cart_item = array(
|
233 |
"cart_item_id" => $cart_row['id'],
|
234 |
"product_id" => $cart_row['prodid'],
|
243 |
"is_subscription" => $is_recurring,
|
244 |
"recurring_data" => array(
|
245 |
"rebill_interval" => array(
|
246 |
+
'unit' => isset( $rebill_interval['unit'] ) ? $rebill_interval['unit'] : null,
|
247 |
+
'length' => isset( $rebill_interval['number'] ) ? $rebill_interval['number'] : null,
|
248 |
),
|
249 |
"charge_to_expiry" => (bool)get_post_meta( $cart_row['prodid'], '_wpsc_charge_to_expiry', true ),
|
250 |
"times_to_rebill" => get_post_meta( $cart_row['prodid'], '_wpsc_rebill_number', true )
|
251 |
)
|
252 |
);
|
253 |
+
|
254 |
$this->cart_items[] = $new_cart_item;
|
255 |
}
|
256 |
}
|
282 |
* go to transaction results, if this changes and you extend this, your merchant module may go to the wrong place
|
283 |
*/
|
284 |
function go_to_transaction_results( $session_id ) {
|
285 |
+
global $wpdb, $purchase_log;
|
286 |
+
|
287 |
+
//Now to do actions once the payment has been attempted
|
288 |
+
switch ($purchase_log['processed']) {
|
289 |
+
case 3:
|
290 |
+
// payment worked
|
291 |
+
do_action('wpsc_payment_successful');
|
292 |
+
break;
|
293 |
+
case 1:
|
294 |
+
// payment declined
|
295 |
+
do_action('wpsc_payment_failed');
|
296 |
+
break;
|
297 |
+
case 2:
|
298 |
+
// something happened with the payment
|
299 |
+
do_action('wpsc_payment_incomplete');
|
300 |
+
break;
|
301 |
+
}
|
302 |
|
303 |
$transaction_url_with_sessionid = add_query_arg( 'sessionid', $session_id, get_option( 'transact_url' ) );
|
304 |
wp_redirect( $transaction_url_with_sessionid );
|
wpsc-includes/purchaselogs.class.php
CHANGED
@@ -724,7 +724,7 @@ class wpsc_purchaselogs {
|
|
724 |
|
725 |
$this->current_timestamp = time();
|
726 |
//if there are no reccords set the date to now.
|
727 |
-
$this->earliest_timestamp = ($earliest_record[0]['date'])?$earliest_record[0]['date']:time();
|
728 |
|
729 |
$this->current_year = date( "Y" );
|
730 |
$this->earliest_year = date( "Y", $this->earliest_timestamp );
|
724 |
|
725 |
$this->current_timestamp = time();
|
726 |
//if there are no reccords set the date to now.
|
727 |
+
$this->earliest_timestamp = ( isset( $earliest_record[0] ) && isset( $earliest_record[0]['date'] ) )?$earliest_record[0]['date']:time();
|
728 |
|
729 |
$this->current_year = date( "Y" );
|
730 |
$this->earliest_year = date( "Y", $this->earliest_timestamp );
|
wpsc-includes/theme.functions.php
CHANGED
@@ -1079,29 +1079,42 @@ function wpsc_products_page( $content = '' ) {
|
|
1079 |
return $content;
|
1080 |
}
|
1081 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1082 |
function wpsc_all_products_on_page(){
|
1083 |
global $wp_query,$wpsc_query;
|
1084 |
do_action('wpsc_swap_the_template');
|
1085 |
$products_page_id = wpec_get_the_post_id_by_shortcode('[productspage]');
|
1086 |
-
|
1087 |
-
|
1088 |
-
|
1089 |
-
|
1090 |
-
|
1091 |
-
|
1092 |
-
|
1093 |
-
|
1094 |
-
|
1095 |
-
|
1096 |
-
include(STYLESHEETPATH. '/single.php');
|
1097 |
-
exit();
|
1098 |
-
}elseif(file_exists(STYLESHEETPATH.'/index.php')){
|
1099 |
-
include(STYLESHEETPATH. '/index.php');
|
1100 |
-
exit();
|
1101 |
}
|
1102 |
-
|
1103 |
-
|
1104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1105 |
}
|
1106 |
add_action('template_redirect', 'wpsc_all_products_on_page');
|
1107 |
|
1079 |
return $content;
|
1080 |
}
|
1081 |
}
|
1082 |
+
|
1083 |
+
function wpsc_thesis_compat( $loop ) {
|
1084 |
+
$loop[1] = 'page';
|
1085 |
+
return $loop;
|
1086 |
+
}
|
1087 |
+
|
1088 |
function wpsc_all_products_on_page(){
|
1089 |
global $wp_query,$wpsc_query;
|
1090 |
do_action('wpsc_swap_the_template');
|
1091 |
$products_page_id = wpec_get_the_post_id_by_shortcode('[productspage]');
|
1092 |
+
$term = get_query_var( 'wpsc_product_category' );
|
1093 |
+
$obj = get_queried_object();
|
1094 |
+
$id = isset( $obj->ID ) ? $obj->ID : null;
|
1095 |
+
|
1096 |
+
if( get_query_var( 'post_type' ) == 'wpsc-product' || $term || ( $id == $products_page_id )){
|
1097 |
+
|
1098 |
+
$templates = array();
|
1099 |
+
|
1100 |
+
if ( $term && ! is_single() ) {
|
1101 |
+
array_push( $templates, "taxonomy-wpsc_product_category-{$term}.php", 'taxonomy-wpsc_product_category.php' );
|
|
|
|
|
|
|
|
|
|
|
1102 |
}
|
1103 |
+
|
1104 |
+
array_push( $templates, 'page.php', 'single.php' );
|
1105 |
|
1106 |
+
if ( is_single() )
|
1107 |
+
array_unshift( $templates, 'single-wpsc-product.php' );
|
1108 |
+
|
1109 |
+
// have to pass 'page' as the template type. This is lame, btw, and needs a rewrite in 4.0
|
1110 |
+
if ( ! $template = get_query_template( 'page', $templates ) )
|
1111 |
+
$template = get_index_template();
|
1112 |
+
|
1113 |
+
add_filter( 'thesis_custom_loop', 'wpsc_thesis_compat' );
|
1114 |
+
|
1115 |
+
include( $template );
|
1116 |
+
exit;
|
1117 |
+
}
|
1118 |
}
|
1119 |
add_action('template_redirect', 'wpsc_all_products_on_page');
|
1120 |
|
wpsc-merchants/paypal-express.merchant.php
CHANGED
@@ -60,7 +60,7 @@ class wpsc_merchant_paypal_express extends wpsc_merchant {
|
|
60 |
$PROXY_HOST = '127.0.0.1';
|
61 |
$PROXY_PORT = '808';
|
62 |
$USE_PROXY = false;
|
63 |
-
$version="
|
64 |
|
65 |
// PayPal API Credentials
|
66 |
$API_UserName=get_option('paypal_certified_apiuser');
|
@@ -91,7 +91,7 @@ class wpsc_merchant_paypal_express extends wpsc_merchant {
|
|
91 |
'country' => $this->cart_data['shipping_address']['country'],
|
92 |
'zip' => $this->cart_data['shipping_address']['post_code']
|
93 |
);
|
94 |
-
if($this->cart_data['shipping_address']['state']
|
95 |
$paypal_vars += array(
|
96 |
'state' => $this->cart_data['shipping_address']['state']
|
97 |
);
|
@@ -146,14 +146,33 @@ class wpsc_merchant_paypal_express extends wpsc_merchant {
|
|
146 |
|
147 |
}
|
148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
149 |
function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL) {
|
150 |
global $wpdb;
|
151 |
|
152 |
-
$nvpstr = "&
|
153 |
-
$nvpstr = $nvpstr . "&
|
154 |
$nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
|
155 |
$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
|
156 |
-
$nvpstr = $nvpstr . "&
|
157 |
$data = array();
|
158 |
if(!isset($this->cart_data['shipping_address']['first_name']) && !isset($this->cart_data['shipping_address']['last_name'])){
|
159 |
$this->cart_data['shipping_address']['first_name'] =$this->cart_data['billing_address']['first_name'];
|
@@ -161,18 +180,38 @@ class wpsc_merchant_paypal_express extends wpsc_merchant {
|
|
161 |
|
162 |
}
|
163 |
$data += array(
|
164 |
-
'
|
165 |
-
'
|
166 |
-
'
|
167 |
-
'
|
168 |
-
'
|
169 |
);
|
170 |
-
|
|
|
171 |
$data += array(
|
172 |
-
'
|
173 |
);
|
174 |
-
}
|
175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
if(count($data) >= 4) {
|
177 |
$temp_data = array();
|
178 |
foreach($data as $key => $value)
|
@@ -182,6 +221,7 @@ class wpsc_merchant_paypal_express extends wpsc_merchant {
|
|
182 |
}
|
183 |
$_SESSION["currencyCodeType"] = $currencyCodeType;
|
184 |
$_SESSION["PaymentType"] = $paymentType;
|
|
|
185 |
$resArray= paypal_hash_call("SetExpressCheckout", $nvpstr);
|
186 |
$ack = strtoupper($resArray["ACK"]);
|
187 |
if($ack=="SUCCESS") {
|
@@ -285,9 +325,9 @@ function form_paypal_express() {
|
|
285 |
$store_currency_code = $wpdb->get_var("SELECT `code` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `id` IN ('".absint(get_option('currency_type'))."')");
|
286 |
$current_currency = get_option('paypal_curcode');
|
287 |
|
288 |
-
if(($current_currency == '') && in_array($
|
289 |
-
update_option('paypal_curcode', $
|
290 |
-
$current_currency = $
|
291 |
}
|
292 |
if($current_currency != $store_currency_code) {
|
293 |
$output .= "<tr> <td colspan='2'><strong class='form_group'>".__('Currency Converter')."</td> </tr>
|
@@ -331,12 +371,8 @@ function paypal_express_currencyconverter(){
|
|
331 |
$curr=new CURRENCYCONVERTER();
|
332 |
if($paypal_currency_code != $local_currency_code) {
|
333 |
$paypal_currency_productprice = $curr->convert($_SESSION['paypalAmount'],$paypal_currency_code,$local_currency_code);
|
334 |
-
$paypal_currency_shipping = $curr->convert($local_currency_shipping,$paypal_currency_code,$local_currency_code);
|
335 |
-
$base_shipping = $curr->convert($purchase_log['base_shipping'],$paypal_currency_code, $local_currency_code);
|
336 |
} else {
|
337 |
$paypal_currency_productprice = $_SESSION['paypalAmount'];
|
338 |
-
$paypal_currency_shipping = $local_currency_shipping;
|
339 |
-
$base_shipping = $purchase_log['base_shipping'];
|
340 |
}
|
341 |
switch($paypal_currency_code) {
|
342 |
case "JPY":
|
@@ -352,7 +388,6 @@ function paypal_express_currencyconverter(){
|
|
352 |
break;
|
353 |
}
|
354 |
$_SESSION['paypalAmount'] = number_format(sprintf("%01.2f", $paypal_currency_productprice),$decimal_places,'.','');
|
355 |
-
|
356 |
}
|
357 |
|
358 |
|
@@ -439,22 +474,21 @@ function paypal_processingfunctions(){
|
|
439 |
</table>";
|
440 |
|
441 |
}else if(isset($_REQUEST['act']) && ($_REQUEST['act']=='do')){
|
442 |
-
session_start();
|
443 |
-
|
444 |
/* Gather the information to make the final call to
|
445 |
finalize the PayPal payment. The variable nvpstr
|
446 |
holds the name value pairs */
|
447 |
-
|
448 |
$token =urlencode($_REQUEST['token']);
|
|
|
449 |
$paymentAmount =urlencode ($_SESSION['paypalAmount']);
|
450 |
-
$paymentType = urlencode($_SESSION['
|
451 |
$currCodeType = urlencode(get_option('paypal_curcode'));
|
452 |
$payerID = urlencode($_REQUEST['PayerID']);
|
453 |
$serverName = urlencode($_SERVER['SERVER_NAME']);
|
454 |
$BN='Instinct_e-commerce_wp-shopping-cart_NZ';
|
455 |
-
$nvpstr='&TOKEN='.$token.'&PAYERID='.$payerID.'&
|
456 |
$resArray=paypal_hash_call("DoExpressCheckoutPayment",$nvpstr);
|
457 |
-
|
458 |
/* Display the API response back to the browser.
|
459 |
If the response from PayPal was a success, display the response parameters'
|
460 |
If the response was an error, display the errors received using APIError.php. */
|
@@ -463,13 +497,12 @@ function paypal_processingfunctions(){
|
|
463 |
if($ack!="SUCCESS"){
|
464 |
$location = get_option('transact_url')."&act=error";
|
465 |
}else{
|
466 |
-
$transaction_id = $wpdb->escape($resArray['
|
467 |
-
switch($resArray['
|
468 |
case 'Processed': // I think this is mostly equivalent to Completed
|
469 |
case 'Completed':
|
470 |
$wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `processed` = '3' WHERE `sessionid` = ".$sessionid." LIMIT 1");
|
471 |
-
|
472 |
-
transaction_results($_SESSION['wpsc_sessionid'], false, $transaction_id);
|
473 |
break;
|
474 |
|
475 |
case 'Pending': // need to wait for "Completed" before processing
|
@@ -507,7 +540,7 @@ function paypal_processingfunctions(){
|
|
507 |
the varialbes were set in the web form, and the resulting string
|
508 |
is stored in $nvpstr */
|
509 |
|
510 |
-
$nvpstr="&
|
511 |
|
512 |
/* Make the call to PayPal to set the Express Checkout token
|
513 |
If the API call succeded, then redirect the buyer to PayPal
|
@@ -572,9 +605,6 @@ function paypal_processingfunctions(){
|
|
572 |
|
573 |
********************************************************/
|
574 |
|
575 |
-
|
576 |
-
session_start();
|
577 |
-
|
578 |
/* Collect the necessary information to complete the
|
579 |
authorization for the PayPal payment
|
580 |
*/
|
@@ -596,14 +626,16 @@ function paypal_processingfunctions(){
|
|
596 |
if(isset($_REQUEST['TOKEN']) && !isset($_REQUEST['PAYERID'])){
|
597 |
$_SESSION['paypalExpressMessage']= '<h4>TRANSACTION CANCELED</h4>';
|
598 |
}else{
|
|
|
|
|
599 |
$output ="
|
600 |
<table width='400' class='paypal_express_form'>
|
601 |
<tr>
|
602 |
-
<td align='left' class='firstcol'><b>
|
603 |
<td align='left'>" . wpsc_currency_display($_SESSION['paypalAmount']) . "</td>
|
604 |
</tr>
|
605 |
<tr>
|
606 |
-
<td align='left'><b>" . __('Shipping Address:', 'wpsc' ) . " </b></td>
|
607 |
</tr>
|
608 |
<tr>
|
609 |
<td align='left' class='firstcol'>
|
@@ -640,7 +672,7 @@ function paypal_processingfunctions(){
|
|
640 |
<td align='left'>".$resArray['SHIPTOCOUNTRYNAME']."</td>
|
641 |
</tr>
|
642 |
<tr>
|
643 |
-
<td>";
|
644 |
|
645 |
$output .= "<form action=".get_option('transact_url')." method='post'>\n";
|
646 |
$output .= " <input type='hidden' name='totalAmount' value='".wpsc_cart_total(false)."' />\n";
|
@@ -673,13 +705,13 @@ function paypal_processingfunctions(){
|
|
673 |
|
674 |
function paypal_hash_call($methodName,$nvpStr) {
|
675 |
//declaring of variables
|
676 |
-
$version =
|
677 |
if ( 'sandbox' == get_option('paypal_certified_server_type') ) {
|
678 |
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
|
679 |
-
$paypal_certified_url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=";
|
680 |
} else {
|
681 |
$API_Endpoint = "https://api-3t.paypal.com/nvp";
|
682 |
-
$paypal_certified_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=";
|
683 |
}
|
684 |
|
685 |
$USE_PROXY = false;
|
@@ -702,13 +734,13 @@ function paypal_hash_call($methodName,$nvpStr) {
|
|
702 |
$options = array(
|
703 |
'timeout' => 5,
|
704 |
'body' => $nvpreq,
|
|
|
705 |
);
|
706 |
|
707 |
-
$_SESSION['nvpReqArray']=$nvpReqArray;
|
708 |
$nvpReqArray=paypal_deformatNVP($nvpreq);
|
709 |
-
|
710 |
$res = wp_remote_post($API_Endpoint, $options);
|
711 |
-
|
712 |
if ( is_wp_error($res) ) {
|
713 |
$_SESSION['curl_error_msg'] = 'WP HTTP Error: ' . $res->get_error_message();
|
714 |
$nvpResArray=paypal_deformatNVP('');
|
60 |
$PROXY_HOST = '127.0.0.1';
|
61 |
$PROXY_PORT = '808';
|
62 |
$USE_PROXY = false;
|
63 |
+
$version="71";
|
64 |
|
65 |
// PayPal API Credentials
|
66 |
$API_UserName=get_option('paypal_certified_apiuser');
|
91 |
'country' => $this->cart_data['shipping_address']['country'],
|
92 |
'zip' => $this->cart_data['shipping_address']['post_code']
|
93 |
);
|
94 |
+
if( ! empty( $this->cart_data['shipping_address']['state'] ) ) {
|
95 |
$paypal_vars += array(
|
96 |
'state' => $this->cart_data['shipping_address']['state']
|
97 |
);
|
146 |
|
147 |
}
|
148 |
|
149 |
+
function format_price( $price ) {
|
150 |
+
$paypal_currency_code = get_option('paypal_curcode', 'US');
|
151 |
+
|
152 |
+
switch($paypal_currency_code) {
|
153 |
+
case "JPY":
|
154 |
+
$decimal_places = 0;
|
155 |
+
break;
|
156 |
+
|
157 |
+
case "HUF":
|
158 |
+
$decimal_places = 0;
|
159 |
+
break;
|
160 |
+
|
161 |
+
default:
|
162 |
+
$decimal_places = 2;
|
163 |
+
break;
|
164 |
+
}
|
165 |
+
return number_format(sprintf("%01.2f", $price),$decimal_places,'.','');
|
166 |
+
}
|
167 |
+
|
168 |
function CallShortcutExpressCheckout( $paymentAmount, $currencyCodeType, $paymentType, $returnURL, $cancelURL) {
|
169 |
global $wpdb;
|
170 |
|
171 |
+
$nvpstr = "&PAYMENTREQUEST_0_AMT=". $paymentAmount;
|
172 |
+
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_PAYMENTACTION=" . $paymentType;
|
173 |
$nvpstr = $nvpstr . "&RETURNURL=" . $returnURL;
|
174 |
$nvpstr = $nvpstr . "&CANCELURL=" . $cancelURL;
|
175 |
+
$nvpstr = $nvpstr . "&PAYMENTREQUEST_0_CURRENCYCODE=" . $currencyCodeType;
|
176 |
$data = array();
|
177 |
if(!isset($this->cart_data['shipping_address']['first_name']) && !isset($this->cart_data['shipping_address']['last_name'])){
|
178 |
$this->cart_data['shipping_address']['first_name'] =$this->cart_data['billing_address']['first_name'];
|
180 |
|
181 |
}
|
182 |
$data += array(
|
183 |
+
'PAYMENTREQUEST_0_SHIPTONAME' => $this->cart_data['shipping_address']['first_name'].' '.$this->cart_data['shipping_address']['last_name'],
|
184 |
+
'PAYMENTREQUEST_0_SHIPTOSTREET' => $this->cart_data['shipping_address']['address'],
|
185 |
+
'PAYMENTREQUEST_0_SHIPTOCITY' => $this->cart_data['shipping_address']['city'],
|
186 |
+
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => $this->cart_data['shipping_address']['country'],
|
187 |
+
'PAYMENTREQUEST_0_SHIPTOZIP' => $this->cart_data['shipping_address']['post_code'],
|
188 |
);
|
189 |
+
|
190 |
+
if( ! empty( $this->cart_data['shipping_address']['state'] ) ){
|
191 |
$data += array(
|
192 |
+
'PAYMENTREQUEST_0_SHIPTOSTATE' => $this->cart_data['shipping_address']['state']
|
193 |
);
|
194 |
+
}
|
195 |
|
196 |
+
$i = 0;
|
197 |
+
$item_total = 0;
|
198 |
+
$tax_total = 0;
|
199 |
+
$shipping_total = 0;
|
200 |
+
foreach ( $this->cart_items as $cart_item ) {
|
201 |
+
$data["L_PAYMENTREQUEST_0_NAME{$i}"] = $cart_item['name'];
|
202 |
+
$data["L_PAYMENTREQUEST_0_AMT{$i}"] = $cart_item['price'];
|
203 |
+
$data["L_PAYMENTREQUEST_0_NUMBER{$i}"] = $i;
|
204 |
+
$data["L_PAYMENTREQUEST_0_QTY{$i}"] = $cart_item['quantity'];
|
205 |
+
$item_total += $cart_item['price'] * $cart_item['quantity'];
|
206 |
+
$shipping_total += $cart_item['shipping'];
|
207 |
+
$i ++;
|
208 |
+
}
|
209 |
+
|
210 |
+
$data["PAYMENTREQUEST_0_ITEMAMT"] = $this->format_price( $item_total );
|
211 |
+
$data["PAYMENTREQUEST_0_SHIPPINGAMT"] = $this->format_price( $this->cart_data['base_shipping'] + $shipping_total );
|
212 |
+
if ( ! wpsc_tax_isincluded() )
|
213 |
+
$data["PAYMENTREQUEST_0_TAXAMT"] = $this->cart_data['cart_tax'];
|
214 |
+
|
215 |
if(count($data) >= 4) {
|
216 |
$temp_data = array();
|
217 |
foreach($data as $key => $value)
|
221 |
}
|
222 |
$_SESSION["currencyCodeType"] = $currencyCodeType;
|
223 |
$_SESSION["PaymentType"] = $paymentType;
|
224 |
+
|
225 |
$resArray= paypal_hash_call("SetExpressCheckout", $nvpstr);
|
226 |
$ack = strtoupper($resArray["ACK"]);
|
227 |
if($ack=="SUCCESS") {
|
325 |
$store_currency_code = $wpdb->get_var("SELECT `code` FROM `".WPSC_TABLE_CURRENCY_LIST."` WHERE `id` IN ('".absint(get_option('currency_type'))."')");
|
326 |
$current_currency = get_option('paypal_curcode');
|
327 |
|
328 |
+
if(($current_currency == '') && in_array($store_currency_code, $wpsc_gateways['wpsc_merchant_paypal_express']['supported_currencies']['currency_list'])) {
|
329 |
+
update_option('paypal_curcode', $store_currency_code);
|
330 |
+
$current_currency = $store_currency_code;
|
331 |
}
|
332 |
if($current_currency != $store_currency_code) {
|
333 |
$output .= "<tr> <td colspan='2'><strong class='form_group'>".__('Currency Converter')."</td> </tr>
|
371 |
$curr=new CURRENCYCONVERTER();
|
372 |
if($paypal_currency_code != $local_currency_code) {
|
373 |
$paypal_currency_productprice = $curr->convert($_SESSION['paypalAmount'],$paypal_currency_code,$local_currency_code);
|
|
|
|
|
374 |
} else {
|
375 |
$paypal_currency_productprice = $_SESSION['paypalAmount'];
|
|
|
|
|
376 |
}
|
377 |
switch($paypal_currency_code) {
|
378 |
case "JPY":
|
388 |
break;
|
389 |
}
|
390 |
$_SESSION['paypalAmount'] = number_format(sprintf("%01.2f", $paypal_currency_productprice),$decimal_places,'.','');
|
|
|
391 |
}
|
392 |
|
393 |
|
474 |
</table>";
|
475 |
|
476 |
}else if(isset($_REQUEST['act']) && ($_REQUEST['act']=='do')){
|
|
|
|
|
477 |
/* Gather the information to make the final call to
|
478 |
finalize the PayPal payment. The variable nvpstr
|
479 |
holds the name value pairs */
|
480 |
+
|
481 |
$token =urlencode($_REQUEST['token']);
|
482 |
+
|
483 |
$paymentAmount =urlencode ($_SESSION['paypalAmount']);
|
484 |
+
$paymentType = urlencode($_SESSION['PaymentType']);
|
485 |
$currCodeType = urlencode(get_option('paypal_curcode'));
|
486 |
$payerID = urlencode($_REQUEST['PayerID']);
|
487 |
$serverName = urlencode($_SERVER['SERVER_NAME']);
|
488 |
$BN='Instinct_e-commerce_wp-shopping-cart_NZ';
|
489 |
+
$nvpstr='&TOKEN='.$token.'&PAYERID='.$payerID.'&PAYMENTREQUEST_0_PAYMENTACTION=Sale&PAYMENTREQUEST_0_AMT='.$paymentAmount.'&PAYMENTREQUEST_0_CURRENCYCODE='.$currCodeType.'&IPADDRESS='.$serverName."&BUTTONSOURCE=".$BN ;
|
490 |
$resArray=paypal_hash_call("DoExpressCheckoutPayment",$nvpstr);
|
491 |
+
|
492 |
/* Display the API response back to the browser.
|
493 |
If the response from PayPal was a success, display the response parameters'
|
494 |
If the response was an error, display the errors received using APIError.php. */
|
497 |
if($ack!="SUCCESS"){
|
498 |
$location = get_option('transact_url')."&act=error";
|
499 |
}else{
|
500 |
+
$transaction_id = $wpdb->escape($resArray['PAYMENTINFO_0_TRANSACTIONID']);
|
501 |
+
switch($resArray['PAYMENTINFO_0_PAYMENTSTATUS']) {
|
502 |
case 'Processed': // I think this is mostly equivalent to Completed
|
503 |
case 'Completed':
|
504 |
$wpdb->query("UPDATE `".WPSC_TABLE_PURCHASE_LOGS."` SET `processed` = '3' WHERE `sessionid` = ".$sessionid." LIMIT 1");
|
505 |
+
transaction_results($sessionid, false, $transaction_id);
|
|
|
506 |
break;
|
507 |
|
508 |
case 'Pending': // need to wait for "Completed" before processing
|
540 |
the varialbes were set in the web form, and the resulting string
|
541 |
is stored in $nvpstr */
|
542 |
|
543 |
+
$nvpstr="&PAYMENTREQUEST_0_AMT=".$paymentAmount."&PAYMENTREQUEST_0_PAYMENTACTION=".$paymentType."&ReturnUrl=".$returnURL."&CANCELURL=".$cancelURL ."&PAYMENTREQUEST_0_CURRENCYCODE=".$currencyCodeType;
|
544 |
|
545 |
/* Make the call to PayPal to set the Express Checkout token
|
546 |
If the API call succeded, then redirect the buyer to PayPal
|
605 |
|
606 |
********************************************************/
|
607 |
|
|
|
|
|
|
|
608 |
/* Collect the necessary information to complete the
|
609 |
authorization for the PayPal payment
|
610 |
*/
|
626 |
if(isset($_REQUEST['TOKEN']) && !isset($_REQUEST['PAYERID'])){
|
627 |
$_SESSION['paypalExpressMessage']= '<h4>TRANSACTION CANCELED</h4>';
|
628 |
}else{
|
629 |
+
if ( ! isset( $resArray['SHIPTOSTREET2'] ) )
|
630 |
+
$resArray['SHIPTOSTREET2'] = '';
|
631 |
$output ="
|
632 |
<table width='400' class='paypal_express_form'>
|
633 |
<tr>
|
634 |
+
<td align='left' class='firstcol'><b>Order Total:</b></td>
|
635 |
<td align='left'>" . wpsc_currency_display($_SESSION['paypalAmount']) . "</td>
|
636 |
</tr>
|
637 |
<tr>
|
638 |
+
<td align='left' colspan='2'><b>" . __('Shipping Address:', 'wpsc' ) . " </b></td>
|
639 |
</tr>
|
640 |
<tr>
|
641 |
<td align='left' class='firstcol'>
|
672 |
<td align='left'>".$resArray['SHIPTOCOUNTRYNAME']."</td>
|
673 |
</tr>
|
674 |
<tr>
|
675 |
+
<td colspan='2'>";
|
676 |
|
677 |
$output .= "<form action=".get_option('transact_url')." method='post'>\n";
|
678 |
$output .= " <input type='hidden' name='totalAmount' value='".wpsc_cart_total(false)."' />\n";
|
705 |
|
706 |
function paypal_hash_call($methodName,$nvpStr) {
|
707 |
//declaring of variables
|
708 |
+
$version = 71;
|
709 |
if ( 'sandbox' == get_option('paypal_certified_server_type') ) {
|
710 |
$API_Endpoint = "https://api-3t.sandbox.paypal.com/nvp";
|
711 |
+
$paypal_certified_url = "https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&useraction=commit&token=";
|
712 |
} else {
|
713 |
$API_Endpoint = "https://api-3t.paypal.com/nvp";
|
714 |
+
$paypal_certified_url = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&useraction=commit&token=";
|
715 |
}
|
716 |
|
717 |
$USE_PROXY = false;
|
734 |
$options = array(
|
735 |
'timeout' => 5,
|
736 |
'body' => $nvpreq,
|
737 |
+
'sslverify' => false,
|
738 |
);
|
739 |
|
|
|
740 |
$nvpReqArray=paypal_deformatNVP($nvpreq);
|
741 |
+
$_SESSION['nvpReqArray']=$nvpReqArray;
|
742 |
$res = wp_remote_post($API_Endpoint, $options);
|
743 |
+
|
744 |
if ( is_wp_error($res) ) {
|
745 |
$_SESSION['curl_error_msg'] = 'WP HTTP Error: ' . $res->get_error_message();
|
746 |
$nvpResArray=paypal_deformatNVP('');
|
wpsc-merchants/paypal-pro.merchant.php
CHANGED
@@ -128,14 +128,15 @@ class wpsc_merchant_paypal_pro extends wpsc_merchant {
|
|
128 |
*/
|
129 |
function submit() {
|
130 |
if ( get_option( 'paypal_pro_testmode' ) == "on" )
|
131 |
-
$paypal_url = "https://api-3t.
|
132 |
else
|
133 |
$paypal_url = "https://api-3t.paypal.com/nvp"; // Live
|
134 |
|
135 |
$options = array(
|
136 |
'timeout' => 5,
|
137 |
'body' => $this->collected_gateway_data,
|
138 |
-
'user-agent' => $this->cart_data['software_name'] . " " . get_bloginfo( 'url' )
|
|
|
139 |
);
|
140 |
$response = wp_remote_post( $paypal_url, $options );
|
141 |
|
128 |
*/
|
129 |
function submit() {
|
130 |
if ( get_option( 'paypal_pro_testmode' ) == "on" )
|
131 |
+
$paypal_url = "https://api-3t.sandbox.paypal.com/nvp"; // Sandbox testing
|
132 |
else
|
133 |
$paypal_url = "https://api-3t.paypal.com/nvp"; // Live
|
134 |
|
135 |
$options = array(
|
136 |
'timeout' => 5,
|
137 |
'body' => $this->collected_gateway_data,
|
138 |
+
'user-agent' => $this->cart_data['software_name'] . " " . get_bloginfo( 'url' ),
|
139 |
+
'sslverify' => false,
|
140 |
);
|
141 |
$response = wp_remote_post( $paypal_url, $options );
|
142 |
|
wpsc-merchants/paypal-standard.merchant.php
CHANGED
@@ -114,13 +114,14 @@ class wpsc_merchant_paypal_standard extends wpsc_merchant {
|
|
114 |
'city' => $this->cart_data['shipping_address']['city'],
|
115 |
'country' => $this->cart_data['shipping_address']['country'],
|
116 |
'zip' => $this->cart_data['shipping_address']['post_code'],
|
|
|
117 |
);
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
// Order settings to be sent to paypal
|
125 |
$paypal_vars += array(
|
126 |
'invoice' => $this->cart_data['session_id']
|
114 |
'city' => $this->cart_data['shipping_address']['city'],
|
115 |
'country' => $this->cart_data['shipping_address']['country'],
|
116 |
'zip' => $this->cart_data['shipping_address']['post_code'],
|
117 |
+
'state' => $this->cart_data['shipping_address']['state'],
|
118 |
);
|
119 |
+
|
120 |
+
//PayPal doesnt accept the country code of US it must be USA! - this also breaks the send shipping details,
|
121 |
+
//this will need to be refactored as its messy
|
122 |
+
if ($this->cart_data['shipping_address']['country'] == 'US')
|
123 |
+
$paypal_vars['country'] = 'USA';
|
124 |
+
|
125 |
// Order settings to be sent to paypal
|
126 |
$paypal_vars += array(
|
127 |
'invoice' => $this->cart_data['session_id']
|
wpsc-shipping/flatrate.php
CHANGED
@@ -101,12 +101,14 @@ class flatrate {
|
|
101 |
|
102 |
global $wpdb, $wpsc_cart;
|
103 |
|
|
|
|
|
104 |
if (isset($_POST['country'])) {
|
105 |
|
106 |
$country = $_POST['country'];
|
107 |
$_SESSION['wpsc_delivery_country'] = $country;
|
108 |
|
109 |
-
}
|
110 |
|
111 |
$country = $_SESSION['wpsc_delivery_country'];
|
112 |
|
@@ -128,8 +130,8 @@ class flatrate {
|
|
128 |
}
|
129 |
|
130 |
}
|
131 |
-
|
132 |
-
if (
|
133 |
}
|
134 |
|
135 |
} else {
|
101 |
|
102 |
global $wpdb, $wpsc_cart;
|
103 |
|
104 |
+
$country = '';
|
105 |
+
|
106 |
if (isset($_POST['country'])) {
|
107 |
|
108 |
$country = $_POST['country'];
|
109 |
$_SESSION['wpsc_delivery_country'] = $country;
|
110 |
|
111 |
+
} elseif ( isset( $_SESSION['wpsc_delivery_country'] ) ) {
|
112 |
|
113 |
$country = $_SESSION['wpsc_delivery_country'];
|
114 |
|
130 |
}
|
131 |
|
132 |
}
|
133 |
+
|
134 |
+
if ( ! empty( $flatrates[$results] ) ) return array("Flat Rate"=>(float)$flatrates[$results]);
|
135 |
}
|
136 |
|
137 |
} else {
|
wpsc-taxes/controllers/taxes_controller.class.php
CHANGED
@@ -79,6 +79,18 @@ class wpec_taxes_controller {
|
|
79 |
$total_tax += $taxes['tax'];
|
80 |
}// if
|
81 |
}// foreach
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
//add shipping tax if set
|
84 |
if ( $tax_rate['shipping'] ) {
|
@@ -170,8 +182,10 @@ class wpec_taxes_controller {
|
|
170 |
$wpec_base_country = $this->wpec_taxes_retrieve_selected_country();
|
171 |
$region = $this->wpec_taxes_retrieve_region();
|
172 |
|
|
|
|
|
173 |
//get the tax percentage rate
|
174 |
-
$tax_rate = $this->wpec_taxes->wpec_taxes_get_included_rate( $
|
175 |
|
176 |
//get the taxable price - unit price multiplied by qty
|
177 |
$taxable_price = $cart_item->unit_price * $cart_item->quantity;
|
79 |
$total_tax += $taxes['tax'];
|
80 |
}// if
|
81 |
}// foreach
|
82 |
+
|
83 |
+
///minus coupon tax if we are using coupons
|
84 |
+
if ($wpsc_cart->coupons_amount > 0){
|
85 |
+
|
86 |
+
if ( $this->wpec_taxes_isincluded() )
|
87 |
+
$coupon_tax = $this->wpec_taxes_calculate_tax($wpsc_cart->coupons_amount, $tax_rate['rate'], false);
|
88 |
+
else
|
89 |
+
$coupon_tax = $this->wpec_taxes_calculate_tax($wpsc_cart->coupons_amount, $tax_rate['rate']);
|
90 |
+
|
91 |
+
$total_tax -= $coupon_tax;
|
92 |
+
}
|
93 |
+
|
94 |
|
95 |
//add shipping tax if set
|
96 |
if ( $tax_rate['shipping'] ) {
|
182 |
$wpec_base_country = $this->wpec_taxes_retrieve_selected_country();
|
183 |
$region = $this->wpec_taxes_retrieve_region();
|
184 |
|
185 |
+
$taxes_band = isset( $cart_item->meta[0]['wpec_taxes_band'] ) ? $cart_item->meta[0]['wpec_taxes_band'] : null;
|
186 |
+
|
187 |
//get the tax percentage rate
|
188 |
+
$tax_rate = $this->wpec_taxes->wpec_taxes_get_included_rate( $taxes_band, $wpec_base_country, $region );
|
189 |
|
190 |
//get the taxable price - unit price multiplied by qty
|
191 |
$taxable_price = $cart_item->unit_price * $cart_item->quantity;
|
wpsc-theme/functions/wpsc-transaction_results_functions.php
CHANGED
@@ -24,7 +24,7 @@ function wpsc_transaction_theme() {
|
|
24 |
unset( $_SESSION['wpsc_sessionid'] );
|
25 |
}
|
26 |
|
27 |
-
if ( '
|
28 |
$sessionid = $_SESSION['paypalexpresssessionid'];
|
29 |
|
30 |
if ( isset( $_REQUEST['eway'] ) && '1' == $_REQUEST['eway'] )
|
@@ -35,20 +35,27 @@ function wpsc_transaction_theme() {
|
|
35 |
echo $_SESSION['payflow_message'];
|
36 |
$_SESSION['payflow_message'] = '';
|
37 |
}
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
$
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
|
|
52 |
if(!$dont_show_transaction_results ) {
|
53 |
if ( !empty($sessionid) ){
|
54 |
$cart_log_id = $wpdb->get_var( "SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1" );
|
24 |
unset( $_SESSION['wpsc_sessionid'] );
|
25 |
}
|
26 |
|
27 |
+
if ( isset( $_SESSION['wpsc_previous_selected_gateway'] ) && in_array( $_SESSION['wpsc_previous_selected_gateway'], array( 'paypal_certified', 'wpsc_merchant_paypal_express' ) ) )
|
28 |
$sessionid = $_SESSION['paypalexpresssessionid'];
|
29 |
|
30 |
if ( isset( $_REQUEST['eway'] ) && '1' == $_REQUEST['eway'] )
|
35 |
echo $_SESSION['payflow_message'];
|
36 |
$_SESSION['payflow_message'] = '';
|
37 |
}
|
38 |
+
|
39 |
+
$dont_show_transaction_results = false;
|
40 |
+
|
41 |
+
if ( isset( $_SESSION['wpsc_previous_selected_gateway'] ) ) {
|
42 |
+
// Replaces the ugly if else for gateways
|
43 |
+
switch($_SESSION['wpsc_previous_selected_gateway']){
|
44 |
+
case 'paypal_certified':
|
45 |
+
case 'wpsc_merchant_paypal_express':
|
46 |
+
echo $_SESSION['paypalExpressMessage'];
|
47 |
+
|
48 |
+
if(isset($_SESSION['reshash']['PAYMENTINFO_0_TRANSACTIONTYPE']) && 'expresscheckout' == $_SESSION['reshash']['PAYMENTINFO_0_TRANSACTIONTYPE'])
|
49 |
+
$dont_show_transaction_results = false;
|
50 |
+
else
|
51 |
+
$dont_show_transaction_results = true;
|
52 |
+
break;
|
53 |
+
case 'dps':
|
54 |
+
$sessionid = decrypt_dps_response();
|
55 |
+
break;
|
56 |
+
}
|
57 |
}
|
58 |
+
|
59 |
if(!$dont_show_transaction_results ) {
|
60 |
if ( !empty($sessionid) ){
|
61 |
$cart_log_id = $wpdb->get_var( "SELECT `id` FROM `" . WPSC_TABLE_PURCHASE_LOGS . "` WHERE `sessionid`= " . $sessionid . " LIMIT 1" );
|