Esempio n. 1
0
 /**
  * Handles loading, saving and deleting products in the context of workflows
  *
  * @author Jonathan Davis
  * @since 1.0
  * @version 1.2
  *
  * @return void
  **/
 public function workflow()
 {
     global $Shopp, $post;
     $defaults = array('page' => false, 'action' => false, 'selected' => array(), 'id' => false, 'save' => false, 'duplicate' => false, 'next' => false);
     $args = array_merge($defaults, $_REQUEST);
     extract($args, EXTR_SKIP);
     if (!is_array($selected)) {
         $selected = array($selected);
     }
     if (!defined('WP_ADMIN') || !isset($page) || $this->Admin->pagename('products') != $page) {
         return false;
     }
     $adminurl = admin_url('admin.php');
     if ($this->Admin->pagename('products') == $page && (false !== $action || isset($_GET['delete_all']))) {
         if (isset($_GET['delete_all'])) {
             $action = 'emptytrash';
         }
         switch ($action) {
             case 'publish':
                 ShoppProduct::publishset($selected, 'publish');
                 break;
             case 'unpublish':
                 ShoppProduct::publishset($selected, 'draft');
                 break;
             case 'feature':
                 ShoppProduct::featureset($selected, 'on');
                 break;
             case 'defeature':
                 ShoppProduct::featureset($selected, 'off');
                 break;
             case 'restore':
                 ShoppProduct::publishset($selected, 'draft');
                 break;
             case 'trash':
                 ShoppProduct::publishset($selected, 'trash');
                 break;
             case 'delete':
                 foreach ($selected as $id) {
                     $P = new ShoppProduct($id);
                     $P->delete();
                 }
                 break;
             case 'emptytrash':
                 $Template = new ShoppProduct();
                 $trash = sDB::query("SELECT ID FROM {$Template->_table} WHERE post_status='trash' AND post_type='" . ShoppProduct::posttype() . "'", 'array', 'col', 'ID');
                 foreach ($trash as $id) {
                     $P = new ShoppProduct($id);
                     $P->delete();
                 }
                 break;
         }
         // Gracefully invalidate Shopp object caching
         Shopp::invalidate_cache();
         $redirect = add_query_arg($_GET, $adminurl);
         $redirect = remove_query_arg(array('action', 'selected', 'delete_all'), $redirect);
         Shopp::redirect($redirect);
     }
     if ($duplicate) {
         // Gracefully invalidate Shopp object caching
         Shopp::invalidate_cache();
         $Product = new ShoppProduct($duplicate);
         $Product->duplicate();
         $this->index($Product);
         Shopp::redirect(add_query_arg(array('page' => $this->Admin->pagename('products'), 'paged' => $_REQUEST['paged']), $adminurl));
     }
     if (isset($id) && $id != "new") {
         $Shopp->Product = new ShoppProduct($id);
         $Shopp->Product->load_data();
         // Adds CPT compatibility support for third-party plugins/themes
         global $post;
         if (is_null($post)) {
             $post = get_post($Shopp->Product->id);
         }
     } else {
         $Shopp->Product = new ShoppProduct();
     }
     if ($save) {
         // Gracefully invalidate Shopp object caching
         Shopp::invalidate_cache();
         $this->save($Shopp->Product);
         $this->notice(sprintf(__('%s has been saved.', 'Shopp'), '<strong>' . stripslashes($Shopp->Product->name) . '</strong>'));
         // Workflow handler
         if (isset($_REQUEST['settings']) && isset($_REQUEST['settings']['workflow'])) {
             $workflow = $_REQUEST['settings']['workflow'];
             $worklist = $this->worklist;
             $working = array_search($id, $this->worklist);
             switch ($workflow) {
                 case 'close':
                     $next = 'close';
                     break;
                 case 'new':
                     $next = 'new';
                     break;
                 case 'next':
                     $key = $working + 1;
                     break;
                 case 'previous':
                     $key = $working - 1;
                     break;
                 case 'continue':
                     $next = $id;
                     break;
             }
             if (isset($key)) {
                 $next = isset($worklist[$key]) ? $worklist[$key] : 'close';
             }
         }
         if ($next) {
             $query = $_GET;
             if (isset($this->worklist['query'])) {
                 $query = array_merge($_GET, $this->worklist['query']);
             }
             $redirect = add_query_arg($query, $adminurl);
             $cleanup = array('action', 'selected', 'delete_all');
             if ('close' == $next) {
                 $cleanup[] = 'id';
                 $next = false;
             }
             $redirect = remove_query_arg($cleanup, $redirect);
             if ($next) {
                 $redirect = add_query_arg('id', $next, $redirect);
             }
             Shopp::redirect($redirect);
         }
         if (empty($id)) {
             $id = $Shopp->Product->id;
         }
         $Shopp->Product = new ShoppProduct($id);
         $Shopp->Product->load_data();
     }
     // WP post type editing support for other plugins
     if (!empty($Shopp->Product->id)) {
         $post = get_post($Shopp->Product->id);
     }
 }
Esempio n. 2
0
/**
 * shopp_product_set_featured - set or unset the product as featured.
 *
 * @api
 * @since 1.2
 *
 * @param int $product (required) the product id to set
 * @param bool $flag (optional default:false) true to set as featured, false to unset featured
 * @return bool true on success, false on failure
 **/
function shopp_product_set_featured($product = false, $flag = false)
{
    if (false === $product) {
        shopp_debug(__FUNCTION__ . " failed: Product id required.");
        return false;
    }
    $Product = new ShoppProduct($product);
    if (empty($Product->id)) {
        shopp_debug(__FUNCTION__ . " failed: Product id {$product} not found.");
        return false;
    }
    return ShoppProduct::featureset(array($product), $flag ? "on" : "off");
}