public
Created

Mass Price Update for Shopp

  • Download Gist
voc_priceeditor.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
<?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();

Is this compatible with Shopp 1.1.9.1?

It should be. I haven't tested it with 1.2 though.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.