-
-
Save netconstructor/2567217 to your computer and use it in GitHub Desktop.
Mass Price Update for Shopp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function vol_price_css() { | |
$theme_dir = get_bloginfo('template_directory'); | |
?> | |
<style type="text/css"> | |
.shopp h2.voc_title {padding: 12px 15px 25px 0;} | |
.icon32 {background: url(<?php echo $theme_dir;?>/lib/img/shopp32.png) no-repeat scroll 0 0 transparent;} | |
.vcc_price_update_btn { position:absolute; top:47px; left:400px;} | |
table.price-editor tr.headers th{font-weight:bold;} | |
table.price-editor tr.even {background:#eeeeee;} | |
table.price-editor tr.odd {background:#ffffff;} | |
table.price-editor td.price input {width:45px; text-align:center;} | |
</style> | |
<?php } | |
add_action( 'admin_head', 'vol_price_css' ); | |
// price page | |
class volcanic_price_edit_screen{ | |
function __construct(){ | |
add_action('shopp_init', array(&$this, 'init')); | |
} | |
function init(){ | |
add_action('admin_menu', array(&$this, 'add_menu')); | |
} | |
function add_menu(){ | |
global $Shopp; | |
$ShoppMenu = $Shopp->Flow->Admin->MainMenu; //this is our Shopp menu handle | |
add_submenu_page($ShoppMenu, 'Price Editor', 'Price Editor',(defined('SHOPP_USERLEVEL') ? SHOPP_USERLEVEL : 'manage_options'), 'price-editor', array($this, 'vol_price_screen')); | |
} | |
function vol_price_screen(){ | |
// declare global DB | |
global $wpdb; | |
// define custom tables | |
$wpdb->shopp_product = $wpdb->prefix.'shopp_product'; | |
$wpdb->shopp_price = $wpdb->prefix.'shopp_price'; | |
if(isset($_POST['submit'])){ | |
if($_POST['submit']=="Update Prices"){ | |
$price_tmp = $_POST['price']; | |
foreach($price_tmp as $key => $value) { | |
$wpdb->query("UPDATE $wpdb->shopp_price SET price = '$value' WHERE id = '$key'"); | |
} | |
$message = '<div class="updated fade below-h2" id="message"><p>Prices have been updated successfully.</p></div>'; | |
echo $message; | |
} | |
} | |
// prepare product list query | |
$shopp_product_query = $wpdb->prepare(" | |
SELECT pd.id, pd.name, ps.id, ps.product, ps.label, ps.price | |
FROM $wpdb->shopp_product pd | |
INNER JOIN $wpdb->shopp_price ps | |
ON pd.id = ps.product | |
WHERE ps.price != '0.000000' | |
ORDER BY pd.name, ps.label ASC | |
"); | |
$shopp_products = $wpdb->get_results($shopp_product_query); | |
// prepare update table layout | |
echo '<div class="wrap shopp">'; | |
echo '<div class="icon32"></div>'; | |
echo '<h2 class="voc_title">Bulk Price Editor</h2>'; | |
?> | |
<form name="shopp_price_update" id="shopp_price_update" method="post" action=""> | |
<div class="vcc_price_update_btn"><input class="button-primary" type="submit" name="submit" value="<?php _e('Update Prices') ?>"></div> | |
<table class="widefat price-editor" cellspacing="0"> | |
<thead> | |
<tr class="headers"> | |
<th scope='col'>Product Name</th> | |
<th scope='col'>Variation</th> | |
<th scope='col'>Price</th> | |
</tr> | |
</thead> | |
<tfoot> | |
<tr class="headers"> | |
<th scope='col'>Product Name</th> | |
<th scope='col'>Variation</th> | |
<th scope='col'>Price</th> | |
</tr> | |
</tfoot> | |
<tbody id="price-editor-table"> | |
<?php | |
foreach ($shopp_products as $shopp_product) : | |
$prod_name = $shopp_product->name; | |
$price_lbl = $shopp_product->label; | |
$price_amt = $shopp_product->price; | |
$price_id = $shopp_product->id; | |
$even_odd = ( 'odd' != $even_odd ) ? 'odd' : 'even'; | |
echo '<tr class="'.$even_odd.'">'; | |
// echo '<td>'.$price_id .'</td>'; | |
echo '<td class="name">'.$prod_name .'</td>'; | |
echo '<td class="variation">'.$price_lbl .'</td>'; | |
echo '<td class="price"><input type="text" name="price['.$price_id .']" class="price" value="'.number_format($price_amt, 2, '.', '') .'" /></td>'; | |
echo '</tr>'; | |
endforeach; | |
echo '</tbody>'; | |
echo '</table>'; | |
echo '</form>'; | |
echo '</div>'; | |
} | |
} // end class | |
$priceEditPage = new volcanic_price_edit_screen(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment