Skip to content

Commit

Permalink
1st pass
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Cao committed Jun 11, 2013
1 parent eeecc7f commit 6d2881f
Show file tree
Hide file tree
Showing 79 changed files with 7,461 additions and 7,417 deletions.
12 changes: 6 additions & 6 deletions wp-shopping-cart.php
Expand Up @@ -69,6 +69,12 @@ public function _register_core_components( $components ) {
WPSC_FILE_PATH . '/wpsc-components/merchant-core-v2/merchant-core-v2.php'
);

$components['theme-engine']['core-v1'] = array(
'title' => __( 'WP e-Commerce Theme Engine v1', 'wpsc' ),
'includes' =>
WPSC_FILE_PATH . '/wpsc-components/theme-engine-v1/theme-engine-v1.php'
);

return $components;
}

Expand Down Expand Up @@ -195,9 +201,6 @@ function load() {
// Setup the core WPEC cart
wpsc_core_setup_cart();

// Load the thumbnail sizes
wpsc_core_load_thumbnail_sizes();

// Load the purchase log statuses
wpsc_core_load_purchase_log_statuses();

Expand All @@ -210,9 +213,6 @@ function load() {
// Load the shipping modules
wpsc_core_load_shipping_modules();

// Set page title array for important WPSC pages
wpsc_core_load_page_titles();

// WPEC is fully loaded
do_action( 'wpsc_loaded' );
}
Expand Down
30 changes: 23 additions & 7 deletions wpsc-admin/css/admin.css
Expand Up @@ -1906,24 +1906,38 @@ table.purchase-logs tr:hover .column-id .delete {

.wpsc-product-variations-tabs {
background: #F1F1F1;
border-bottom: 1px solid #ccc;
padding: 10px 10px 0;
border-bottom: 1px solid #dfdfdf;
padding: 5px 4px 0;
margin: 0;
width: 100%;
}

.wpsc-product-variations-tabs:before,
.wpsc-product-variations-tabs:after {
display: table;
content: "";
}

.wpsc-product-variations-tabs:after {
clear: both;
}

.wpsc-product-variations-tabs li {
display: inline-block;
margin: 0 4px 2px 0;
float: left;
margin: 0 4px 0 0;
}

.wpsc-product-variations-tabs a {
background-color: #fff;
border-color: #ccc #ccc #fff;
display: block;
background-color: #f1f1f1;
border-color: #dfdfdf #dfdfdf #fff;
border-style: solid;
border-width: 1px 1px 0;
line-height: 1em;
color: #aaa;
padding: 5px 7px 3px;
text-decoration: none;
vertical-align: middle;

border-top-left-radius: 3px;
border-top-right-radius: 3px;
Expand All @@ -1938,12 +1952,14 @@ table.purchase-logs tr:hover .column-id .delete {
}

.wpsc-product-variations-tabs .active a {
background: #fff;
border-bottom-width: 1px;
color: #333;
margin-bottom: 2px;
margin-bottom: -1px;
}

.wpsc-product-variations-tab-content {
clear: both;
padding: 0 10px;
}

Expand Down
2 changes: 1 addition & 1 deletion wpsc-admin/includes/product-variations-page.class.php
Expand Up @@ -60,7 +60,7 @@ private function save_variation_meta( $id, $data ) {
if ( isset( $data['sku'] ) )
update_product_meta( $id, 'sku', $data['sku'] );

if ( isset( $data['stock'] ) && $data['stock'] !== '' ) {
if ( isset( $data['stock'] ) ) {
if ( is_numeric( $data['stock'] ) )
update_product_meta( $id, 'stock', absint( $data['stock'] ) );
else
Expand Down
13 changes: 0 additions & 13 deletions wpsc-admin/init.php
Expand Up @@ -679,19 +679,6 @@ function wpsc_delete_variation_set() {
if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( 'wpsc-delete-variation-set' == $_REQUEST['wpsc_admin_action'] ) )
add_action( 'admin_init', 'wpsc_delete_variation_set' );

function wpsc_force_flush_theme_transients() {
// Flush transients
wpsc_flush_theme_transients( true );

// Bounce back
$sendback = wp_get_referer();
wp_redirect( $sendback );

exit();
}
if ( isset( $_REQUEST['wpsc_flush_theme_transients'] ) && ( $_REQUEST['wpsc_flush_theme_transients'] == 'true' ) )
add_action( 'admin_init', 'wpsc_force_flush_theme_transients' );

function wpsc_backup_theme() {
$wp_theme_path = get_stylesheet_directory();
wpsc_recursive_copy( $wp_theme_path, WPSC_THEME_BACKUP_DIR );
Expand Down
19 changes: 14 additions & 5 deletions wpsc-admin/settings-page.php
Expand Up @@ -203,7 +203,6 @@ final class WPSC_Settings_Page {
public static function init() {
self::$default_tabs = array(
'general' => _x( 'General' , 'General settings tab in Settings->Store page' , 'wpsc' ),
'presentation' => _x( 'Presentation', 'Presentation settings tab in Settings->Store page', 'wpsc' ),
'admin' => _x( 'Admin' , 'Admin settings tab in Settings->Store page' , 'wpsc' ),
'taxes' => _x( 'Taxes' , 'Taxes settings tab in Settings->Store page' , 'wpsc' ),
'shipping' => _x( 'Shipping' , 'Shipping settings tab in Settings->Store page' , 'wpsc' ),
Expand Down Expand Up @@ -378,10 +377,10 @@ public function set_current_tab( $tab_id = null ) {

if ( isset( $_REQUEST['wpsc_admin_action'] ) && ( $_REQUEST['wpsc_admin_action'] == 'submit_options' ) ) {
check_admin_referer( 'update-options', 'wpsc-update-options' );

$this->save_options();
do_action( 'wpsc_save_' . $this->current_tab_id . '_settings', $this->current_tab );

$query_args = array();
if ( is_callable( array( $this->current_tab, 'callback_submit_options' ) ) ) {
$additional_query_args = $this->current_tab->callback_submit_options();
Expand Down Expand Up @@ -445,6 +444,7 @@ private function tab_class( $id ) {
*/
private function submit_url() {
$location = add_query_arg( 'tab', $this->current_tab_id );
$location = apply_filters( 'wpsc_settings_page_submit_url', $location, $this, $this->current_tab );
return $location;
}

Expand Down Expand Up @@ -476,14 +476,14 @@ public function display_current_tab() {
<div id="options_<?php echo esc_attr( $this->current_tab_id ); ?>" class="tab-content">
<?php
if ( is_callable( array( $this->current_tab, 'display' ) ) ) {
do_action( 'wpsc_before_settings_tab', $this, $this->current_tab );
$this->current_tab->display();
do_action( 'wpsc_after_settings_tab', $this, $this->current_tab );
}
?>

<?php do_action( 'wpsc_' . $this->current_tab_id . '_settings_page' ); ?>
<div class="submit">
<input type='hidden' name='wpsc_admin_action' value='submit_options' />
<?php wp_nonce_field( 'update-options', 'wpsc-update-options' ); ?>
<?php if ( $this->current_tab->is_submit_button_displayed() ): ?>
<?php submit_button( __( 'Save Changes' ) ); ?>
<?php endif ?>
Expand Down Expand Up @@ -706,3 +706,12 @@ private function save_options( $selected = '' ) {
}

WPSC_Settings_Page::init();

add_action( 'wpsc_after_settings_tab', '_wpsc_action_after_settings_tab' );

function _wpsc_action_after_settings_tab() {
?>
<input type='hidden' name='wpsc_admin_action' value='submit_options' />
<?php
wp_nonce_field( 'update-options', 'wpsc-update-options' );
}
Expand Up @@ -259,6 +259,4 @@ function rewind_breadcrumbs() {
}
}

}

?>
}
@@ -0,0 +1,61 @@
<?php

/**
* wpsc_display_products_page class
*
* Shows only products from current category, but not from subcategories.
*
* @access public
* @return void
*/

class WPSC_Hide_subcatsprods_in_cat {
var $q;

function get_posts( &$q ) {
$this->q =& $q;
if ( ( !isset($q->query_vars['taxonomy']) || ( "wpsc_product_category" != $q->query_vars['taxonomy'] )) )
return false;

add_action( 'posts_where', array( &$this, 'where' ) );
add_action( 'posts_join', array( &$this, 'join' ) );
}

function where( $where ) {
global $wpdb;

remove_action( 'posts_where', array( &$this, 'where' ) );

$term_id=$wpdb->get_var($wpdb->prepare('SELECT term_id FROM '.$wpdb->terms.' WHERE slug = %s ', $this->q->query_vars['term']));

if ( !is_numeric( $term_id ) || $term_id < 1 )
return $where;

$term_taxonomy_id = $wpdb->get_var($wpdb->prepare('SELECT term_taxonomy_id FROM '.$wpdb->term_taxonomy.' WHERE term_id = %d and taxonomy = %s', $term_id, $this->q->query_vars['taxonomy']));

if ( !is_numeric($term_taxonomy_id) || $term_taxonomy_id < 1)
return $where;

$field = preg_quote( "$wpdb->term_relationships.term_taxonomy_id", '#' );

$just_one = $wpdb->prepare( " AND $wpdb->term_relationships.term_taxonomy_id = %d ", $term_taxonomy_id );
if ( preg_match( "#AND\s+$field\s+IN\s*\(\s*(?:['\"]?\d+['\"]?\s*,\s*)*['\"]?\d+['\"]?\s*\)#", $where, $matches ) )
$where = str_replace( $matches[0], $just_one, $where );
else
$where .= $just_one;

return $where;
}

function join($join){
global $wpdb;
remove_action( 'posts_where', array( &$this, 'where' ) );
remove_action( 'posts_join', array( &$this, 'join' ) );
if( strpos($join, "JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)" ) ){
return $join;
}
$join .= " JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)";
return $join;
}
}

130 changes: 130 additions & 0 deletions wpsc-components/theme-engine-v1/classes/wpsc-products-by-category.php
@@ -0,0 +1,130 @@
<?php
/**
* wpsc_products_by_category class.
*
*/
class wpsc_products_by_category {

var $sql_components = array( );

/**
* wpsc_products_by_category function.
*
* @access public
* @param mixed $query
* @return void
*/
function wpsc_products_by_category( $query ) {
global $wpdb;
$q = $query->query_vars;


// Category stuff for nice URLs
if ( !empty( $q['wpsc_product_category'] ) && !$query->is_singular ) {
$q['taxonomy'] = 'wpsc_product_category';
$q['term'] = $q['wpsc_product_category'];
$in_cats = '';
$join = " INNER JOIN $wpdb->term_relationships
ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)
INNER JOIN $wpdb->term_taxonomy
ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
";
if(isset($q['meta_key']))
$join .= " INNER JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) ";

$whichcat = " AND $wpdb->term_taxonomy.taxonomy = '{$q['taxonomy']}' ";

$term_data = get_term_by( 'slug', $q['term'], $q['taxonomy'] );

if( is_object( $term_data ) )
$in_cats = array( $term_data->term_id );

if('0' != get_option('show_subcatsprods_in_cat') && is_object($term_data)){
$term_children_data = get_term_children( $term_data->term_id, $q['taxonomy'] );
$in_cats = array_reverse( array_merge( $in_cats, $term_children_data ) );
}
if( is_array( $in_cats ) ){
$in_cats = "'" . implode( "', '", $in_cats ) . "'";
$whichcat .= "AND $wpdb->term_taxonomy.term_id IN ($in_cats)";
}

$post_type_object = get_post_type_object( 'wpsc-product' );
$permitted_post_statuses = current_user_can( $post_type_object->cap->edit_posts ) ? "'private', 'draft', 'pending', 'publish'" : "'publish'";


$whichcat .= " AND $wpdb->posts.post_status IN ($permitted_post_statuses) ";
$groupby = "{$wpdb->posts}.ID";

$this->sql_components['join'] = $join;
$this->sql_components['fields'] = "{$wpdb->posts}.*, {$wpdb->term_taxonomy}.term_id";
$this->sql_components['group_by'] = $groupby;

//what about ordering by price
if(isset($q['meta_key']) && '_wpsc_price' == $q['meta_key']){
$whichcat .= " AND $wpdb->postmeta.meta_key = '_wpsc_price'";
}else{

$this->sql_components['order_by'] = "{$wpdb->term_taxonomy}.term_id";
}
$this->sql_components['where'] = $whichcat;
add_filter( 'posts_join', array( &$this, 'join_sql' ) );
add_filter( 'posts_where', array( &$this, 'where_sql' ) );
add_filter( 'posts_fields', array( &$this, 'fields_sql' ) );
add_filter( 'posts_orderby', array( &$this, 'order_by_sql' ) );
add_filter( 'posts_groupby', array( &$this, 'group_by_sql' ) );
}
}

function join_sql( $sql ) {
if ( isset( $this->sql_components['join'] ) )
$sql = $this->sql_components['join'];

remove_filter( 'posts_join', array( &$this, 'join_sql' ) );
return $sql;
}

function where_sql( $sql ) {
if ( isset( $this->sql_components['where'] ) )
$sql = $this->sql_components['where'];

remove_filter( 'posts_where', array( &$this, 'where_sql' ) );
return $sql;
}

function order_by_sql( $sql ) {
$order_by_parts = array( );
$order_by_parts[] = $sql;

if ( isset( $this->sql_components['order_by'] ) )
$order_by_parts[] = $this->sql_components['order_by'];

$order_by_parts = array_reverse( $order_by_parts );
$sql = implode( ',', $order_by_parts );

remove_filter( 'posts_orderby', array( &$this, 'order_by_sql' ) );
return $sql;
}

function fields_sql( $sql ) {
if ( isset( $this->sql_components['fields'] ) )
$sql = $this->sql_components['fields'];

remove_filter( 'posts_fields', array( &$this, 'fields_sql' ) );
return $sql;
}

function group_by_sql( $sql ) {
if ( isset( $this->sql_components['group_by'] ) )
$sql = $this->sql_components['group_by'];

remove_filter( 'posts_groupby', array( &$this, 'group_by_sql' ) );
return $sql;
}

function request_sql( $sql ) {
echo $sql . "<br />";
remove_filter( 'posts_request', array( &$this, 'request_sql' ) );
return $sql;
}
}

14 changes: 14 additions & 0 deletions wpsc-components/theme-engine-v1/helpers/admin.php
@@ -0,0 +1,14 @@
<?php

add_action( 'wpsc_register_settings_tabs', '_wpsc_te_v1_register_settings_tabs', 10, 1 );
add_action( 'wpsc_load_settings_tab_class', '_wpsc_te_v1_load_settings_tab_class', 10, 1 );

function _wpsc_te_v1_register_settings_tabs( $page_instance ) {
$page_instance->register_tab( 'presentation', _x( 'Presentation', 'Presentation settings tab in Settings->Store page', 'wpsc' ) );
}

function _wpsc_te_v1_load_settings_tab_class( $page_instance ) {
$current_tab_id = $page_instance->get_current_tab_id();
if ( in_array( $current_tab_id, array( 'presentation' ) ) )
require_once( WPSC_TE_V1_PATH . '/classes/settings-tab-presentation.php' );
}

0 comments on commit 6d2881f

Please sign in to comment.